forked from tinode/chat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils_test.go
60 lines (54 loc) · 1.21 KB
/
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
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"testing"
)
func slicesEqual(expected, gotten []string) bool {
if len(expected) != len(gotten) {
return false
}
for i, v := range expected {
if v != gotten[i] {
return false
}
}
return true
}
func expectSlicesEqual(t *testing.T, name string, expected, gotten []string) {
if !slicesEqual(expected, gotten) {
t.Errorf("%s: expected %+v, got %+v", name, expected, gotten)
}
}
func TestStringSliceDelta(t *testing.T) {
// Case format:
// - inputs: old, new
// - expected outputs: added, removed, intersection
cases := [][5][]string{
{
{"abc", "def", "fff"}, {},
{}, {"abc", "def", "fff"}, {},
},
{
{}, {}, {}, {}, {},
},
{
{"aa", "xx", "bb", "aa", "bb"}, {"yy", "aa"},
{"yy"}, {"aa", "bb", "bb", "xx"}, {"aa"},
},
{
{"bb", "aa", "bb"}, {"yy", "aa", "bb", "zzz", "zzz", "cc"},
{"cc", "yy", "zzz", "zzz"}, {"bb"}, {"aa", "bb"},
},
{
{"aa", "aa", "aa"}, {"aa", "aa", "aa"},
{}, {}, {"aa", "aa", "aa"},
},
}
for _, tc := range cases {
added, removed, both := stringSliceDelta(
tc[0], tc[1],
)
expectSlicesEqual(t, "added", tc[2], added)
expectSlicesEqual(t, "removed", tc[3], removed)
expectSlicesEqual(t, "both", tc[4], both)
}
}