Skip to content

added unit test for Trie #140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
"eslint-plugin-import": "^2.14.0",
"jest": "^25.0.0"
}
}
}
4 changes: 1 addition & 3 deletions src/_DataStructures_/Trees/Trie/total-words-in-trie/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// eslint-disable-next-line no-unused-vars
const Trie = require('../index');

function totalWords(root) {
let result = 0;
if (root.isEndOfWord) {
Expand All @@ -20,4 +18,4 @@ function totalWords(root) {
// words.forEach(word => trie.insert(word));
// console.log(totalWords(trie.root));

module.exports = totalWords;
module.exports = { totalWords };
25 changes: 25 additions & 0 deletions src/_DataStructures_/Trees/Trie/total-words-in-trie/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const trie = require('../index');
const wordcounts = require('./index');

describe('Trees Total words in trie', () => {
//case with non-empty array
it("Solution for this testarray is 5", () => {
const testarray = ["one", "two", "three", "four", "five"];
const t = new trie();

for (let i of testarray) {
t.insert(i);
}
expect(wordcounts.totalWords(t.root)).toEqual(testarray.length);
})

//case with empty array
it("Solution for this empty_array is empty", () => {
const empty_array = [];
const t = new trie();
for (let j of empty_array) {
t.insert(j);
}
expect(wordcounts.totalWords(t.root)).toEqual(0);
})
})