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

Statements: 100% (89 / 89)      Branches: 100% (0 / 0)      Functions: 100% (34 / 34)      Lines: 100% (89 / 89)      Ignored: none     

All files » spec/dataStructures/ » trie.add.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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 1571   1 1 1   1 3 3     1 3     1 1     1 1     1 1       1 1 1 1   1 4 4 4     1 4     1 1     1 1     1 1     1 1       1 1 1 1 1 1   1 6 6 6 6 6     1 6     1 1     1 1     1 1     1 1     1 1     1 1       1 1 1 1 1   1 7 7 7 7     1 7     1 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"
 
	beforeEach(function() {
		tree = new trie();
		tree.add(testValue);
	});
 
	afterEach(function() {
		tree = null;
	});
 
	it('the tree`s head should only contain one entry', function () {
		expect(Object.keys(tree.head).length).toBe(1);
	});
 
	it('the tree`s head should contain the property P.', function () {
		expect(tree.head.P).toBeDefined();
	});
 
	it('the hasWord() method should be able to find Philadelphia', function() {
		expect(tree.hasWord(testValue)).toBe(true);
	});
});
 
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('the tree`s head should only contain one entry', function () {
		expect(Object.keys(tree.head).length).toBe(1);
	});
 
	it('the tree`s head should contain the property P.', function () {
		expect(tree.head.P).toBeDefined();
	});
 
	it('the hasWord() method should be able to find ' + testValue, function() {
		expect(tree.hasWord(testValue)).toBe(true);
	});
 
	it('the hasWord() method should be able to find ' + testValue2, function() {
		expect(tree.hasWord(testValue2)).toBe(true);
	});
});
 
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('the tree`s head should contain one entry', function () {
		expect(Object.keys(tree.head).length).toBe(1);
	});
 
	it('the tree`s head should contain the property f.', function () {
		expect(tree.head.f).toBeDefined();
	});
 
	it('the hasWord() method should be able to find ' + testValue1 , function() {
		expect(tree.hasWord(testValue1)).toBe(true);
	});
 
	it('the hasWord() method should be able to find ' + testValue2, function() {
		expect(tree.hasWord(testValue2)).toBe(true);
	});
 
	it('the hasWord() method should be able to find ' + testValue3, function() {
		expect(tree.hasWord(testValue3)).toBe(true);
	});
 
	it('the hasWord() method should be able to find ' + testValue5, function() {
		expect(tree.hasWord(testValue5)).toBe(true);
	});
});
 
describe('Given a trie containing the words "apple", "banana", and "orange"', function () {
	var tree;
	var testValue1 = "apple";
	var testValue2 = "banana";
	var testValue3 = "orange";
 
	beforeEach(function() {
		tree = new trie();
		tree.add(testValue1);
		tree.add(testValue2);
		tree.add(testValue3);
	});
 
	afterEach(function() {
		tree = null;
	});
 
	it('the tree`s head should contain three entries', function () {
		expect(Object.keys(tree.head).length).toBe(3);
	});
 
	it('the tree`s head should contain the property a.', function () {
		expect(tree.head.a).toBeDefined();
	});
 
	it('the tree`s head should contain the property b.', function () {
		expect(tree.head.b).toBeDefined();
	});
 
	it('the tree`s head should contain the property o.', function () {
		expect(tree.head.o).toBeDefined();
	});
 
	it('the hasWord() method should be able to find ' + testValue1 ,  function() {
		expect(tree.hasWord(testValue1)).toBe(true);
	});
 
	it('the hasWord() method should be able to find ' + testValue2, function() {
		expect(tree.hasWord(testValue2)).toBe(true);
	});
 
	it('the hasWord() method should be able to find ' + testValue3, function() {
		expect(tree.hasWord(testValue3)).toBe(true);
	});
});
 
describe("When adding undefined to the trie", function() {
 
	it('the add() method will throw an exception if given undefined', function() {
		var tree = new trie();
		expect(tree.add).toThrow();
	})
});