Skip to content

Commit 0c97c61

Browse files
committed
Add unit test for all-words-in-trie
1 parent 29b1650 commit 0c97c61

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const Trie = require("../index");
2+
const allWordsFromTrie = require(".");
3+
4+
describe("Find all words in Trie", () => {
5+
let trie = new Trie();
6+
const words = ["bed", "ball", "apple", "java", "javascript", "bed"];
7+
8+
it("Should return an empty array when null is passed in", () => {
9+
expect(allWordsFromTrie(null)).toEqual([]);
10+
});
11+
12+
it("Should return an empty array when trie is empty", () => {
13+
expect(allWordsFromTrie(trie.root)).toEqual([]);
14+
});
15+
16+
it("Should return all words in the trie", () => {
17+
words.forEach(word => trie.insert(word));
18+
expect(allWordsFromTrie(trie.root).sort()).toEqual(words.sort());
19+
});
20+
});

0 commit comments

Comments
 (0)