-
Notifications
You must be signed in to change notification settings - Fork 166
/
binary_test.go
68 lines (60 loc) · 1.47 KB
/
binary_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
package rueidis
import (
"encoding/json"
"reflect"
"strings"
"testing"
)
func TestBinaryString(t *testing.T) {
if str := []byte{0, 1, 2, 3, 4}; string(str) != BinaryString(str) {
t.Fatalf("BinaryString mismatch")
}
}
func TestJSON(t *testing.T) {
if v := JSON("a"); v != `"a"` {
t.Fatalf("unexpected JSON result")
}
}
func TestJSONPanic(t *testing.T) {
defer func() {
if m := recover().(*json.UnsupportedValueError); !strings.Contains(m.Error(), "encountered a cycle") {
t.Fatalf("should panic")
}
}()
a := &recursive{}
a.R = a
JSON(a)
}
func TestVectorString32(t *testing.T) {
for _, test := range [][]float32{
{},
{0, 0, 0, 0},
{9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{.9, .9, .9, .9, .9, .9, .9, .9, .9, .9, .9},
{-.1, -.1, -.1, -.1, -.1, -.1, -.1, -.1, -.1, -.1},
{.1, -.1, .1, -.1, .1, -.1, .1, -.1, .1, -.1},
} {
if !reflect.DeepEqual(test, ToVector32(VectorString32(test))) {
t.Fatalf("fail to convert %v", test)
}
}
}
func TestVectorString64(t *testing.T) {
for _, test := range [][]float64{
{},
{0, 0, 0, 0},
{9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9},
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
{.9, .9, .9, .9, .9, .9, .9, .9, .9, .9, .9},
{-.1, -.1, -.1, -.1, -.1, -.1, -.1, -.1, -.1, -.1},
{.1, -.1, .1, -.1, .1, -.1, .1, -.1, .1, -.1},
} {
if !reflect.DeepEqual(test, ToVector64(VectorString64(test))) {
t.Fatalf("fail to convert %v", test)
}
}
}
type recursive struct {
R *recursive
}