From 17ba2e35a902a9dae568bd44df49d53bc35c528c Mon Sep 17 00:00:00 2001 From: Seebs Date: Tue, 8 Sep 2020 12:21:01 -0500 Subject: [PATCH] call helper functions every time to get new run slices If you just stash the results of the function when defining the test cases, the outcome is in part that you are reusing the same slices for multiple things. So, for instance, if you perform a union on the OddBitsSet slice, with the EvenBitsSet slice, the result is to overwrite the first entry in that slice with the 0-ffff run... But the original slice still exists, and then we reuse it and get a slice with a bit count of around 98,000. The underlying issue is that doContainer() is calling NewContainerRun(), which is simply using the provided slice, not copying it -- which is intentional, but the test has to be careful about it. We call repair on the one we think should be a bitmap. Theoretically maybe we should also repair the other one in case unionRunRun some day starts returning unrepaired bitmaps, which in principle it's allowed to do... --- roaring/roaring_internal_test.go | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/roaring/roaring_internal_test.go b/roaring/roaring_internal_test.go index b10964cb5..c75df2140 100644 --- a/roaring/roaring_internal_test.go +++ b/roaring/roaring_internal_test.go @@ -4375,26 +4375,28 @@ func BenchmarkUnionRunRunInPlace(bm *testing.B) { func TestUnionRunRunInPlaceBitwiseCompare(t *testing.T) { runs := []struct { name string - run []Interval16 + fn func() []Interval16 }{ - {name: "FirstBitSet", run: runFirstBitSet()}, - {name: "LastBitSet", run: runLastBitSet()}, - {name: "FirstBitUnset", run: runFirstBitUnset()}, - {name: "LastBitUnset", run: runLastBitUnset()}, - {name: "InnerBitsSet", run: runInnerBitsSet()}, - {name: "OuterBitsSet", run: runOuterBitsSet()}, - {name: "OddBitsSet", run: runOddBitsSet()}, - {name: "EvenBitsSet", run: runEvenBitsSet()}, + {name: "FirstBitSet", fn: runFirstBitSet}, + {name: "LastBitSet", fn: runLastBitSet}, + {name: "FirstBitUnset", fn: runFirstBitUnset}, + {name: "LastBitUnset", fn: runLastBitUnset}, + {name: "InnerBitsSet", fn: runInnerBitsSet}, + {name: "OuterBitsSet", fn: runOuterBitsSet}, + {name: "OddBitsSet", fn: runOddBitsSet}, + {name: "EvenBitsSet", fn: runEvenBitsSet}, } for _, a := range runs { for _, b := range runs { t.Run(a.name+"-"+b.name, func(t *testing.T) { - arun := doContainer(ContainerRun, a.run) - brun := doContainer(ContainerRun, b.run) + arun := doContainer(ContainerRun, a.fn()) + abm := doContainer(ContainerRun, a.fn()).runToBitmap() + brun := doContainer(ContainerRun, b.fn()) - out1 := unionBitmapRunInPlace(arun.runToBitmap(), brun) + out1 := unionBitmapRunInPlace(abm, brun) out2 := unionRunRunInPlace(arun, brun) + out1.Repair() err := out1.BitwiseCompare(out2.runToBitmap()) if err != nil {