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 0329d44

Browse files
committed
--fix: code coverage 100%
1 parent 5bad659 commit 0329d44

File tree

7 files changed

+50
-16
lines changed

7 files changed

+50
-16
lines changed

‎src/_DataStructures_/Trees/BinaryTree/bottom-view-binary-tree/BottomViewBinaryTree.test.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const BinaryTree = require("../index");
1+
const BinaryTree = require('../index');
22
const bottomView = require('.');
33

44
describe('Bottom View Binary Tree', () => {
5-
let btree
5+
let btree;
66

77
beforeEach(() => {
88
btree = new BinaryTree([1, 2, 3, 4, 5, 6]);

‎src/_DataStructures_/Trees/BinaryTree/btree-traversals.test.js‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1-
const BinaryTree = require("./index");
1+
const BinaryTree = require('./index');
22

3-
describe("Binary Tree Preorder Traversal", () => {
3+
describe('Binary Tree Preorder Traversal', () => {
44
let btree;
55
let preOrderTraversal;
66

7-
describe("Creates BTree", () => {
7+
describe('Creates BTree', () => {
8+
it('Should throw error if argument is not array', () => {
9+
expect(() => {
10+
btree = new BinaryTree('Hello tree');
11+
}).toThrow('Invalid argument to create a Binary Tree');
12+
});
813
btree = new BinaryTree([1, 2, 3, 4, 5, 6]);
914
});
1015

11-
describe("BTree Traversals", () => {
12-
it("should compute the Preorder traversal for the above created binary tree", () => {
16+
describe('BTree Traversals', () => {
17+
it('Should compute the Preorder traversal for the above created binary tree', () => {
1318
preOrderTraversal = btree.preOrder();
1419
expect(preOrderTraversal).toEqual([1, 2, 4, 5, 3, 6]);
1520
});

‎src/_DataStructures_/Trees/Trie/Node.js‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ class TrieNode {
1313
this.isEndOfWord = true;
1414
}
1515

16-
unmarkAsLeaf() {
17-
this.isEndOfWord = false;
18-
}
19-
2016
increaseCount() {
2117
this.wordCount += 1;
2218
}

‎src/_DataStructures_/Trees/Trie/all-words-in-trie/all-words-in-trie.test.js‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ const allWordsInTrie = require('./index');
22
const Trie = require('../index');
33

44
describe('Data Structure : Trie : All Words In Tree', () => {
5+
it('Should return empty array', () => {
6+
const trie = new Trie();
7+
const result = allWordsInTrie(trie.root);
8+
expect(result.length).toEqual(0);
9+
});
10+
511
it('Should return all words sorted alphabetically', () => {
612
const words = ['bed', 'ball', 'apple', 'java', 'javascript', 'bed'];
713
const trie = new Trie();

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ const TrieNode = require('../Node');
55
function getAllWords(root, level, word) {
66
let result = [];
77

8-
if (!root) return result;
9-
108
if (root.isEndOfWord) {
119
let temp = '';
1210
for (let i = 0; i < level; i += 1) {

‎src/_DataStructures_/Trees/Trie/get-unique-words/index.js‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ const TrieNode = require('../Node');
44
function getAllUniqueWords(root, level, word) {
55
let result = [];
66

7-
if (!root) return result;
8-
97
if (root.isEndOfWord) {
108
let temp = '';
119
for (let i = 0; i < level; i += 1) {
@@ -25,7 +23,7 @@ function getAllUniqueWords(root, level, word) {
2523
}
2624

2725
function allUniqueWordsFromTrie(root) {
28-
if (!(root instanceof TrieNode)) {
26+
if (!(root instanceof TrieNode)) {
2927
throw new Error('Invalid argument: Root of Trie is required');
3028
}
3129
const word = []; // char arr to store a word
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const Trie = require('./index');
2+
3+
describe('Data Structure : Trie', () => {
4+
describe('Trie Instance', () => {
5+
it('Should be a class', () => {
6+
expect(typeof Trie.prototype.constructor).toEqual('function');
7+
});
8+
});
9+
10+
describe('Trie API', () => {
11+
const words = ['bed', 'ball', 'apple', 'java', 'javascript'];
12+
let trie;
13+
it('Should insert string', () => {
14+
trie = new Trie();
15+
words.forEach(word => trie.insert(word));
16+
});
17+
18+
it('Should return `True` if string present', () => {
19+
expect(trie.search(words[0])).toEqual(true);
20+
});
21+
22+
it('Should return `False` if string present', () => {
23+
expect(trie.search('Ashu')).toEqual(false);
24+
expect(trie.search('be')).toEqual(false);
25+
});
26+
27+
it('Should return `False` if argument is not pass', () => {
28+
expect(trie.search()).toEqual(false);
29+
});
30+
});
31+
});

0 commit comments

Comments
(0)

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