Skip to content

Commit

Permalink
beacon: Improve Utils Coverage to 100% (#415)
Browse files Browse the repository at this point in the history
  • Loading branch information
terencechain authored and rauljordan committed Aug 19, 2018
1 parent d3b5a7c commit 0982442
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions beacon-chain/utils/checkbit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,33 @@ import (
"testing"
)

func TestCheckBit(t *testing.T) {
tests := []struct {
a []byte
b int
c bool
}{
{a: []byte{200}, b: 4, c: true}, //11001000
{a: []byte{148}, b: 5, c: true}, //10010100
{a: []byte{146}, b: 4, c: false}, //10010010
{a: []byte{179}, b: 7, c: true}, //10110011
{a: []byte{49}, b: 6, c: false}, //00110001

}
for _, tt := range tests {
set, err := CheckBit(tt.a, tt.b)
if err != nil {
t.Fatalf("Call check bit failed: %v", err)
}
if set != tt.c {
t.Errorf("Test check bit set failed with %v and location %v", tt.a, tt.b)
}
}
if _, err := CheckBit([]byte{1}, 8); err == nil {
t.Errorf("Call check bit should have failed with invalid index")
}
}

func TestBitSetCount(t *testing.T) {
tests := []struct {
a byte
Expand Down

0 comments on commit 0982442

Please sign in to comment.