-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfss_test.go
102 lines (87 loc) · 2.02 KB
/
fss_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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package fss
import (
"bufio"
"os"
"testing"
)
var fss *Fss
func TestBuildFSS(t *testing.T) {
fss = NewFss(2)
filename := "/usr/share/dict/words"
f, err := os.Open(filename)
if err != nil {
t.Error("Unable to open file %s", filename)
}
scanner := bufio.NewScanner(f)
count := 0
for scanner.Scan() {
count++
if count == 2000 {
break
}
fss.Insert(scanner.Text())
}
if scanner.Err() != nil {
t.Errorf("Could not read lines from file `%s`", filename)
}
}
//I'm not sure if this is needed as I am using a third party library that is supposed to be tested by industry standards
func TestHashWord(t *testing.T) {
}
func TestSplitWord(t *testing.T) {
//TODO: Add more words with different distances.
table := []struct {
word string
distance int
expected []string
}{
{word: "table", distance: 1, expected: []string{"tabl", "tabe", "tale", "tble", "able"}},
}
for _, tab := range table {
perm := getpermutations(tab.word, tab.distance+1)
for _, str := range tab.expected {
if !contains(perm, str) {
t.Errorf("Expected string %s.", str)
}
}
}
}
func qcontains(strs []QueryResult, s string) bool {
for _, str := range strs {
if str.S == s {
return true
}
}
return false
}
func contains(strs []string, s string) bool {
for _, str := range strs {
if str == s {
return true
}
}
return false
}
func TestLookup(t *testing.T) {
//TODO: This should build an FSS for each query item. This would make sure I can search
//different sizes of deletion neighborhoods
table := []struct {
query string
matches []string
distance int
}{
{query: "abaft", matches: []string{"abaft"}, distance: 0},
{query: "abaft", matches: []string{"abaft", "abaff"}, distance: 1},
}
for _, tabl := range table {
results := fss.Search(tabl.query)
for _, w := range tabl.matches {
if !qcontains(results, w) {
t.Errorf("Expected %s", w)
}
}
}
}
func TestSplitQuery(t *testing.T) {
//Because splitting a query is not the same as splitting a full word, the result is multiple splits
}