-
Notifications
You must be signed in to change notification settings - Fork 0
/
print_test.go
71 lines (58 loc) · 1.42 KB
/
print_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
package bits
import (
"fmt"
"testing"
)
func assertPanic(t *testing.T, msg string, f func()) {
defer func() {
if r := recover(); r == nil {
t.Error(msg)
}
}()
f()
}
func TestExcessBytesFromStringFails(t *testing.T) {
assertPanic(t, "Blah", func() {
_ = CreateByteFromString("01010001010010101")
})
}
func TestByteFromStringNotMatches(t *testing.T) {
a := CreateByteFromString("10101011")
b := byte(13)
if a == b {
fmt.Printf("Bytes should not match: %08b - %08b\n", a, b)
t.Fail()
}
}
func TestByteFromStringMatches(t *testing.T) {
a := CreateByteFromString("10101011")
b := byte(171)
if a != b {
fmt.Printf("Bytes should match: %08b - %08b\n", a, b)
t.Fail()
}
}
func TestBytesFromStringNotMatches(t *testing.T) {
a := CreateBytesFromString("1010101100101111")
b := []byte{byte(171), byte(2)}
if a[0] == b[0] && a[1] == b[1] && len(a) == len(b) {
fmt.Println("Byte arrays should not match")
t.Fail()
}
}
func TestBytesFromStringMatches(t *testing.T) {
a := CreateBytesFromString("1010101100101111")
b := []byte{byte(171), byte(47)}
if a[0] != b[0] || a[1] != b[1] || len(a) != len(b) {
fmt.Println("Byte arrays should match")
t.Fail()
}
}
func TestBytesFromStringWithSpacesMatches(t *testing.T) {
a := CreateBytesFromString("10101011 00101111")
b := []byte{byte(171), byte(47)}
if a[0] != b[0] || a[1] != b[1] || len(a) != len(b) {
fmt.Println("Byte arrays should match")
t.Fail()
}
}