-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils_test.go
49 lines (41 loc) · 939 Bytes
/
utils_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
package utils
import (
"bytes"
"encoding/hex"
"testing"
)
func TestMax(t *testing.T) {
if Max(10, 11) != 11 {
t.Error("Max function failed")
}
if Max(11, 10) != 11 {
t.Error("Max function failed")
}
}
func TestMin(t *testing.T) {
if Min(10, 11) != 10 {
t.Error("Min function failed")
}
if Min(11, 10) != 10 {
t.Error("Min function failed")
}
}
func TestCloneByteSlice(t *testing.T) {
b, _ := hex.DecodeString("aabbccddeeff")
b2 := CloneByteSlice(b)
if &b == &b2 {
t.Error("Memory addresses of cloned byteslice is equal")
}
if !bytes.Equal(b, b2) {
t.Error("Byteslices have different content")
}
}
func TestGetBit(t *testing.T) {
b, _ := hex.DecodeString("aabbccddeeff")
bits := "101010101011101111001100110111011110111011111111"
for i, bit := range bits {
if GetBit(b, uint(i)) != (bit == '1') {
t.Errorf("Failed at bit %d - expected %t , got %t", i, (bit == '1'), GetBit(b, uint(i)))
}
}
}