-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_test.go
131 lines (98 loc) · 3.2 KB
/
set_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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package bits
import (
"testing"
)
func TestUnset(t *testing.T) {
a := byte(255)
b := Unset(a, 3)
c := CreateByteFromString("11101111")
assertBytesMatch(t, b, c)
}
func TestSet(t *testing.T) {
a := byte(0)
b := Set(a, 3)
c := CreateByteFromString("00010000")
assertBytesMatch(t, b, c)
}
func TestSetIsUnchanged(t *testing.T) {
a := CreateByteFromString("00010000")
b := Set(a, 3)
c := CreateByteFromString("00010000")
assertBytesMatch(t, b, c)
}
func TestIsSetInRowTrueAtBeginning(t *testing.T) {
a := CreateBytesFromString("00000000 00000000 10000000 00000000")
b := IsSetInRow(a, 16)
assertBool(t, true, b)
}
func TestIsSetInRowTrueAtEnd(t *testing.T) {
a := CreateBytesFromString("00000000 00000001 00000000 00000000")
b := IsSetInRow(a, 15)
assertBool(t, true, b)
}
func TestIsSetInRowTrueInMiddle(t *testing.T) {
a := CreateBytesFromString("00000000 00001000 00000000 00000000")
b := IsSetInRow(a, 12)
assertBool(t, true, b)
}
func TestIsUnSetInRowTrueAtBeginning(t *testing.T) {
a := CreateBytesFromString("11111111 11111111 01111111 11111111")
b := IsSetInRow(a, 16)
assertBool(t, false, b)
}
func TestIsUnSetInRowTrueAtEnd(t *testing.T) {
a := CreateBytesFromString("11111111 11111110 11111111 11111111")
b := IsSetInRow(a, 15)
assertBool(t, false, b)
}
func TestIsUnSetInRowTrueInMiddle(t *testing.T) {
a := CreateBytesFromString("11111111 11110111 11111111 11111111")
b := IsSetInRow(a, 12)
assertBool(t, false, b)
}
func TestDoSetInRowTrueAtBeginning(t *testing.T) {
org := CreateBytesFromString("00000000 00000000 00000000 00000000")
exp := CreateBytesFromString("00000000 00000000 10000000 00000000")
act := SetInRow(org, 16)
assertByteSliceMatches(t, exp, act)
}
func TestDoSetInRowTrueAtEnd(t *testing.T) {
org := CreateBytesFromString("00000000 00000000 00000000 00000000")
exp := CreateBytesFromString("00000000 00000001 00000000 00000000")
act := SetInRow(org, 15)
assertByteSliceMatches(t, exp, act)
}
func TestDoSetInRowTrueInMiddle(t *testing.T) {
org := CreateBytesFromString("00000000 00000000 00000000 00000000")
exp := CreateBytesFromString("00000000 00001000 00000000 00000000")
act := SetInRow(org, 12)
assertByteSliceMatches(t, exp, act)
}
func TestDoUnSetInRowTrueAtBeginning(t *testing.T) {
org := CreateBytesFromString("11111111 11111111 11111111 11111111")
exp := CreateBytesFromString("11111111 11111111 01111111 11111111")
act := UnsetInRow(org, 16)
assertByteSliceMatches(t, exp, act)
}
func TestDoUnSetInRowTrueAtEnd(t *testing.T) {
org := CreateBytesFromString("11111111 11111111 11111111 11111111")
exp := CreateBytesFromString("11111111 11111110 11111111 11111111")
act := UnsetInRow(org, 15)
assertByteSliceMatches(t, exp, act)
}
func TestDoUnSetInRowTrueInMiddle(t *testing.T) {
org := CreateBytesFromString("11111111 11111111 11111111 11111111")
exp := CreateBytesFromString("11111111 11110111 11111111 11111111")
act := UnsetInRow(org, 12)
assertByteSliceMatches(t, exp, act)
}
func assertBool(t *testing.T, expected, actual bool) {
if expected != actual {
t.Errorf("Expected %v, received %v\n", expected, actual)
}
}
func assertBytesMatch(t *testing.T, a, b byte) {
if a != b {
t.Errorf("Bytes should match: %08b - %08b\n", a, b)
}
}