Skip to content

Commit

Permalink
stree: add more expressive tests for Find
Browse files Browse the repository at this point in the history
  • Loading branch information
creachadair committed Jan 5, 2025
1 parent bd85c99 commit 0f17035
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions stree/stree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,40 +324,46 @@ func TestCursor(t *testing.T) {
})

t.Run("Find", func(t *testing.T) {
tree := stree.New(250, strings.Compare, "a", "e", "i", "o", "u")
tree := stree.New(250, strings.Compare, "apple", "ennui", "iota", "opal", "usury")

t.Run("None", func(t *testing.T) {
if got := tree.Find("z"); got != nil {
t.Errorf("Find z: got %v, want nil", got)
}
})
t.Run("Exact", func(t *testing.T) {
if got := tree.Find("e"); got.Key() != "e" {
t.Errorf("Find e: got %q, want e", got.Key())
if got := tree.Find("ennui"); got.Key() != "ennui" {
t.Errorf("Find ennui: got %q, want ennui", got.Key())
}
})
t.Run("Before", func(t *testing.T) {
got := tree.Find("0")
if got.Key() != "a" {
t.Errorf("Find 0: got %q, want a", got.Key())
if got.Key() != "apple" {
t.Errorf("Find 0: got %q, want apple", got.Key())
}
if next := got.Next(); next.Key() != "e" {
t.Errorf("Next a: got %q, want e", next.Key())
if next := got.Next(); next.Key() != "ennui" {
t.Errorf("Next apple: got %q, want ennui", next.Key())
}
if prev := got.Prev().Prev(); prev.Valid() {
t.Errorf("Prev a: got %v, want invalid", prev)
t.Errorf("Prev apple: got %q, want invalid", prev.Key())
}
})
t.Run("Edge", func(t *testing.T) {
got := tree.Find("e")
if got.Key() != "ennui" {
t.Errorf("Find e: got %q, want ennui", got.Key())
}
})
t.Run("Between", func(t *testing.T) {
got := tree.Find("k")
if got.Key() != "o" {
t.Errorf("Find k: got %q, want o", got.Key())
if got.Key() != "opal" {
t.Errorf("Find k: got %q, want opal", got.Key())
}
if next := got.Next(); next.Key() != "u" {
t.Errorf("Next o: got %q, want u", next.Key())
if next := got.Next(); next.Key() != "usury" {
t.Errorf("Next opal: got %q, want usuru", next.Key())
}
if prev := got.Prev().Prev(); prev.Key() != "i" {
t.Errorf("Prev o: got %q, want i", prev.Key())
if prev := got.Prev().Prev(); prev.Key() != "iota" {
t.Errorf("Prev opal: got %q, want iota", prev.Key())
}
})
})
Expand Down

0 comments on commit 0f17035

Please sign in to comment.