Add check for multiple all iterators
Update test to reflect that the two Alls will be collapsed, also fix the test of tag optimization to use fixed iterators.
This commit is contained in:
parent
f54a84ff0b
commit
ac1fa668e7
2 changed files with 51 additions and 3 deletions
|
|
@ -73,7 +73,7 @@ func TestNullIteratorAnd(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestReorderWithTag(t *testing.T) {
|
||||
func TestAllPromotion(t *testing.T) {
|
||||
qs := &store{
|
||||
data: []string{},
|
||||
iter: NewFixed(Identity),
|
||||
|
|
@ -91,6 +91,43 @@ func TestReorderWithTag(t *testing.T) {
|
|||
if !changed {
|
||||
t.Error("Expected new iterator")
|
||||
}
|
||||
if newIt.Type() != graph.All {
|
||||
t.Error("Should have promoted the All iterator")
|
||||
}
|
||||
expectedTags := []string{"good", "slow"}
|
||||
tagsOut := make([]string, 0)
|
||||
for _, x := range newIt.Tagger().Tags() {
|
||||
tagsOut = append(tagsOut, x)
|
||||
}
|
||||
sort.Strings(tagsOut)
|
||||
if !reflect.DeepEqual(expectedTags, tagsOut) {
|
||||
t.Fatalf("Tags don't match: expected: %#v, got: %#v", expectedTags, tagsOut)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReorderWithTag(t *testing.T) {
|
||||
qs := &store{
|
||||
data: []string{},
|
||||
iter: NewFixed(Identity),
|
||||
}
|
||||
all := NewFixed(Identity)
|
||||
all.Add(3)
|
||||
all.Tagger().Add("good")
|
||||
all2 := NewFixed(Identity)
|
||||
all2.Tagger().Add("slow")
|
||||
all2.Add(3)
|
||||
all2.Add(4)
|
||||
all2.Add(5)
|
||||
all2.Add(6)
|
||||
a := NewAnd(qs)
|
||||
// Make all2 the default iterator
|
||||
a.AddSubIterator(all2)
|
||||
a.AddSubIterator(all)
|
||||
|
||||
newIt, changed := a.Optimize()
|
||||
if !changed {
|
||||
t.Error("Expected new iterator")
|
||||
}
|
||||
expectedTags := []string{"good", "slow"}
|
||||
tagsOut := make([]string, 0)
|
||||
for _, sub := range newIt.SubIterators() {
|
||||
|
|
@ -98,8 +135,12 @@ func TestReorderWithTag(t *testing.T) {
|
|||
tagsOut = append(tagsOut, x)
|
||||
}
|
||||
}
|
||||
for _, x := range newIt.Tagger().Tags() {
|
||||
tagsOut = append(tagsOut, x)
|
||||
}
|
||||
sort.Strings(tagsOut)
|
||||
if !reflect.DeepEqual(expectedTags, tagsOut) {
|
||||
t.Fatal("Tags don't match")
|
||||
t.Fatalf("Tags don't match: expected: %#v, got: %#v", expectedTags, tagsOut)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue