-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhelpers_test.go
More file actions
121 lines (105 loc) · 2.71 KB
/
helpers_test.go
File metadata and controls
121 lines (105 loc) · 2.71 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package gofaker
import (
"testing"
)
func TestRandIntRange(t *testing.T) {
if randIntRange(5, 5) != 5 {
t.Error("You should have gotten 5 back")
}
}
func TestGetRandValueFail(t *testing.T) {
for _, test := range [][]string{nil, {}, {"not", "found"}, {"person", "notfound"}} {
if getRandValue(test) != "" {
t.Error("You should have gotten no value back")
}
}
}
func TestGetRandIntValueFail(t *testing.T) {
for _, test := range [][]string{nil, {}, {"not", "found"}, {"status_code", "notfound"}} {
if getRandIntValue(test) != 0 {
t.Error("You should have gotten no value back")
}
}
}
func TestRandFloat32RangeSame(t *testing.T) {
if randFloat32Range(5.0, 5.0) != 5.0 {
t.Error("You should have gotten 5.0 back")
}
}
func TestRandFloat64RangeSame(t *testing.T) {
if randFloat64Range(5.0, 5.0) != 5.0 {
t.Error("You should have gotten 5.0 back")
}
}
func TestReplaceWithNumbers(t *testing.T) {
if replaceWithNumbers("") != "" {
t.Error("You should have gotten an empty string")
}
}
func BenchmarkReplaceWithNumbers(b *testing.B) {
b.StopTimer()
for i := 0; i < b.N; i++ {
Seed(42)
b.StartTimer()
replaceWithNumbers("###☺#☻##☹##")
b.StopTimer()
}
}
func TestReplaceWithNumbersUnicode(t *testing.T) {
for _, test := range []struct{ in, should string }{
{"#界#世#", "5界7世8"},
{"☺#☻☹#", "☺5☻☹7"},
{"\x80#¼#語", "\x805¼7語"},
} {
Seed(42)
got := replaceWithNumbers(test.in)
if got == test.should {
continue
}
t.Errorf("for '%s' got '%s' should '%s'",
test.in, got, test.should)
}
}
func TestReplaceWithLetters(t *testing.T) {
if replaceWithLetters("") != "" {
t.Error("You should have gotten an empty string")
}
}
func TestReplaceWithHexLetters(t *testing.T) {
if "" != replaceWithHexLetters("") {
t.Error("You should have gotten an empty string")
}
}
func TestToFixed(t *testing.T) {
floats := [][]float64{
{123.1234567489, 123.123456},
{987.987654321, 987.987654},
}
for _, f := range floats {
if toFixed(f[0], 6) != f[1] {
t.Fatalf("%g did not equal %g. Got: %g", f[0], f[1], toFixed(f[0], 6))
}
}
}
func TestFuncLookupSplit(t *testing.T) {
tests := map[string][]string{
"": {},
"a": {"a"},
"a,b,c": {"a", "b", "c"},
"a, b, c": {"a", "b", "c"},
"[a,b,c]": {"[a,b,c]"},
"a,[1,2,3],b": {"a", "[1,2,3]", "b"},
"[1,2,3],a,[1,2,3]": {"[1,2,3]", "a", "[1,2,3]"},
}
for input, expected := range tests {
values := funcLookupSplit(input)
if len(values) != len(expected) {
t.Fatalf("%s was not %s", values, expected)
}
for i := 0; i < len(values); i++ {
if values[i] != expected[i] {
t.Fatalf("expected %s got %s", expected[i], values[i])
}
}
}
}