-
Notifications
You must be signed in to change notification settings - Fork 7
/
simple-test.js
61 lines (52 loc) · 1.78 KB
/
simple-test.js
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
var BurstTrie = require("../index.js");
var BurstTrieWriter = require("../writer/BurstTrieWriter.js");
var assert = require("chai").assert;
describe("burst-trie", function()
{
var myTrie;
before(function()
{
myTrie = BurstTrie.createTrie();
myTrie.add('CAR');
myTrie.add('CART');
myTrie.add('CARE');
myTrie.add('CARTS');
myTrie.add('CARS');
myTrie.add('CARED');
myTrie.add('CAB');
})
it("added keys are contained", function()
{
assert.equal(myTrie.contains('C'), false, "C should not exist");
assert.equal(myTrie.contains('CAR'), true, "CAR should exist");
assert.equal(myTrie.contains('CARE'), true, "CARE should exist");
assert.equal(myTrie.contains('CART'), true, "CART should exist");
assert.equal(myTrie.contains('CARTS'), true, "CARTS should exist");
assert.equal(myTrie.contains('CARTIS'), false, "CARTIS should not exist");
})
it("prints correctly", function()
{
var output = BurstTrieWriter.write(myTrie);
var lines = output.split("\n");
var CLines = [];
assert(lines[0].indexOf("BurstTrie") >= 0);
assert(lines[1].indexOf("AccessTrieNode") >= 0);
for (var i = 2; i < lines.length; i++)
{
var line = lines[i].trim();
var parts = line.split(":");
var char = parts[0].trim();
if (char == "C")
{
CLines.push(line);
}
else if (char.length == 1)
{
assert(parts[1].length == 0, char + " line should be empty");
}
}
assert(CLines[0].indexOf("ContainerNode") >= 0);
assert(CLines[1].indexOf("BST") >= 0);
console.log(output);
})
})