Test CountRange on non-container ranges.

This test was supposed to check against all the container types,
but especially bitmaps, but turns out not to work because the
containers turn into RLE containers. Oops. Now, we start with
every-other-bit for the first 8k, then start filling in the holes,
so we get some bitmap containers and then start generating
RLE containers.
This commit is contained in:
Seebs 2021-01-25 14:41:05 -06:00
parent 13c63baa14
commit d1a9c91a96

View file

@ -37,20 +37,29 @@ func requireCountRangeSampleData(tb testing.TB) (*fragment, Tx) {
// request that each container get its own copy of the bitmap.
var bitmapSample [1025]uint64
for i := range arraySample {
arraySample[i] = uint16(i)
arraySample[i] = uint16(i * 2)
}
for i := 0; i < 4096/64; i++ {
bitmapSample[i] = ^uint64(0)
// Put corresponding bits in the bitmap...
for i := 0; i < 4096/32; i++ {
// bit 0 is 0x1, bit 2 is 0x4, so even-numbered bits
// are 0x5555....
bitmapSample[i] = 0x5555555555555555
}
bm := roaring.NewSliceBitmap()
for n := 0; n < 4096 && n < countRangeMaxN; n++ {
c := roaring.NewContainerArray(arraySample[:n])
bm.Put(uint64(n), c)
}
for n := 4096; n < countRangeMaxN; n++ {
// Start filling in the missing bits. This starts us out with
// bitmap containers, but then eventually converts to things
// that are more likely to be run containers. At the end of this,
// we should have exactly the first 8,192 bits set, for a single
// run of 8k.
for n := 4096; n < 8192; n++ {
c := roaring.NewContainerBitmapN(bitmapSample[:], int32(n))
bm.Put(uint64(n), c)
bitmapSample[n/64] |= 1 << (n % 64)
w := n - 4096
bitmapSample[w/32] |= 1 << (((n % 32) * 2) + 1)
}
var asBytes bytes.Buffer
n, err := bm.WriteTo(&asBytes)
@ -90,11 +99,14 @@ func TestTx_CountRange(t *testing.T) {
expected := uint64(0)
j := uint64(0)
for i := uint64(0); i < countRangeMaxN; i += 7 {
expected += i
if i%4 == 3 {
expected -= (j * 7) + 21
j += 7
}
got, err := tx.CountRange("i", "f", viewStandard, 0, uint64(j)<<16, uint64(i)<<16)
// Every other bit gets set, for a total of i bits in container
// i, so they're all in the first (i*2) bits of the container.
got, err := tx.CountRange("i", "f", viewStandard, 0, uint64(j)<<16, (uint64(i)<<16)+(i*2))
if err != nil {
t.Fatalf("counting range: %v", err)
}
@ -102,7 +114,8 @@ func TestTx_CountRange(t *testing.T) {
t.Fatalf("counting from container %d to %d, expected %d, got %d",
j, i, expected, got)
}
expected += (i * 7) + 21
// The -i here undoes the +i at the top of this loop.
expected += (i * 7) + 21 - i
}
}