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 ad92a28

Browse files
fixup! test: add test for all-words-in-tree
1 parent ecb0a0f commit ad92a28

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

‎src/_DataStructures_/Trees/Trie/all-words-in-trie/all-words-in-trie.test.js‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,49 @@ describe('Data Structure : Trie : All Words In Tree', () => {
1313
const expected = ['apple', 'ball', 'bed', 'bed', 'java', 'javascript'];
1414
expect(expected).toEqual(result);
1515
});
16+
17+
it('Should retain duplicates', () => {
18+
const words = ['bed', 'bed', 'bed'];
19+
const trie = new Trie();
20+
21+
words.forEach(word => trie.insert(word));
22+
23+
const result = allWordsInTrie(trie.root);
24+
expect(result.length).toBe(3);
25+
});
26+
27+
it('passing an empty array of words returns an empty array', () => {
28+
const words = [];
29+
const trie = new Trie();
30+
31+
words.forEach(word => trie.insert(word));
32+
33+
const result = allWordsInTrie(trie.root);
34+
expect(result).toEqual([]);
35+
});
36+
37+
it('passing an empty Trie will throw an error ', () => {
38+
const trie = new Trie();
39+
expect(() => {
40+
allWordsInTrie(trie);
41+
}).toThrow('Cannot read property \'0\' of undefined');
42+
});
43+
44+
it('passing an empty array will throw an error ', () => {
45+
expect(() => {
46+
allWordsInTrie([]);
47+
}).toThrow('Cannot read property \'0\' of undefined');
48+
});
49+
50+
it('passing null will throw an error ', () => {
51+
expect(() => {
52+
allWordsInTrie([]);
53+
}).toThrow('Cannot read property \'0\' of undefined');
54+
});
55+
56+
it('passing an array not in a Trie will throw an error ', () => {
57+
expect(() => {
58+
allWordsInTrie(['bed', 'ball', 'apple']);
59+
}).toThrow('Cannot read property \'0\' of undefined');
60+
});
1661
});

0 commit comments

Comments
(0)

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