-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdeduplicate_test.go
173 lines (134 loc) · 3.58 KB
/
deduplicate_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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package slicer
import (
"encoding/json"
"strings"
"testing"
)
func TestStringDeduplicate(t *testing.T) {
s := String()
s.Add("one", "four", "two", "three", "two", "one")
s.Deduplicate()
expected := "one four two three"
actual := strings.Join(s.AsSlice(), " ")
if expected != actual {
t.Errorf("Expected '%s', but got '%s'", expected, actual)
}
}
func TestInt64Deduplicate(t *testing.T) {
s := Int64()
s.Add(1, 2, 3, 2, 3, 4, 3, 4, 5)
s.Deduplicate()
expected := "[1,2,3,4,5]"
actual, _ := json.Marshal(s.AsSlice())
if expected != string(actual) {
t.Errorf("Expected '%s', but got '%s'", expected, actual)
}
}
func TestInt32Deduplicate(t *testing.T) {
s := Int32()
s.Add(1, 2, 3, 2, 3, 4, 3, 4, 5)
s.Deduplicate()
expected := "[1,2,3,4,5]"
actual, _ := json.Marshal(s.AsSlice())
if expected != string(actual) {
t.Errorf("Expected '%s', but got '%s'", expected, actual)
}
}
func TestInt16Deduplicate(t *testing.T) {
s := Int16()
s.Add(1, 2, 3, 2, 3, 4, 3, 4, 5)
s.Deduplicate()
expected := "[1,2,3,4,5]"
actual, _ := json.Marshal(s.AsSlice())
if expected != string(actual) {
t.Errorf("Expected '%s', but got '%s'", expected, actual)
}
}
func TestInt8Deduplicate(t *testing.T) {
s := Int8()
s.Add(1, 2, 3, 2, 3, 4, 3, 4, 5)
s.Deduplicate()
expected := "[1,2,3,4,5]"
actual, _ := json.Marshal(s.AsSlice())
if expected != string(actual) {
t.Errorf("Expected '%s', but got '%s'", expected, actual)
}
}
func TestIntDeduplicate(t *testing.T) {
s := Int()
s.Add(1, 2, 3, 2, 3, 4, 3, 4, 5)
s.Deduplicate()
expected := "[1,2,3,4,5]"
actual, _ := json.Marshal(s.AsSlice())
if expected != string(actual) {
t.Errorf("Expected '%s', but got '%s'", expected, actual)
}
}
func TestInterfaceDeduplicate(t *testing.T) {
s := Interface()
var a interface{} = 1
var b interface{} = "hello"
s.Add(a, b, a, b)
s.Deduplicate()
expected := `[1,"hello"]`
actual, _ := json.Marshal(s.AsSlice())
if expected != string(actual) {
t.Errorf("Expected '%s', but got '%s'", expected, actual)
}
}
func TestFloat32Deduplicate(t *testing.T) {
s := Float32()
s.Add(1.5, 2.3, 3.9, 2.3, 3.9, 4.4, 3.9, 4.4, 5.2)
s.Deduplicate()
expected := "[1.5,2.3,3.9,4.4,5.2]"
actual, _ := json.Marshal(s.AsSlice())
if expected != string(actual) {
t.Errorf("Expected '%s', but got '%s'", expected, actual)
}
}
func TestFloat64Deduplicate(t *testing.T) {
s := Float64()
s.Add(1.5, 2.3, 3.9, 2.3, 3.9, 4.4, 3.9, 4.4, 5.2)
s.Deduplicate()
expected := "[1.5,2.3,3.9,4.4,5.2]"
actual, _ := json.Marshal(s.AsSlice())
if expected != string(actual) {
t.Errorf("Expected '%s', but got '%s'", expected, actual)
}
}
func TestBoolDeduplicate(t *testing.T) {
s := Bool()
s.Add(true, true, true, false, true, false, false, false)
s.Deduplicate()
expected := "[true,false]"
actual, _ := json.Marshal(s.AsSlice())
if expected != string(actual) {
t.Errorf("Expected '%s', but got '%s'", expected, actual)
}
}
// func TestStringAddSlice(t *testing.T) {
// s := String()
// s.Add("one")
// s.Add("two")
// extras := []string{"three", "four"}
// s.AddSlice(extras)
// expected := "one two three four"
// actual := strings.Join(s.AsSlice(), " ")
// if expected != actual {
// t.Errorf("Expected '%s', but got '%s'", expected, actual)
// }
// }
// func TestStringAddSlicer(t *testing.T) {
// s := String()
// s.Add("one")
// s.Add("two")
// p := String()
// p.Add("three")
// p.Add("four")
// s.AddSlicer(p)
// expected := "one two three four"
// actual := strings.Join(s.AsSlice(), " ")
// if expected != actual {
// t.Errorf("Expected '%s', but got '%s'", expected, actual)
// }
// }