-
Notifications
You must be signed in to change notification settings - Fork 0
/
tools_test.go
71 lines (56 loc) · 1.2 KB
/
tools_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 main
import (
"errors"
"testing"
)
func TestCheck(t *testing.T) {
defer func() {
r := recover()
if r != nil {
t.Errorf("check should not panic")
}
}()
check(nil)
}
func TestCheckWithErr(t *testing.T) {
defer func() {
r := recover()
if r == nil {
t.Errorf("check should panic")
}
}()
check(errors.New("error"))
}
func TestByteSlice(t *testing.T) {
if !byteSliceEquals([]byte{1, 2, 3}, []byte{1, 2, 3}) {
t.Error("Expected true")
}
}
func TestByteSliceWrong(t *testing.T) {
if byteSliceEquals([]byte{7, 2, 3, 4, 5, 6}, []byte{1, 2, 3, 4, 5, 6}) {
t.Error("Expected {1,2,3,4,5,6}")
}
}
func TestByteSliceNil(t *testing.T) {
if byteSliceEquals([]byte{7, 2, 3, 4, 5, 6}, nil) {
t.Error("Expected false")
}
}
func TestByteSliceDifferentLength(t *testing.T) {
if byteSliceEquals([]byte{7, 2, 3, 4, 5, 6}, []byte{1, 2, 3}) {
t.Error("Expected false")
}
}
func TestByteSliceBothNil(t *testing.T) {
if !byteSliceEquals(nil, nil) {
t.Error("Expected true")
}
}
func TestDifference(t *testing.T) {
a := []string{"cat", "dog"}
b := []string{"cat", "dog", "mouse"}
mouse := difference(b, a)
if len(mouse) != 1 && mouse[0] != "mouse" {
t.Error("Expected [\"mouse\"]")
}
}