diff --git a/roaring/roaring.go b/roaring/roaring.go index 3cccf3af1..aa42fb380 100644 --- a/roaring/roaring.go +++ b/roaring/roaring.go @@ -4617,8 +4617,8 @@ func compareArrayArray(a1, a2 []uint16) error { // an error describing any difference it finds. This is mostly intended // for use in tests that expect equality. func (c *Container) BitwiseCompare(c2 *Container) error { - if c.N() != c2.N() { - return errors.New("containers are different lengths") + if cn, c2n := c.N(), c2.N(); cn != c2n { + return errors.Errorf("containers are different lengths: %d, %d", cn, c2n) } if c.N() == 0 { return nil diff --git a/roaring/roaring_internal_test.go b/roaring/roaring_internal_test.go index 4cf0b48d6..e52a29b23 100644 --- a/roaring/roaring_internal_test.go +++ b/roaring/roaring_internal_test.go @@ -4391,12 +4391,18 @@ func TestUnionRunRunInPlaceBitwiseCompare(t *testing.T) { for _, a := range runs { for _, b := range runs { t.Run(a.name+"-"+b.name, func(t *testing.T) { - arun := doContainer(containerRun, a.run).Thaw() - brun := doContainer(containerRun, b.run).Thaw() + arun := doContainer(containerRun, a.run) + brun := doContainer(containerRun, b.run) out1 := unionBitmapRunInPlace(arun.runToBitmap(), brun) out2 := unionRunRunInPlace(arun, brun) + // Because these containers have been modified using in-place + // methods, we need to repair them before comparison to ensure + // that their `n` value is updated. + out1.Repair() + out2.Repair() + err := out1.BitwiseCompare(out2.runToBitmap()) if err != nil { t.Fatal(err)