-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbinenc_test.go
34 lines (29 loc) · 893 Bytes
/
binenc_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
package binenc
import "testing"
func TestEncode(t *testing.T) {
key := Key{"alfa", "bravo", "charlie", "delta", "echo", "foxtrot", "golf"}
example := []string{"bravo", "delta", "foxtrot"}
want := int64(42)
encoded, err := key.Encode(example)
if want != encoded || err != nil {
t.Fatalf(`Encode([]string{"bravo", "delta", "foxtrot"}) = %v, %v, want %v, nil`, encoded, err, want)
}
}
func TestDecode(t *testing.T) {
key := Key{"alfa", "bravo", "charlie", "delta", "echo", "foxtrot", "golf"}
example := int64(42)
want := []string{"bravo", "delta", "foxtrot"}
decoded := key.Decode(example)
if !equalSlices(want, decoded) {
t.Fatalf(`Decoded(int64(42)) = %v, want %v`, decoded, want)
}
}
// Test if slices contains the same strings (not ordered)
func equalSlices(s1 []string, s2 []string) bool {
for i, v := range s1 {
if v != s2[i] {
return false
}
}
return true
}