Skip to content

Commit

Permalink
fixins
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeHahn committed Nov 10, 2023
1 parent 83418f2 commit 783a66d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
4 changes: 1 addition & 3 deletions pkg/quantile/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,7 @@ func TestAgentInterpolation(t *testing.T) {
t.Run("uint16", func(t *testing.T) {
testAgentInterpolation[uint16](t)
})
t.Run("uint32", func(t *testing.T) {
testAgentInterpolation[uint32](t)
})
// Not run for uint32. These tests are specialized for uint16.
}

func testAgentInterpolation[T uint16 | uint32](t *testing.T) {
Expand Down
13 changes: 6 additions & 7 deletions pkg/quantile/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package quantile

import (
"math"
"strconv"
"strings"
"testing"
Expand All @@ -26,7 +25,7 @@ func ParseBuf[T uint16 | uint32](t *testing.T, dsl string) []float64 {
out []float64
)

eachParsedToken(t, dsl, bitSize[T](), func(k Key, n uint64) {
eachParsedToken[T](t, dsl, bitSize[T](), func(k Key, n uint64) {
if n > uint64(maxBinWidth[T]()) {
t.Fatal("n > max", n, maxBinWidth[T]())
}
Expand All @@ -49,7 +48,7 @@ func ParseSketch[T uint16 | uint32](t *testing.T, dsl string) *Sketch[T] {
s := &Sketch[T]{}
c := Default()

eachParsedToken(t, dsl, bitSize[T](), func(k Key, n uint64) {
eachParsedToken[T](t, dsl, bitSize[T](), func(k Key, n uint64) {
if n > uint64(maxBinWidth[T]()) {
t.Fatal("n > max", n, maxBinWidth[T]())
}
Expand All @@ -72,7 +71,7 @@ func parseKey(t *testing.T, s string) Key {
return Key(k)
}

func parseN(t *testing.T, s string) uint64 {
func parseN[T uint16 | uint32](t *testing.T, s string) uint64 {
t.Helper()
if !strings.HasPrefix(s, "max") {
n, err := strconv.ParseUint(s, 10, 64)
Expand All @@ -84,7 +83,7 @@ func parseN(t *testing.T, s string) uint64 {
}

// <k>:max case
n := uint64(math.MaxUint16)
n := uint64(maxBinWidth[T]())
switch {
case s == "max":
return n
Expand Down Expand Up @@ -115,7 +114,7 @@ func parseN(t *testing.T, s string) uint64 {
// - "0:max" = Bin{k:0, n:maxBinWidth}
// - "1:2" = Bin{k:1, n:2}
// - "3:max-2" = Bin{k:3, n:maxBinWidth-2}
func eachParsedToken(t *testing.T, dsl string, bitSize uint, f func(Key, uint64)) {
func eachParsedToken[T uint16 | uint32](t *testing.T, dsl string, bitSize uint, f func(Key, uint64)) {
t.Helper()
if dsl == "" {
return
Expand All @@ -127,7 +126,7 @@ func eachParsedToken(t *testing.T, dsl string, bitSize uint, f func(Key, uint64)
t.Fatal("bad incr tpl:", tok)
}
k := parseKey(t, tok[:i])
n := parseN(t, tok[i+1:])
n := parseN[T](t, tok[i+1:])

// make sure this value can be cast to our bitSize
if maxn := uint64(1)<<bitSize - 1; n > maxn {
Expand Down
15 changes: 9 additions & 6 deletions pkg/quantile/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package quantile

import (
"math"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -22,7 +21,7 @@ import (
func buildStore[T uint16 | uint32](t *testing.T, dsl string) *sparseStore[T] {
s := &sparseStore[T]{}

eachParsedToken(t, dsl, bitSize[T](), func(k Key, n uint64) {
eachParsedToken[T](t, dsl, bitSize[T](), func(k Key, n uint64) {
if n > uint64(maxBinWidth[T]()) {
t.Fatal("n > max", n, maxBinWidth[T]())
}
Expand Down Expand Up @@ -90,7 +89,9 @@ func testStore[T uint16 | uint32](t *testing.T) {
}

require.Equal(t, exp.bins.String(), s.bins.String())
require.EqualValues(t, exp, s)
// don't compare binPool (lazy initialized sync.Pools)
require.EqualValues(t, exp.count, s.count)
require.EqualValues(t, exp.bins, s.bins)
})
}

Expand Down Expand Up @@ -143,7 +144,9 @@ func testStore[T uint16 | uint32](t *testing.T) {
}

require.Equal(t, exp.bins.String(), s.bins.String())
require.EqualValues(t, exp, s)
// don't compare binPool (lazy initialized sync.Pools)
require.EqualValues(t, exp.count, s.count)
require.EqualValues(t, exp.bins, s.bins)
})
}
})
Expand Down Expand Up @@ -219,12 +222,12 @@ func testCols[T uint16 | uint32](t *testing.T) {
{
store: "0:1 1:1 2:2 3:1 4:1 5:1 8:1 9:1 10:max",
k: []int32{0, 1, 2, 3, 4, 5, 8, 9, 10},
n: []uint32{1, 1, 2, 1, 1, 1, 1, 1, math.MaxUint16},
n: []uint32{1, 1, 2, 1, 1, 1, 1, 1, uint32(maxBinWidth[T]())},
},
{
store: "0:1 0:max",
k: []int32{0, 0},
n: []uint32{1, math.MaxUint16},
n: []uint32{1, uint32(maxBinWidth[T]())},
},
} {
st := buildStore[T](t, tt.store)
Expand Down

0 comments on commit 783a66d

Please sign in to comment.