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 a47787d

Browse files
Merge pull request knaxus#159 from knaxus/codeCoverage
Code coverage
2 parents 5d3d94b + edb379a commit a47787d

File tree

13 files changed

+84
-39
lines changed

13 files changed

+84
-39
lines changed

‎src/_DataStructures_/Heaps/MaxHeap/MaxHeap.test.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@ describe('MaxHeap', () => {
3838
});
3939

4040
it('Should return `null` when heap is empty', () => {
41-
[1, 34].forEach(el => mh.add(el));
42-
expect(mh.getMax()).toEqual(34);
41+
[1, 34, 43, 54, 123].forEach(el => mh.add(el));
42+
mh.remove();
43+
mh.remove();
44+
mh.remove();
45+
mh.remove();
4346
mh.remove();
4447
mh.remove();
4548
expect(mh.getMax()).toEqual(null);

‎src/_DataStructures_/Heaps/MinHeap/MinHeap.test.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,14 @@ describe('MinHeap', () => {
3838
});
3939

4040
it('Should return `null` when heap is empty', () => {
41-
[1, 34].forEach(el => mh.add(el));
41+
[1, 34,43,54,123].forEach(el => mh.add(el));
4242
expect(mh.getMin()).toEqual(1);
4343
mh.remove();
4444
mh.remove();
45+
mh.remove();
46+
mh.remove();
47+
mh.remove();
48+
mh.remove();
4549
expect(mh.getMin()).toEqual(null);
4650
});
4751

‎src/_DataStructures_/LinkedList/LinkedList.test.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,11 @@ describe('Data Structures: Linked Lists', () => {
224224
});
225225

226226
it('Should remove and return the element at given index value', () => {
227-
expect(list.removeAt(3).data).toEqual('Welcome');
228-
expect(list.removeAt(2).data).toEqual('There!');
227+
list.delete();
228+
[1, 2, 3, 4, 5, 6, 7, 8, 9].forEach(el => list.addAtBeginning(el));
229+
expect(list.removeAt(10).data).toEqual(1);
230+
expect(list.removeAt(0).data).toEqual(9);
231+
expect(list.removeAt(5).data).toEqual(3);
229232
});
230233
});
231234
});

‎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 によって変換されたページ (->オリジナル) /