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...
This commit is contained in:
Seebs 2020-09-08 12:21:01 -05:00
parent ecacbf65d4
commit 17ba2e35a9

View file

@ -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 {