forked from takuyaa/doublearray
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoublearray.js
More file actions
72 lines (69 loc) · 2.45 KB
/
doublearray.js
File metadata and controls
72 lines (69 loc) · 2.45 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
// Copyright (c) 2014 Takuya Asano All Rights Reserved.
describe("doublearray", function () {
before(function(done) {
done();
});
describe("contain", function () {
var trie; // target
var dict = {
"apple": 1,
"ball": 2,
"bear": 3,
"bird": 4,
"bison": 5,
"black": 6,
"blue": 7,
"blur": 8,
"cold": 10,
"column": 11,
"cow": 12
}
var words = []
for (var key in dict) {
words.push({ k: key, v: dict[key]})
}
it("Contain bird", function () {
trie = doublearray.builder().build(words);
expect(trie.contain("bird")).to.be.true;
});
it("Contain bison", function () {
trie = doublearray.builder().build(words);
expect(trie.contain("bison")).to.be.true;
});
it("Lookup bird", function () {
trie = doublearray.builder().build(words);
expect(trie.lookup("bird")).to.be.eql(dict["bird"]);
});
it("Lookup bison", function () {
trie = doublearray.builder().build(words);
expect(trie.lookup("bison")).to.be.eql(dict["bison"]);
});
it("Build", function () {
trie = doublearray.builder(4).build(words);
// trie.bc.
expect(trie.lookup("bison")).to.be.eql(dict["bison"]);
});
});
describe("load", function () {
var trie; // target
var load_trie; // target
var words = [ { k: "apple", v: 1 } ]; // test data
beforeEach(function (done) {
// Build original
trie = doublearray.builder().build(words);
// Load from original typed array
var base_buffer = trie.bc.getBaseBuffer();
var check_buffer = trie.bc.getCheckBuffer();
load_trie = doublearray.load(base_buffer, check_buffer);
done();
});
it("Original and loaded tries lookup successfully", function () {
expect(trie.lookup("apple")).to.be.eql(words[0].v);
expect(load_trie.lookup("apple")).to.be.eql(words[0].v);
});
it("Original and loaded typed arrays are same", function () {
expect(trie.bc.getBaseBuffer()).to.deep.eql(load_trie.bc.getBaseBuffer());
expect(trie.bc.getCheckBuffer()).to.deep.eql(load_trie.bc.getCheckBuffer());
});
});
});