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 93cc506

Browse files
committed
Added Unit Test
1 parent 85a1890 commit 93cc506

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

‎src/_DataStructures_/Trees/Trie/total-words-in-trie/index.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ function totalWords(root) {
1414
return result;
1515
}
1616

17-
// const words = ['bed', 'ball', 'apple', 'java', 'javascript', 'bed'];
18-
// const trie = new Trie();
17+
const words = ['bed', 'ball', 'apple', 'java', 'javascript', 'bed'];
18+
const trie = new Trie();
1919

20-
// words.forEach(word => trie.insert(word));
21-
// console.log(totalWords(trie.root));
20+
words.forEach(word => trie.insert(word));
21+
console.log(totalWords(trie.root));
2222

2323
module.exports = totalWords;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const totalWordsInTrie = require('./index')
2+
const Trie = require('../index');
3+
var assert = require('assert');
4+
5+
describe('Data Structure : Trie', () => {
6+
it('Should be class of type Trie', () => {
7+
assert.equal(typeof Trie.prototype.constructor, 'function');
8+
// expect(typeof Trie.prototype.constructor).toEqual('function');
9+
});
10+
11+
describe('Trie', () => {
12+
13+
it('Should return 6.', () => {
14+
let newTrie = new Trie();
15+
const words = ['bed', 'ball', 'apple', 'java', 'javascript', 'bed'];
16+
words.forEach(word => newTrie.insert(word));
17+
result = totalWordsInTrie.totalWords(newTrie.root);
18+
assert.equal(result, 6);
19+
});
20+
21+
it('Should return 0.', () => {
22+
let newTrie = new Trie();
23+
result = totalWordsInTrie.totalWords(newTrie.root);
24+
assert.equal(result, 0);
25+
});
26+
27+
it('Should return 6.', () => {
28+
let newTrie = new Trie();
29+
const words = ['bed', 'ball','', 'apple', 'java', 'javascript', 'bed'];
30+
words.forEach(word => newTrie.insert(word));
31+
result = totalWordsInTrie.totalWords(newTrie.root);
32+
assert.equal(result, 6);
33+
});
34+
});
35+
});

0 commit comments

Comments
(0)

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