BitArray sub fix

This commit is contained in:
Jae Kwon
2014-10-25 14:27:53 -07:00
parent 13d70e4112
commit c3fc1a39ea
9 changed files with 112 additions and 42 deletions

View File

@ -111,17 +111,17 @@ func TestOr(t *testing.T) {
}
}
func TestSub(t *testing.T) {
func TestSub1(t *testing.T) {
bA1, _ := randBitArray(31)
bA2, _ := randBitArray(51)
bA3 := bA1.Sub(bA2)
if bA3.bits != 31 {
t.Error("Expected min bits")
if bA3.bits != bA1.bits {
t.Error("Expected bA1 bits")
}
if len(bA3.elems) != len(bA1.elems) {
t.Error("Expected min elems length")
t.Error("Expected bA1 elems length")
}
for i := uint(0); i < bA3.bits; i++ {
expected := bA1.GetIndex(i)
@ -133,3 +133,26 @@ func TestSub(t *testing.T) {
}
}
}
func TestSub2(t *testing.T) {
bA1, _ := randBitArray(51)
bA2, _ := randBitArray(31)
bA3 := bA1.Sub(bA2)
if bA3.bits != bA1.bits {
t.Error("Expected bA1 bits")
}
if len(bA3.elems) != len(bA1.elems) {
t.Error("Expected bA1 elems length")
}
for i := uint(0); i < bA3.bits; i++ {
expected := bA1.GetIndex(i)
if i < bA2.bits && bA2.GetIndex(i) {
expected = false
}
if bA3.GetIndex(i) != expected {
t.Error("Wrong bit from bA3")
}
}
}