Skip to content

Commit

Permalink
Move new AllIntersections test to search_test.go
Browse files Browse the repository at this point in the history
  • Loading branch information
ttjoseph authored and rdleal committed Jan 11, 2024
1 parent 4dfeb9b commit 5d9b9c7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
17 changes: 0 additions & 17 deletions interval/insert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,23 +125,6 @@ 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
21 changes: 21 additions & 0 deletions interval/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,27 @@ func TestSearchTree_AllIntersections(t *testing.T) {
}
})
}

// 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)

start, end := 10, 20
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 !ok {
t.Errorf("st2.AllIntersections(%v, %v): unable to retreive any values, want values %v", start, end, want)
}

if !reflect.DeepEqual(got, want) {
t.Errorf("st2.AllIntersections(%v, %v): got unexpected values %v, want values %v", start, end, got, want)
}
}

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

0 comments on commit 5d9b9c7

Please sign in to comment.