mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 02:44:59 +00:00
basic goconvey tests for bitmap
This commit is contained in:
parent
43554244c8
commit
9306290d96
1 changed files with 62 additions and 70 deletions
|
|
@ -2,77 +2,69 @@ package index
|
|||
|
||||
import (
|
||||
"testing"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
func TestCount(t *testing.T) {
|
||||
bm:= CreateRBBitmap()
|
||||
for i:=uint64(0); i<uint64(4096);i++{
|
||||
SetBit(bm,i)
|
||||
}
|
||||
bc1:= BitCount(bm)
|
||||
bc2:= bm.Count()
|
||||
if bc1 != bc2 {
|
||||
t.Errorf("Counts not equal BitCount (%d) bm.Count(%d)",bc1,bc2)
|
||||
}
|
||||
func TestSomething(t *testing.T) {
|
||||
Convey("function BitCount should equal method bm.Count()", t, func() {
|
||||
bm:= CreateRBBitmap()
|
||||
for i:=uint64(0); i<uint64(4096);i++{
|
||||
SetBit(bm,i)
|
||||
}
|
||||
bc1:= BitCount(bm)
|
||||
bc2:= bm.Count()
|
||||
So(bc1, ShouldEqual, bc2)
|
||||
})
|
||||
Convey("function AND_NOT 1 and not 0 => true ", t, func() {
|
||||
bm1:= CreateRBBitmap()
|
||||
bm2:= CreateRBBitmap()
|
||||
SetBit(bm1,1)
|
||||
//SetBit(bm2,2)
|
||||
all:= AND_NOT(bm1,bm2)
|
||||
res :=BitCount(all)
|
||||
|
||||
if bc1 != uint64(4096){
|
||||
t.Errorf("Count (%d) no equal 4096",bc1)
|
||||
So(1, ShouldEqual, res)
|
||||
})
|
||||
/*
|
||||
SetBit(bm2,1)
|
||||
all= AND_NOT(bm1,bm2)
|
||||
res =BitCount(all)
|
||||
if res != 0{
|
||||
t.Errorf("SHOULD BE 0 => %d",res)
|
||||
}
|
||||
*/
|
||||
|
||||
//func TestUnion(t *testing.T) {
|
||||
Convey("UNION even + odd equal 4096 ", t, func() {
|
||||
even:= CreateRBBitmap()
|
||||
for i:=uint64(0); i<uint64(4096);i+=2{
|
||||
SetBit(even,i)
|
||||
}
|
||||
|
||||
odd:= CreateRBBitmap()
|
||||
for i:=uint64(1); i<uint64(4096);i+=2{
|
||||
SetBit(odd,i)
|
||||
}
|
||||
all:= Union(even,odd)
|
||||
total_bits:= BitCount(all)
|
||||
|
||||
So(total_bits, ShouldEqual, 4096)
|
||||
})
|
||||
|
||||
Convey("Intersection even - odd equal 0 ", t, func() {
|
||||
even:= CreateRBBitmap()
|
||||
for i:=uint64(0); i<uint64(4096);i+=2{
|
||||
SetBit(even,i)
|
||||
}
|
||||
|
||||
odd:= CreateRBBitmap()
|
||||
for i:=uint64(1); i<uint64(4096);i+=2{
|
||||
SetBit(odd,i)
|
||||
}
|
||||
all:= Intersection(even,odd)
|
||||
total_bits:= BitCount(all)
|
||||
|
||||
So(total_bits, ShouldEqual, 0)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
func TestANDNOT(t *testing.T){
|
||||
bm1:= CreateRBBitmap()
|
||||
bm2:= CreateRBBitmap()
|
||||
SetBit(bm1,1)
|
||||
//SetBit(bm2,2)
|
||||
all:= AND_NOT(bm1,bm2)
|
||||
res :=BitCount(all)
|
||||
if res != 1{
|
||||
t.Errorf("SHOULD BE 1 => %d",res)
|
||||
}
|
||||
|
||||
SetBit(bm2,1)
|
||||
all= AND_NOT(bm1,bm2)
|
||||
res =BitCount(all)
|
||||
if res != 0{
|
||||
t.Errorf("SHOULD BE 0 => %d",res)
|
||||
}
|
||||
|
||||
}
|
||||
func TestUnion(t *testing.T) {
|
||||
even:= CreateRBBitmap()
|
||||
for i:=uint64(0); i<uint64(4096);i+=2{
|
||||
SetBit(even,i)
|
||||
}
|
||||
|
||||
odd:= CreateRBBitmap()
|
||||
for i:=uint64(1); i<uint64(4096);i+=2{
|
||||
SetBit(odd,i)
|
||||
}
|
||||
all:= Union(even,odd)
|
||||
total_bits:= BitCount(all)
|
||||
|
||||
if total_bits != uint64(4096){
|
||||
t.Errorf("Count (%d) no equal 4096",total_bits)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestIntersect(t *testing.T){
|
||||
even:= CreateRBBitmap()
|
||||
for i:=uint64(0); i<uint64(4096);i+=2{
|
||||
SetBit(even,i)
|
||||
}
|
||||
|
||||
odd:= CreateRBBitmap()
|
||||
for i:=uint64(1); i<uint64(4096);i+=2{
|
||||
SetBit(odd,i)
|
||||
}
|
||||
all:= Intersection(even,odd)
|
||||
total_bits:= BitCount(all)
|
||||
|
||||
if total_bits != 0{
|
||||
t.Errorf("Count (%d) no equal 0",total_bits)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue