-
Notifications
You must be signed in to change notification settings - Fork 2
/
match_test.go
53 lines (41 loc) · 1.31 KB
/
match_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
// Copyright 2016 David Lavieri. All rights reserved.
// Use of this source code is governed by a MIT License
// License that can be found in the LICENSE file.
package goradix
import "testing"
func TestSourceMatch(t *testing.T) {
match := func(t *testing.T, insert []string, matchString, lbsMatch, plbsMatch []byte, matchesInt int) {
//Complex N. 1
radix := New(false)
for _, v := range insert {
radix.Insert(v)
}
lbs, matches, plbs := radix.match([]byte(matchString))
if matches != matchesInt {
t.Fail()
t.Logf("matches fail. Expected %d; Got: %d", matchesInt, matches)
}
if len(lbs) != len(lbsMatch) {
t.Fail()
t.Logf("left string length fail. Expected %d; Got: %d", len(lbsMatch), len(lbs))
}
for i, v := range lbs {
if v != lbsMatch[i] {
t.Fail()
t.Logf("left byte string fail. Expected: %d; Got: %d", lbsMatch[i], v)
}
}
if len(plbs) != len(plbsMatch) {
t.Fail()
t.Logf("left string length fail. Expected %d; Got: %d", len(plbsMatch), len(lbs))
}
for i, v := range plbs {
if v != plbsMatch[i] {
t.Fail()
t.Logf("left byte string fail. Expected: %d; Got: %d", plbsMatch[i], v)
}
}
}
match(t, []string{"test"}, []byte("tea"), []byte("a"), []byte("st"), 2)
match(t, []string{"yubel", "yuber", "yubo"}, []byte("y"), []byte{}, []byte("ub"), 1)
}