Skip to content

Commit 891bf46

Browse files
Junior PereirapereiraJr
Junior Pereira
authored andcommitted
Adding Tests to totalWords in trie algorithm this closes knaxus#136
Author: Junior Pereira <pereirajr@lielsonjr@gmail.com> Date: Thu Oct 24 18:04:38 2019 -0300
1 parent 85a1890 commit 891bf46

File tree

3 files changed

+32
-39
lines changed

3 files changed

+32
-39
lines changed

package-lock.json

Lines changed: 11 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
// eslint-disable-next-line no-unused-vars
2-
const Trie = require('../index');
3-
42
function totalWords(root) {
53
let result = 0;
64
if (root.isEndOfWord) {
@@ -14,10 +12,4 @@ function totalWords(root) {
1412
return result;
1513
}
1614

17-
// const words = ['bed', 'ball', 'apple', 'java', 'javascript', 'bed'];
18-
// const trie = new Trie();
19-
20-
// words.forEach(word => trie.insert(word));
21-
// console.log(totalWords(trie.root));
22-
23-
module.exports = totalWords;
15+
module.exports.totalWords = totalWords;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const totalWordsInTrie = require('./index')
2+
const Trie = require('../index');
3+
4+
describe('Trees Total words in trie', () => {
5+
6+
it('should return 6 when counting from trie object', () => {
7+
const words = ['bed', 'ball', 'apple', 'java', 'javascript', 'bed'];
8+
const trie = new Trie();
9+
10+
words.forEach(word => trie.insert(word));
11+
12+
expect(totalWordsInTrie.totalWords(trie.root)).toEqual(words.length)
13+
})
14+
15+
it('should return 0 when a empty Trie with no words inserted is created', () => {
16+
const trie = new Trie();
17+
18+
expect(totalWordsInTrie.totalWords(trie.root)).toEqual(0)
19+
})
20+
})

0 commit comments

Comments
 (0)