mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-05 08:10:50 +00:00
Update check function for run containers, add tests
This commit is contained in:
parent
bfce3a0746
commit
ea59de4234
2 changed files with 44 additions and 3 deletions
|
|
@ -1738,15 +1738,24 @@ func (c *container) info() ContainerInfo {
|
|||
func (c *container) check() error {
|
||||
var a ErrorList
|
||||
|
||||
if c.n <= ArrayMaxSize {
|
||||
// TODO check run here
|
||||
if c.isArray() {
|
||||
if len(c.array) != c.n {
|
||||
a.Append(fmt.Errorf("array count mismatch: count=%d, n=%d", len(c.array), c.n))
|
||||
}
|
||||
} else {
|
||||
} else if c.isRun() {
|
||||
runCount := c.runCountRange(0, 0xFFFFFFFF)
|
||||
if runCount != c.n {
|
||||
a.Append(fmt.Errorf("run count mismatch: count=%d, n=%d", runCount, c.n))
|
||||
}
|
||||
} else if c.isBitmap() {
|
||||
if n := c.bitmapCountRange(0, uint32(len(c.bitmap)*64)); n != c.n {
|
||||
a.Append(fmt.Errorf("bitmap count mismatch: count=%d, n=%d", n, c.n))
|
||||
}
|
||||
} else {
|
||||
a.Append(fmt.Errorf("empty container"))
|
||||
if c.n != 0 {
|
||||
a.Append(fmt.Errorf("empty container with nonzero count: n=%d", c.n))
|
||||
}
|
||||
}
|
||||
|
||||
if a == nil {
|
||||
|
|
|
|||
|
|
@ -28,6 +28,38 @@ import (
|
|||
_ "github.com/pilosa/pilosa/test"
|
||||
)
|
||||
|
||||
func TestCheckBitmap(t *testing.T) {
|
||||
b := roaring.NewBitmap()
|
||||
for i := uint64(61000); i < 71000; i++ {
|
||||
b.Add(i)
|
||||
}
|
||||
for i := uint64(75000); i < 75100; i++ {
|
||||
b.Add(i)
|
||||
}
|
||||
|
||||
err := b.Check()
|
||||
if err != nil {
|
||||
t.Fatalf("%v\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckArray(t *testing.T) {
|
||||
b := roaring.NewBitmap(0, 1, 10, 100, 1000, 10000, 90000, 100000)
|
||||
err := b.Check()
|
||||
if err != nil {
|
||||
t.Fatalf("%v\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckRun(t *testing.T) {
|
||||
b := roaring.NewBitmap(0, 1, 2, 3, 4, 5, 1000, 1001, 1002, 1003, 1004, 1005, 100000, 100001, 100002, 100003, 100004, 100005)
|
||||
b.Optimize() // convert to runs
|
||||
err := b.Check()
|
||||
if err != nil {
|
||||
t.Fatalf("%v\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure an empty bitmap returns false if checking for existence.
|
||||
func TestBitmap_Contains_Empty(t *testing.T) {
|
||||
if roaring.NewBitmap().Contains(1000) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue