-
Notifications
You must be signed in to change notification settings - Fork 0
/
bitops_test.go
55 lines (45 loc) · 949 Bytes
/
bitops_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
package bitops
import (
"testing"
)
func TestSetBit(t *testing.T) {
var testInt uint64
testInt = 32
SetBit(&testInt, 5, false)
if testInt != uint64(0) {
t.Errorf("Failed set bit to false test")
}
SetBit(&testInt, 5, false)
if testInt != uint64(0) {
t.Errorf("Failed set bit to false again test")
}
testInt = 0
SetBit(&testInt, 7, true)
if testInt != uint64(128) {
t.Errorf("Failed set bit to true test")
}
SetBit(&testInt, 7, true)
if testInt != uint64(128) {
t.Errorf("Failed set bit to true again test")
}
}
func TestQueryBit(t *testing.T) {
var testInt uint64
testInt = 32
if QueryBit(&testInt, 2) {
t.Error("Failed query bit false test")
}
if !QueryBit(&testInt, 5) {
t.Error("Failed query bit true test")
}
}
func TestFlipAll(t *testing.T) {
var testInt uint64
testInt = 32
for i := 0; i < 64; i++ {
SetBit(&testInt, i, true)
}
if ^uint64(0) != testInt {
t.Error("Failed to flip all")
}
}