diff options
| author | Paul Buetow <paul@buetow.org> | 2023-04-02 22:17:32 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2023-04-02 22:17:32 +0300 |
| commit | 82486957133f0e0e5227c2c168254b1001b28f03 (patch) | |
| tree | 7a10ee6f89ada31849acb118dc6299c20dec6186 | |
| parent | 0c6d4ed2e499e3e17165e43803d0d1c6dd0956d9 (diff) | |
unit tests pass after conversion to generics
| -rw-r--r-- | Makefile | 1 | ||||
| -rw-r--r-- | search/bst.go | 2 | ||||
| -rw-r--r-- | search/redblackbst.go | 2 | ||||
| -rw-r--r-- | search/search_test.go | 13 |
4 files changed, 10 insertions, 8 deletions
@@ -1,4 +1,5 @@ test: + go clean -testcache go test ./... -v bench: go test -run=xxx -bench=. ./... | tee bench.out diff --git a/search/bst.go b/search/bst.go index 2dd0b5b..67140e6 100644 --- a/search/bst.go +++ b/search/bst.go @@ -20,7 +20,7 @@ func (n *node[K,V]) String() string { return n.String() } - return fmt.Sprintf("node[K,V]{%d:%d,%s,%s}", + return fmt.Sprintf("node[K,V]{%v:%v,%s,%s}", n.key, n.val, recurse(n.left), diff --git a/search/redblackbst.go b/search/redblackbst.go index 8f699eb..c243b3b 100644 --- a/search/redblackbst.go +++ b/search/redblackbst.go @@ -35,7 +35,7 @@ func (n *rbNode[K,V]) String() string { if n.color == black { color = "black" } - return fmt.Sprintf("rbNode[K,V]{%v;%d:%d,%s,%d,%s,%s}", + return fmt.Sprintf("rbNode[K,V]{%v;%v:%v,%s,%d,%s,%s}", n.deleted, n.key, n.val, diff --git a/search/search_test.go b/search/search_test.go index ebd0a01..2cb35bc 100644 --- a/search/search_test.go +++ b/search/search_test.go @@ -12,9 +12,6 @@ const factor int = 10 const minLength int = 1 const maxLength int = 10000 -// Store results here to avoid compiler optimizations -var benchResult int - func TestElementary(t *testing.T) { for i := minLength; i <= maxLength; i *= factor { test[int,int](NewElementary[int,int](), i, t) @@ -46,7 +43,7 @@ func TestGoMap(t *testing.T) { } func test[K ds.Integer, V ds.Number](s Set[K,V], l int, t *testing.T) { - keys := ds.NewRandomArrayList[V](l, l) + keys := ds.NewRandomArrayList[K](l, l) randoms := ds.NewRandomArrayList[V](l, -1) mapping := make(map[K]V, l) @@ -142,15 +139,19 @@ func BenchmarkGoMap(t *testing.B) { } func benchmark[K ds.Integer, V ds.Number](s Set[K,V], l int, b *testing.B) { - list := ds.NewRandomArrayList[V](l, -1) + list := ds.NewRandomArrayList[K](l, -1) b.Run(fmt.Sprintf("random(%d)", l), func(b *testing.B) { + var benchResult V + b.ResetTimer() for i, a := range list { - s.Put(a, i) + s.Put(a, V(i)) } for _, a := range list { benchResult, _ = s.Get(a) } + + _ = benchResult }) } |
