-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest.html
More file actions
236 lines (184 loc) · 6.81 KB
/
test.html
File metadata and controls
236 lines (184 loc) · 6.81 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<!DOCTYPE html>
<html>
<head>
<title>Trie Tests</title>
<script src="http://yui.yahooapis.com/3.2.0/build/yui/yui-min.js"></script>
<script src="trie.js"></script>
</head>
<body class="yui3-skin-sam yui-skin-sam">
<h1>Trie Tests</h1>
<div id="testLogger"></div>
<script>
YUI().use("node", "console", "test",function (Y) {
Y.namespace("test");
Y.test.TestInsert = new Y.Test.Case({
name: "Insert Tests",
setUp: function() {
this.T = new Trie();
},
tearDown: function() {
delete this.T;
},
testInsertSingle: function() {
this.T.insert("hello");
var Assert = Y.Assert,
ret = this.T.getAllWords(); //get all words
Assert.areEqual(1, ret.length, "Trie should have one item");
Assert.areEqual("hello", ret[0], "First item should be 'hello'");
},
testInsertMultiple: function() {
this.T.insert("hello");
this.T.insert("world");
var Assert = Y.Assert,
ret = this.T.getAllWords(); //get all words
Assert.areEqual(2, ret.length, "Trie should have two items");
Assert.areEqual("hello", ret[0], "First item should be 'hello'");
Assert.areEqual("world", ret[1], "Second item should be 'world'");
}
});
Y.test.TestRemove = new Y.Test.Case({
name: "Remove Tests",
setUp: function() {
this.T = new Trie();
this.T.insert("hello");
this.T.insert("world");
},
tearDown: function() {
delete this.T;
},
testRemoveSingle: function() {
this.T.remove("hello");
var Assert = Y.Assert,
ret = this.T.getAllWords(); //get all words
Assert.areEqual(1, ret.length, "Trie should have one item left");
Assert.areEqual("world", ret[0], "First item should be 'world' now");
},
testRemoveMultiple: function() {
this.T.remove("hello");
this.T.remove("world");
var Assert = Y.Assert,
ret = this.T.getAllWords(); //get all words
Assert.areEqual(0, ret.length, "Trie should be empty");
}
});
Y.test.TestUpdate = new Y.Test.Case({
name: "Update Tests",
setUp: function() {
this.T = new Trie();
this.T.insert("hello");
},
tearDown: function() {
delete this.T;
},
testUpdate: function() {
this.T.update("hello", "world");
var Assert = Y.Assert,
ret = this.T.getAllWords(); //get all words
Assert.areEqual(1, ret.length, "Trie should have one item");
Assert.areEqual("world", ret[0], "Item should be 'world'");
}
});
Y.test.TestCountWord = new Y.Test.Case({
name: "CountWord Tests",
setUp: function() {
this.T = new Trie();
this.T.insert("hello");
this.T.insert("hello");
},
tearDown: function() {
delete this.T;
},
testCountWord: function() {
var Assert = Y.Assert;
Assert.areEqual(2, this.T.countWord("hello"), "'hello' was inserted twice");
}
});
Y.test.TestCountPrefix = new Y.Test.Case({
name: "CountPrefix Tests",
setUp: function() {
this.T = new Trie();
this.T.insert("hello");
this.T.insert("helloWorld");
this.T.insert("world");
},
tearDown: function() {
delete this.T;
},
testCountPrefix: function() {
var Assert = Y.Assert;
Assert.areEqual(2, this.T.countPrefix("hell"), "2 words have 'hell' as prefix");
}
});
Y.test.TestFind = new Y.Test.Case({
name: "Find Tests",
setUp: function() {
this.T = new Trie();
this.T.insert("hello");
this.T.insert("world");
},
tearDown: function() {
delete this.T;
},
testFind: function() {
var Assert = Y.Assert;
Assert.areEqual(true, this.T.find("hello"), "'helloWorld' exists in trie");
Assert.areEqual(false, this.T.find("xylo"), "'xylo' does not exist in trie");
}
});
Y.test.TestGetWords = new Y.Test.Case({
name: "GetWords Tests",
setUp: function() {
this.T = new Trie();
this.T.insert("hello");
this.T.insert("world");
},
tearDown: function() {
delete this.T;
},
testGetWords: function() {
var Assert = Y.Assert,
ret = this.T.getAllWords(); //get all words
Assert.areEqual(2, ret.length, "trie has 2 words");
Assert.areEqual("hello", ret[0], "First word is 'hello'");
Assert.areEqual("world", ret[1], "Second word is 'world'");
}
});
Y.test.TestAutoComplete = new Y.Test.Case({
name: "AutoComplete Tests",
setUp: function() {
this.T = new Trie();
this.T.insert("hello");
this.T.insert("world");
this.T.insert("helloWorld");
},
tearDown: function() {
delete this.T;
},
testAutoComplete: function() {
var Assert = Y.Assert,
ret = this.T.autoComplete("hell"); //get all words starting with "hell"
Assert.areEqual(2, ret.length, "trie has 2 words starting with 'hell'");
Assert.areEqual("hello", ret[0], "First word is 'hello'");
Assert.areEqual("helloWorld", ret[1], "Second word is 'helloWorld'");
}
});
Y.test.ExampleSuite = new Y.Test.Suite("Trie Tests Suite");
Y.test.ExampleSuite.add(Y.test.TestInsert);
Y.test.ExampleSuite.add(Y.test.TestRemove);
Y.test.ExampleSuite.add(Y.test.TestUpdate);
Y.test.ExampleSuite.add(Y.test.TestCountWord);
Y.test.ExampleSuite.add(Y.test.TestCountPrefix);
Y.test.ExampleSuite.add(Y.test.TestFind);
Y.test.ExampleSuite.add(Y.test.TestGetWords);
Y.test.ExampleSuite.add(Y.test.TestAutoComplete);
var r = new Y.Console({
newestOnTop : false,
style: 'block'
});
r.render('#testLogger');
Y.Test.Runner.add(Y.test.ExampleSuite);
Y.Test.Runner.run(); //run the tests
});
</script>
</body>
</html>