From f8a8b77976fbb428d0a9d81bfa305883377d1c5c Mon Sep 17 00:00:00 2001 From: Goutham Veeramachaneni Date: Sun, 9 Apr 2017 17:20:39 +0530 Subject: [PATCH] postings: Fix bad test and revert changed logic A bad test was introduced a couple of commits ago which also made changes to pass the bad test. Fixed the test and revert the changes. Signed-off-by: Goutham Veeramachaneni --- postings.go | 25 +------------------------ postings_test.go | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 27 deletions(-) diff --git a/postings.go b/postings.go index fcbbd4235..7365099d8 100644 --- a/postings.go +++ b/postings.go @@ -201,30 +201,7 @@ func (it *mergedPostings) Seek(id uint32) bool { it.aok = it.a.Seek(id) it.bok = it.b.Seek(id) - if !it.aok && !it.bok { - return false - } - - if !it.aok { - it.cur = it.b.At() - - return true - } - if !it.bok { - it.cur = it.a.At() - - return true - } - - acur, bcur := it.a.At(), it.b.At() - - if acur < bcur { - it.cur = acur - } else { - it.cur = bcur - } - - return true + return it.Next() } func (it *mergedPostings) Err() error { diff --git a/postings_test.go b/postings_test.go index 62b0dd726..4801b486e 100644 --- a/postings_test.go +++ b/postings_test.go @@ -219,9 +219,18 @@ func TestMerge(t *testing.T) { require.Equal(t, c.success, p.Seek(c.seek)) - res, err := expandPostings(p) - require.NoError(t, err) - require.Equal(t, c.res, res) + if c.success { + // check the current element and then proceed to check the rest. + i := 0 + require.Equal(t, c.res[i], p.At()) + + for p.Next() { + i++ + require.Equal(t, int(c.res[i]), int(p.At())) + } + + require.Equal(t, len(c.res)-1, i) + } } return