Skip to content

Commit

Permalink
stree: clean up excess type instantiations
Browse files Browse the repository at this point in the history
  • Loading branch information
creachadair committed Feb 19, 2024
1 parent fda9b4d commit 924d12c
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions stree/stree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func allWords(tree *stree.Tree[string]) []string {
}

func sortedUnique(ws []string, drop mapset.Set[string]) []string {
out := mapset.New[string](ws...).RemoveAll(drop).Slice()
out := mapset.New(ws...).RemoveAll(drop).Slice()
sort.Strings(out)
return out
}
Expand Down Expand Up @@ -54,7 +54,7 @@ func TestNew(t *testing.T) {

func TestRemoval(t *testing.T) {
words := strings.Fields(`a foolish consistency is the hobgoblin of little minds`)
tree := stree.New[string](0, cmp.Compare[string], words...)
tree := stree.New(0, cmp.Compare, words...)

got := allWords(tree)
want := sortedUnique(words, nil)
Expand All @@ -76,14 +76,9 @@ func TestRemoval(t *testing.T) {
}

func TestInsertion(t *testing.T) {
type kv struct {
key string
val int
}
type kv = stree.KV[string, int]

tree := stree.New[kv](300, func(a, b kv) int {
return cmp.Compare[string](a.key, b.key)
})
tree := stree.New(300, kv{}.Compare(cmp.Compare))
checkInsert := func(f func(kv) bool, key string, val int, ok bool) {
t.Helper()
got := f(kv{key, val})
Expand All @@ -92,11 +87,11 @@ func TestInsertion(t *testing.T) {
}
}
checkValue := func(key string, want int) {
got, ok := tree.Get(kv{key: key})
got, ok := tree.Get(kv{Key: key})
if !ok {
t.Errorf("Key %q not found", key)
} else if got.val != want {
t.Errorf("Key %q: got %v, want %v", key, got.val, want)
} else if got.Value != want {
t.Errorf("Key %q: got %v, want %v", key, got.Value, want)
}
}

Expand Down

0 comments on commit 924d12c

Please sign in to comment.