/
filters_test.go
49 lines (44 loc) · 1.48 KB
/
filters_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
package filterutils_test
import "github.com/hahnicity/filterutils"
import "reflect"
import "sort"
import "testing"
var testStringInSortedSlice = []struct {
name string
a []string
x string
expected bool
} {
{"Has element", []string{"foo", "bar", "baz", "blah", "belp"}, "blah", true},
{"Does not have element", []string{"tar", "var", "car", "a", "b", "d"}, "me", false},
}
func TestStringInSortedSlice(t *testing.T) {
for _, test := range testStringInSortedSlice {
sort.Strings(test.a)
i := filterutils.StringInSortedSlice(test.a, test.x)
if i != test.expected {
// XXX Need to figure out the actual types for % to pass in for string formatting
t.Errorf("Test '%s' has failed. Expected: %s, Actual %s", test.name, test.expected, i)
}
}
}
func TestFilter(t *testing.T) {
a := []string{"foo", "foo", "bar"}
ex := []string{"foo", "foo"}
i := filterutils.Filter(a, func(i int) bool { return a[i] == "foo"})
if !reflect.DeepEqual(i, ex) {
// XXX Arg... string formatting
t.Errorf("Filter test has failed. Expected %s, Actual %s", ex, i)
}
}
func TestHasSuffix(t *testing.T) {
var (
a = []string{"baz", "bar", "chaz", "champ"}
suf string = "az"
exp = []string{"baz", "chaz"}
)
ret := filterutils.HasSuffix(a, suf)
if !reflect.DeepEqual(ret, exp) {
t.Errorf("Filter test has failed. Expected %s, Actual %s")
}
}