-
Notifications
You must be signed in to change notification settings - Fork 0
/
smac_test_common_test.go
128 lines (109 loc) · 3.53 KB
/
smac_test_common_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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Copyright Piero de Salvia.
// All Rights Reserved
package smac
import (
"bufio"
"os"
"reflect"
"testing"
)
const checkMark = "\u2713"
const ballotX = "\u2717"
func initBenchmark() {
goPath := os.Getenv("GOPATH")
wordFile := goPath + "/src/github.com/pierods/smac/demo/allwords.txt"
f, err := os.Open(wordFile)
defer f.Close()
if err != nil {
os.Exit(-1)
}
lineScanner := bufio.NewScanner(f)
for lineScanner.Scan() {
line := lineScanner.Text()
testWords = append(testWords, line)
}
wordsInTestData = len(testWords)
prefixes := make(map[string]bool)
for _, word := range testWords {
for i := 1; i < len(word); i++ {
acc := word[:i]
prefixes[acc] = true
}
}
for k := range prefixes {
testPrefixes = append(testPrefixes, k)
}
prefixesInTestData = len(testPrefixes)
}
var testWords []string
var testPrefixes []string
var wordsInTestData, prefixesInTestData int
func TestTrieSOLILI(t *testing.T) {
t.Log("Given the need to test a sorted linked list")
{
t.Log("When initializing a solili")
{
list := sOLILI{}
slice := list.flush()
if !reflect.DeepEqual(slice, []string{}) {
t.Fatal("Should be able to correctly initialize an empty solili", ballotX)
}
t.Log("Should be able to correctly initialize an empty solili", checkMark)
}
t.Log("When operating on a solili")
{
list := sOLILI{}
list.insert("aaa", 0)
slice := list.flush()
if !reflect.DeepEqual(slice, []string{"aaa"}) {
t.Fatal("Should be able to correctly add an element to a solili", ballotX)
}
t.Log("Should be able to correctly add an element to a solili", checkMark)
list.insert("bbb", 0)
slice = list.flush()
if !reflect.DeepEqual(slice, []string{"aaa", "bbb"}) {
t.Fatal("Should be able to correctly add an element to the back of a solili", ballotX)
}
t.Log("Should be able to correctly add an element to the back of a solili", checkMark)
list.insert("jjj", 100)
slice = list.flush()
if !reflect.DeepEqual(slice, []string{"jjj", "aaa", "bbb"}) {
t.Fatal("Should be able to correctly add an element to the front of a solili", ballotX)
}
t.Log("Should be able to correctly add an element to the front of a solili", checkMark)
list.insert("kkk", 90)
slice = list.flush()
if !reflect.DeepEqual(slice, []string{"jjj", "kkk", "aaa", "bbb"}) {
t.Fatal("Should be able to correctly add an element in the middle of a solili", ballotX)
}
t.Log("Should be able to correctly add an element in the middle of a solili", checkMark)
list.insert("lll", 100)
slice = list.flush()
if !reflect.DeepEqual(slice, []string{"jjj", "lll", "kkk", "aaa", "bbb"}) {
t.Fatal("Should be able to maintain arrival order for same-weight elements (at head)", ballotX)
}
t.Log("Should be able to maintain arrival order for same-weight elements (at head)", checkMark)
list.insert("mmm", 90)
slice = list.flush()
if !reflect.DeepEqual(slice, []string{"jjj", "lll", "kkk", "mmm", "aaa", "bbb"}) {
t.Fatal("Should be able to maintain arrival order for same-weight elements", ballotX)
}
t.Log("Should be able to maintain arrival order for same-weight elements", checkMark)
list = sOLILI{}
list.insert("1", 0)
list.insert("2", 0)
list.insert("3", 0)
list.insert("4", 0)
list.insert("5", 0)
list.insert("6", 0)
list.insert("7", 0)
list.insert("8", 0)
list.insert("8", 0)
slice = list.flushL(5)
if len(slice) != 5 {
t.Fatal("Should be able to limit flushing on a lili", ballotX)
}
t.Log("Should be able to limit flushing on a lili", checkMark)
}
}
}