forked from niven/simhashing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil_test.go
70 lines (51 loc) · 1.32 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
package simhashing
import "testing"
func TestBitsSet(t *testing.T) {
if BitsSet(0x1) != 1 {
t.Errorf("Incorrect count")
}
if BitsSet(0x1<<32) != 1 {
t.Errorf("Incorrect count")
}
if BitsSet(0xff) != 8 {
t.Errorf("Incorrect count")
}
if BitsSet(0xf0) != 4 {
t.Errorf("Incorrect count")
}
}
func TestTokenize(t *testing.T) {
if !stringarray_equal(Tokenize("abcdef", 3), []string{"abc", "def"}) {
t.Errorf("Tokening fail")
}
if !stringarray_equal(Tokenize("abcdef", 4), []string{"abcd", "ef"}) {
t.Errorf("Tokening fail")
}
if !stringarray_equal(Tokenize("abcdef", 10), []string{"abcdef"}) {
t.Errorf("Tokening fail")
}
}
func TestTokenize_stride(t *testing.T) {
if !stringarray_equal(Tokenize_stride("abcdef", 3), []string{"abc", "bcd", "cde", "def"}) {
t.Errorf("Tokening/stride fail")
}
if !stringarray_equal(Tokenize_stride("abcdef", 4), []string{"abcd", "bcde", "cdef"}) {
t.Errorf("Tokening/stride fail")
}
if !stringarray_equal(Tokenize_stride("abcdef", 10), []string{"abcdef"}) {
t.Errorf("Tokening/stride fail")
}
}
// check that 2 arrays of strings are equal (in contents and order)
func stringarray_equal(a []string, b []string) (equal bool) {
equal = true
if len(a) != len(b) {
return false
}
for i := 0; i < len(a); i++ {
if a[i] != b[i] {
return false
}
}
return
}