-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathutil_test.go
executable file
·76 lines (65 loc) · 2.41 KB
/
util_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
// Copyright 2015 Alex Browne. All rights reserved.
// Use of this source code is governed by the MIT
// license, which can be found in the LICENSE file.
// file util_test.go contains unit tests for the functions
// in util.go
package zoom
import (
"reflect"
"testing"
)
func TestIndexOfStringSlice(t *testing.T) {
strings := []string{"one", "two", "three"}
index := indexOfStringSlice(strings, "two")
if index != 1 {
t.Errorf("index was incorrect.\nExpected: %d\nGot: %d\n", 1, index)
}
index = indexOfStringSlice(strings, "four")
if index != -1 {
t.Errorf("index was incorrect.\nExpected: %d\nGot: %d\n", -1, index)
}
}
func TestStringSliceContains(t *testing.T) {
strings := []string{"one", "two", "three"}
contains := stringSliceContains(strings, "two")
if contains != true {
t.Errorf("contains was incorrect.\nExpected: %t\nGot: %t\n", true, contains)
}
contains = stringSliceContains(strings, "four")
if contains != false {
t.Errorf("contains was incorrect.\nExpected: %t\nGot: %t\n", false, contains)
}
}
func TestRemoveElementFromStringSlice(t *testing.T) {
start := []string{"one", "two", "three", "four"}
got := removeElementFromStringSlice(start, "three")
expected := []string{"one", "two", "four"}
if !reflect.DeepEqual(expected, got) {
t.Errorf("result was incorrect.\nExpected: %v\nGot: %v\n", expected, got)
}
}
func TestCompareAsStringSet(t *testing.T) {
a := []string{"one", "two", "three"}
b := []string{"two", "three", "one"}
c := []string{"three", "one"}
d := []string{"four", "one", "three", "two"}
if equal, _ := compareAsStringSet(a, b); !equal {
t.Errorf("equal was incorrect.\nExpected: %t\nGot: %t\n", true, equal)
}
if !reflect.DeepEqual(a, []string{"one", "two", "three"}) {
t.Error("a was modified after the compareAsStringSet operation!\ncurrent value: ", a)
}
if equal, _ := compareAsStringSet(a, c); equal {
t.Errorf("equal was incorrect.\nExpected: %t\nGot: %t\n", false, equal)
}
if !reflect.DeepEqual(a, []string{"one", "two", "three"}) {
t.Error("a was modified after the compareAsStringSet operation!\ncurrent value: ", a)
}
if equal, _ := compareAsStringSet(a, d); equal {
t.Errorf("equal was incorrect.\nExpected: %t\nGot: %t\n", false, equal)
}
if !reflect.DeepEqual(a, []string{"one", "two", "three"}) {
t.Error("a was modified after the compareAsStringSet operation!\ncurrent value: ", a)
}
}
// TODO: test other functions which may be mising from here!