-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcluster_test.go
More file actions
52 lines (42 loc) · 1.25 KB
/
cluster_test.go
File metadata and controls
52 lines (42 loc) · 1.25 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
package Milena
import (
"github.com/JodeZer/Milena/util/testUtil"
"sort"
"testing"
)
type sortStringSlice []string
func (s sortStringSlice) Less(i, j int) bool {
return s[i] < s[j]
}
func (s sortStringSlice) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}
func (s sortStringSlice) Len() int {
return len(s)
}
func TestRemoveCommonTopics(t *testing.T) {
f := func(a interface{}, b interface{}) bool {
as := a.(sortStringSlice)
bs := b.(sortStringSlice)
if len(as) != len(bs) {
return false
}
sort.Sort(as)
sort.Sort(bs)
for i, v := range as {
if v != bs[i] {
return false
}
}
return true
}
ls := sortStringSlice([]string{"a", "a", "b", "b", "c"})
rs := sortStringSlice([]string{"a"})
testUtil.Test(t, "TestRemoveCommonTopics1", sortStringSlice(removeCommonTopics(ls, rs)), sortStringSlice([]string{"b", "c"}), f)
ls = sortStringSlice([]string{"a", "a", "b", "b", "c"})
rs = sortStringSlice([]string{"d"})
testUtil.Test(t, "TestRemoveCommonTopics2", sortStringSlice(removeCommonTopics(ls, rs)), sortStringSlice([]string{"b", "c", "a"}), f)
ls = sortStringSlice([]string{})
rs = sortStringSlice([]string{"d"})
testUtil.Test(t, "TestRemoveCommonTopics3", sortStringSlice(removeCommonTopics(ls, rs)), sortStringSlice([]string{}), f)
}