Browse Source

BitArray.IsEmpty()

pull/1842/head
Ethan Buchman 9 years ago
parent
commit
dcfa46af13
2 changed files with 30 additions and 0 deletions
  1. +14
    -0
      bit_array.go
  2. +16
    -0
      bit_array_test.go

+ 14
- 0
bit_array.go View File

@ -167,6 +167,20 @@ func (bA *BitArray) Sub(o *BitArray) *BitArray {
}
}
func (bA *BitArray) IsEmpty() bool {
if bA == nil {
return true // should this be opposite?
}
bA.mtx.Lock()
defer bA.mtx.Unlock()
for _, e := range bA.Elems {
if e > 0 {
return false
}
}
return true
}
func (bA *BitArray) IsFull() bool {
if bA == nil {
return true


+ 16
- 0
bit_array_test.go View File

@ -148,3 +148,19 @@ func TestBytes(t *testing.T) {
bA.SetIndex(9, true)
check(bA, []byte{0x80, 0x03})
}
func TestEmptyFull(t *testing.T) {
ns := []int{47, 123}
for _, n := range ns {
bA := NewBitArray(n)
if !bA.IsEmpty() {
t.Fatal("Expected bit array to be empty")
}
for i := 0; i < n; i++ {
bA.SetIndex(i, true)
}
if !bA.IsFull() {
t.Fatal("Expected bit array to be full")
}
}
}

Loading…
Cancel
Save