Skip to content

Commit 79e07ad

Browse files
authored
Merge pull request #138 from qualitymanifest/tests/trie-unique-word-count
Add unit tests for Trie/unique-word-count
2 parents 85a1890 + 5b7bdfd commit 79e07ad

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
/* eslint-disable no-unused-vars */
2-
const Trie = require('../index');
3-
41
function uniqueWordCount(root) {
52
let result = 0;
63
if (root.isEndOfWord) {
@@ -14,10 +11,4 @@ function uniqueWordCount(root) {
1411
return result;
1512
}
1613

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(uniqueWordCount(trie.root));
22-
2314
module.exports = uniqueWordCount;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const Trie = require('../index');
2+
const uniqueWordCount = require('.');
3+
4+
describe('Trie Unique Word Count', () => {
5+
it('counts an empty trie', () => {
6+
const trie = new Trie();
7+
const wordCount = uniqueWordCount(trie.root);
8+
expect(wordCount).toEqual(0);
9+
});
10+
11+
it('counts unique words', () => {
12+
const trie = new Trie();
13+
const words = ['one', 'two', 'three', 'four'];
14+
words.forEach(word => trie.insert(word));
15+
const wordCount = uniqueWordCount(trie.root);
16+
expect(wordCount).toEqual(4);
17+
});
18+
19+
it('does not count duplicate words', () => {
20+
const trie = new Trie();
21+
const words = ['one', 'one', 'two', 'three'];
22+
words.forEach(word => trie.insert(word));
23+
const wordCount = uniqueWordCount(trie.root);
24+
expect(wordCount).toEqual(3);
25+
});
26+
});

0 commit comments

Comments
 (0)