-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhashTables_test.go
59 lines (50 loc) · 1.71 KB
/
hashTables_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
package algo
import "testing"
func TestIsSubsetInefficient(t *testing.T) {
testCases := map[string]struct {
input []string
input2 []string
exp bool
}{
"isSubset": {[]string{"a", "b", "c", "d", "e", "f"}, []string{"b", "d", "f"}, true},
"isNotSubset": {[]string{"a", "b", "c", "d", "e", "f"}, []string{"b", "d", "f", "h"}, false},
}
for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
if got := isSubsetInefficient(tc.input, tc.input2); got != tc.exp {
t.Errorf("Exp %t, got %t", tc.exp, got)
}
})
}
}
func TestIsSubset(t *testing.T) {
testCases := map[string]struct {
input []string
input2 []string
exp bool
}{
"isSubset": {[]string{"a", "b", "c", "d", "e", "f"}, []string{"b", "d", "f"}, true},
"isNotSubset": {[]string{"a", "b", "c", "d", "e", "f"}, []string{"b", "d", "f", "h"}, false},
}
for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
if got := isSubset(tc.input, tc.input2); got != tc.exp {
t.Errorf("Exp %t, got %t", tc.exp, got)
}
})
}
}
func BenchmarkIsSubsetInefficient(b *testing.B) {
arr1 := []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}
arr2 := []string{"l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}
for i := 0; i < b.N; i++ {
isSubsetInefficient(arr1, arr2)
}
}
func BenchmarkIsSubset(b *testing.B) {
arr1 := []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}
arr2 := []string{"l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}
for i := 0; i < b.N; i++ {
isSubset(arr1, arr2)
}
}