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 c60b5ef

Browse files
Add unit tests for Trie/unique-word-count
1 parent 85a1890 commit c60b5ef

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
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)

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