Code coverage report for spec/dataStructures/trie.remove.spec.js

Statements: 100% (72 / 72)      Branches: 100% (0 / 0)      Functions: 100% (18 / 18)      Lines: 100% (72 / 72)      Ignored: none     

All files » spec/dataStructures/ » trie.remove.spec.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 1111   1 1 1 1   1 2 2     1 2     1 1 1     1 1 1 1       1 1 1 1   1 3 3 3     1 3     1 1 1 1     1 1 1 1     1 1 1 1 1 1       1 1 1 1 1 1   1 2 2 2 2 2     1 2       1 1 1 1 1 1         1 1 1 1 1 1 1       1   1 1 1    
var trie = require("../../lib/dataStructures/trie.js");
 
describe('Given a trie containing the word "Philadelphia"', function () {
	var tree;
	var testValue = "Philadelphia"
	var testValue2 = "Phil";
 
	beforeEach(function() {
		tree = new trie();
		tree.add(testValue);
	});
 
	afterEach(function() {
		tree = null;
	});
 
	it('after removing "Phil", the trie should still contain Philadelphia.', function () {
		tree.remove(testValue2);
		expect(tree.hasWord(testValue)).toBe(true);
	});
 
	it('after removing "Philadelphia", the trie should be empty.', function () {
		tree.remove(testValue);
		expect(tree.hasWord(testValue)).toBe(false);
		expect(Object.keys(tree.head).length).toBe(0);
	});
});
 
describe('Given a trie containing the words "Philadelphia" and "Phil"', function () {
	var tree;
	var testValue = "Philadelphia"
	var testValue2 = "Phil";
 
	beforeEach(function() {
		tree = new trie();
		tree.add(testValue);
		tree.add(testValue2);
	});
 
	afterEach(function() {
		tree = null;
	});
 
	it('after removing "Phil", the trie should still contain Philadelphia.', function () {
		tree.remove(testValue2);
		expect(tree.hasWord(testValue)).toBe(true);
		expect(tree.hasWord(testValue2)).toBe(false);
	});
 
	it('after removing "Philadelphia", the trie should be still contain "Phil".', function () {
		tree.remove(testValue);
		expect(tree.hasWord(testValue)).toBe(false);
		expect(tree.hasWord(testValue2)).toBe(true);
	});
 
	it('after removing "Philadelphia" and "Phil", the trie should be empty.', function () {
		tree.remove(testValue);
		tree.remove(testValue2);
		expect(tree.hasWord(testValue)).toBe(false);
		expect(tree.hasWord(testValue2)).toBe(false);
		expect(Object.keys(tree.head).length).toBe(0);
	});
});
 
describe('Given a trie containing the words "free", "freed", "freedom", and "frees"', function () {
	var tree;
	var testValue1 = "free";
	var testValue2 = "freed";
	var testValue3 = "frees";
	var testValue5 = "freedom";
 
	beforeEach(function() {
		tree = new trie();
		tree.add(testValue1);
		tree.add(testValue2);
		tree.add(testValue3);
		tree.add(testValue5);
	});
 
	afterEach(function() {
		tree = null;
	});
 
 
	it('after deleting ' + testValue2 + ", " + testValue1 + " & " + testValue5 + " should still exist" , function() {
		tree.remove(testValue2);
		expect(tree.hasWord(testValue1)).toBe(true);
		expect(tree.hasWord(testValue2)).toBe(false);
		expect(tree.hasWord(testValue3)).toBe(true);
		expect(tree.hasWord(testValue5)).toBe(true);
	});
 
 
 
	it('after deleting ' + testValue3 + " & " + testValue5 + ", " + testValue1 + " & " + testValue2 + " should still exist" , function() {
		tree.remove(testValue3);
		tree.remove(testValue5);
		expect(tree.hasWord(testValue1)).toBe(true);
		expect(tree.hasWord(testValue2)).toBe(true);
		expect(tree.hasWord(testValue3)).toBe(false);
		expect(tree.hasWord(testValue5)).toBe(false);
	});
});
 
describe("When calling trie.remove() with the word undefined", function() {
 
	it('the remove() method will throw an exception', function() {
		var tree = new trie();
		expect(tree.remove).toThrow();
	})
});