···11+// Copyright 2019 Google Inc. All rights reserved.
22+//
33+// Licensed under the Apache License, Version 2.0 (the "License");
44+// you may not use this file except in compliance with the License.
55+// You may obtain a copy of the License at
66+//
77+// http://www.apache.org/licenses/LICENSE-2.0
88+//
99+// Unless required by applicable law or agreed to in writing, software
1010+// distributed under the License is distributed on an "AS IS" BASIS,
1111+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212+// See the License for the specific language governing permissions and
1313+// limitations under the License.
1414+1515+package zoekt
1616+1717+import (
1818+ "reflect"
1919+ "sort"
2020+ "testing"
2121+ "testing/quick"
2222+2323+ "github.com/google/go-cmp/cmp"
2424+)
2525+2626+func TestCompressedPostingIterator_limit(t *testing.T) {
2727+ f := func(nums, limits []uint32) bool {
2828+ if len(nums) == 0 || len(limits) == 0 {
2929+ return true
3030+ }
3131+3232+ nums = sortedUnique(nums)
3333+ sort.Slice(limits, func(i, j int) bool { return limits[i] < limits[j] })
3434+3535+ want := doHitIterator(&inMemoryIterator{postings: nums}, limits)
3636+3737+ it := newCompressedPostingIterator(toDeltas(nums), stringToNGram("abc"))
3838+ got := doHitIterator(it, limits)
3939+ if !reflect.DeepEqual(want, got) {
4040+ t.Log(cmp.Diff(want, got))
4141+ return false
4242+ }
4343+ return true
4444+ }
4545+ if err := quick.Check(f, nil); err != nil {
4646+ t.Error(err)
4747+ }
4848+}
4949+5050+func doHitIterator(it hitIterator, limits []uint32) []uint32 {
5151+ var nums []uint32
5252+ for _, limit := range limits {
5353+ it.next(limit)
5454+ nums = append(nums, it.first())
5555+ }
5656+ return nums
5757+}