From 93cc506807b7a745ef35bb460b7535351162d44f Mon Sep 17 00:00:00 2001 From: Nigel Yong Date: Thu, 24 Oct 2019 21:59:00 -0400 Subject: [PATCH 1/3] Added Unit Test --- .../Trees/Trie/total-words-in-trie/index.js | 8 ++--- .../total-words-in-trie.test.js | 35 +++++++++++++++++++ 2 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 src/_DataStructures_/Trees/Trie/total-words-in-trie/total-words-in-trie.test.js diff --git a/src/_DataStructures_/Trees/Trie/total-words-in-trie/index.js b/src/_DataStructures_/Trees/Trie/total-words-in-trie/index.js index 679f9cda..91f1c57e 100644 --- a/src/_DataStructures_/Trees/Trie/total-words-in-trie/index.js +++ b/src/_DataStructures_/Trees/Trie/total-words-in-trie/index.js @@ -14,10 +14,10 @@ function totalWords(root) { return result; } -// const words = ['bed', 'ball', 'apple', 'java', 'javascript', 'bed']; -// const trie = new Trie(); +const words = ['bed', 'ball', 'apple', 'java', 'javascript', 'bed']; +const trie = new Trie(); -// words.forEach(word => trie.insert(word)); -// console.log(totalWords(trie.root)); +words.forEach(word => trie.insert(word)); +console.log(totalWords(trie.root)); module.exports = totalWords; diff --git a/src/_DataStructures_/Trees/Trie/total-words-in-trie/total-words-in-trie.test.js b/src/_DataStructures_/Trees/Trie/total-words-in-trie/total-words-in-trie.test.js new file mode 100644 index 00000000..0dba5631 --- /dev/null +++ b/src/_DataStructures_/Trees/Trie/total-words-in-trie/total-words-in-trie.test.js @@ -0,0 +1,35 @@ +const totalWordsInTrie = require('./index') +const Trie = require('../index'); +var assert = require('assert'); + +describe('Data Structure : Trie', () => { + it('Should be class of type Trie', () => { + assert.equal(typeof Trie.prototype.constructor, 'function'); + // expect(typeof Trie.prototype.constructor).toEqual('function'); + }); + + describe('Trie', () => { + + it('Should return 6.', () => { + let newTrie = new Trie(); + const words = ['bed', 'ball', 'apple', 'java', 'javascript', 'bed']; + words.forEach(word => newTrie.insert(word)); + result = totalWordsInTrie.totalWords(newTrie.root); + assert.equal(result, 6); + }); + + it('Should return 0.', () => { + let newTrie = new Trie(); + result = totalWordsInTrie.totalWords(newTrie.root); + assert.equal(result, 0); + }); + + it('Should return 6.', () => { + let newTrie = new Trie(); + const words = ['bed', 'ball','', 'apple', 'java', 'javascript', 'bed']; + words.forEach(word => newTrie.insert(word)); + result = totalWordsInTrie.totalWords(newTrie.root); + assert.equal(result, 6); + }); + }); +}); \ No newline at end of file From 53d3e180fd080f1f0032f7f8f8408cb6001b38c3 Mon Sep 17 00:00:00 2001 From: Nigel Yong Date: Thu, 24 Oct 2019 22:02:11 -0400 Subject: [PATCH 2/3] Commented code in index.js --- .../Trees/Trie/total-words-in-trie/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/_DataStructures_/Trees/Trie/total-words-in-trie/index.js b/src/_DataStructures_/Trees/Trie/total-words-in-trie/index.js index 91f1c57e..679f9cda 100644 --- a/src/_DataStructures_/Trees/Trie/total-words-in-trie/index.js +++ b/src/_DataStructures_/Trees/Trie/total-words-in-trie/index.js @@ -14,10 +14,10 @@ function totalWords(root) { return result; } -const words = ['bed', 'ball', 'apple', 'java', 'javascript', 'bed']; -const trie = new Trie(); +// const words = ['bed', 'ball', 'apple', 'java', 'javascript', 'bed']; +// const trie = new Trie(); -words.forEach(word => trie.insert(word)); -console.log(totalWords(trie.root)); +// words.forEach(word => trie.insert(word)); +// console.log(totalWords(trie.root)); module.exports = totalWords; From a53e1449e10fe41c04be2533c17b3d7809a219b3 Mon Sep 17 00:00:00 2001 From: Nigel Yong <23243585+niyonx@users.noreply.github.com> Date: Fri, 25 Oct 2019 00:25:58 -0400 Subject: [PATCH 3/3] Changed var to const --- .../Trie/total-words-in-trie/total-words-in-trie.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/_DataStructures_/Trees/Trie/total-words-in-trie/total-words-in-trie.test.js b/src/_DataStructures_/Trees/Trie/total-words-in-trie/total-words-in-trie.test.js index 0dba5631..26f51599 100644 --- a/src/_DataStructures_/Trees/Trie/total-words-in-trie/total-words-in-trie.test.js +++ b/src/_DataStructures_/Trees/Trie/total-words-in-trie/total-words-in-trie.test.js @@ -1,6 +1,6 @@ const totalWordsInTrie = require('./index') const Trie = require('../index'); -var assert = require('assert'); +const assert = require('assert'); describe('Data Structure : Trie', () => { it('Should be class of type Trie', () => { @@ -32,4 +32,4 @@ describe('Data Structure : Trie', () => { assert.equal(result, 6); }); }); -}); \ No newline at end of file +});