Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4c74d9d

Browse files
committed
Add unit tests for suffix tree
Fixes #87
1 parent 43ed1bc commit 4c74d9d

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const SuffixTree = require('.');
2+
3+
describe('Data Structure : Suffix Tree', () => {
4+
it('Should be class', () => {
5+
expect(typeof SuffixTree.prototype.constructor).toEqual('function');
6+
});
7+
8+
it('Should correctly construct Suffix Tree from string', () => {
9+
const banana = new SuffixTree('banana');
10+
banana.constructSuffixTree();
11+
12+
expect(banana.findSubstring('banana')).toBe(0);
13+
expect(banana.findSubstring('nana')).toBe(2);
14+
expect(banana.findSubstring('na')).toBe(4);
15+
expect(banana.findSubstring('an')).toBe(-1);
16+
17+
const suffix = new SuffixTree('suffix');
18+
suffix.constructSuffixTree();
19+
20+
expect(suffix.findSubstring('fix')).toBe(3);
21+
22+
const kebab = new SuffixTree('kebab');
23+
kebab.constructSuffixTree();
24+
25+
expect(kebab.findSubstring('horse')).toBe(-1);
26+
27+
const mississippi = new SuffixTree('mississippi');
28+
mississippi.constructSuffixTree();
29+
30+
expect(mississippi.findSubstring('ssippi')).toBe(5);
31+
expect(mississippi.findSubstring('ppi')).toBe(8);
32+
expect(mississippi.findSubstring('mis')).toBe(-1);
33+
expect(mississippi.findSubstring('pi')).toBe(9);
34+
35+
const linkedList = new SuffixTree('aaaaaaaaaaa');
36+
linkedList.constructSuffixTree();
37+
38+
expect(linkedList.findSubstring('a')).toBe(10);
39+
expect(linkedList.findSubstring('aaa')).toBe(8);
40+
expect(linkedList.findSubstring('b')).toBe(-1);
41+
expect(linkedList.findSubstring('')).toBe(-1);
42+
});
43+
});

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /