Skip to content

Commit

Permalink
Test that values are appended in MultiValueSearchTree (PR #6)
Browse files Browse the repository at this point in the history
  • Loading branch information
ttjoseph authored and rdleal committed Jan 11, 2024
1 parent afef621 commit 4dfeb9b
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions interval/insert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ func TestMultiValueSearchTree_Insert(t *testing.T) {
st := NewMultiValueSearchTree[string](func(x, y int) int { return x - y })
defer mustBeValidTree(t, st.root)

st.Insert(1, 2, "foo")
st.Insert(1, 2, "foo")
st.Insert(1, 2, "foo")

vals := []string{"value1", "value2", "value3", "value4"}
start, end := 17, 19

Expand All @@ -121,6 +125,23 @@ func TestMultiValueSearchTree_Insert(t *testing.T) {
if want := append(vals, val); !reflect.DeepEqual(got, want) {
t.Errorf("st.Find(%v, %v): got unexpected value %v; want %v", start, end, got, want)
}

// Ensure that values inserted for the same interval are appended rather than replacing what's there
st2 := NewMultiValueSearchTree[string](func(x, y int) int { return x - y })
defer mustBeValidTree(t, st2.root)

st2.Insert(start, end, "foo")
st2.Insert(start, end, "foo")
st2.Insert(start, end, "foo")
st2.Insert(start, end, "foo")
st2.Insert(start, end, "foo")

want := []string{"foo", "foo", "foo", "foo", "foo"}
got, ok = st2.AllIntersections(start, end)
if !reflect.DeepEqual(got, want) {
t.Errorf("st.AllIntersections(%v, %v): got unexpected values %v, want values %v", start, end, got, want)
}

}

func TestMultiValueSearchTree_Insert_PointInterval(t *testing.T) {
Expand Down

0 comments on commit 4dfeb9b

Please sign in to comment.