forked from robinson/gos7
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper_test.go
50 lines (45 loc) · 817 Bytes
/
helper_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package gos7
import (
"testing"
)
func TestHelper_SetBoolAt(t *testing.T) {
var h Helper
input := []struct {
in byte
out byte
pos uint
data bool
}{
{0b101, 0b111, 1, true},
{0b111, 0b101, 1, false},
{0b101, 0b001, 2, false},
{0b111, 0b011, 2, false},
{0b11111111, 0b11011111, 5, false},
}
for _, i := range input {
b := h.SetBoolAt(i.in, i.pos, i.data)
if b != i.out {
t.Errorf("expected %b given %b", i.out, b)
}
}
}
func TestHelper_GetBoolAt(t *testing.T) {
var h Helper
input := []struct {
in byte
pos uint
out bool
}{
{0b101, 1, false},
{0b111, 1, true},
{0b101, 2, true},
{0b011, 2, false},
{0b11111111, 5, true},
}
for _, i := range input {
b := h.GetBoolAt(i.in, i.pos)
if b != i.out {
t.Errorf("expected %v given %v", i.out, b)
}
}
}