Skip to content

Commit

Permalink
Fix bitmap test and check bitmap bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
dadgar committed Aug 16, 2016
1 parent 59929b1 commit c8514f9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion nomad/structs/bitmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (b Bitmap) Clear() {
// on the passed parameter in the passed range
func (b Bitmap) IndexesInRange(set bool, from, to uint) []int {
var indexes []int
for i := from; i <= to; i++ {
for i := from; i <= to && i < b.Size(); i++ {
c := b.Check(i)
if c && set || !c && !set {
indexes = append(indexes, int(i))
Expand Down
6 changes: 3 additions & 3 deletions nomad/structs/bitmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ func TestBitmap(t *testing.T) {
}

// Check the indexes
idxs := b.IndexesInRange(true, 0, 256)
idxs := b.IndexesInRange(true, 0, 500)
expected := []int{0, 255}
if !reflect.DeepEqual(idxs, expected) {
t.Fatalf("bad: got %#v; want %#v", idxs, expected)
}

idxs = b.IndexesInRange(true, 1, 256)
idxs = b.IndexesInRange(true, 1, 255)
expected = []int{255}
if !reflect.DeepEqual(idxs, expected) {
t.Fatalf("bad: got %#v; want %#v", idxs, expected)
Expand All @@ -73,7 +73,7 @@ func TestBitmap(t *testing.T) {
}

idxs = b.IndexesInRange(false, 100, 200)
if len(idxs) != 100 {
if len(idxs) != 101 {
t.Fatalf("bad")
}

Expand Down

0 comments on commit c8514f9

Please sign in to comment.