Code coverage report for spec/algo/4-binaryTrees/createBst.spec.js

Statements: 100% (36 / 36)      Branches: 100% (0 / 0)      Functions: 100% (6 / 6)      Lines: 100% (36 / 36)      Ignored: none     

All files » spec/algo/4-binaryTrees/ » createBst.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 561   1 1   1 4     1 1   1   1 1     1 1 1   1   1 1 1     1 1 1 1   1   1 1 1 1     1 1 1 1 1   1   1 1 1 1    
var createBst = require("../../../lib/algorithms/4-binaryTrees/createBst.js");
 
describe('Given an array sorted in ascending order, create a binary search tree', function () {
	var array;
 
	beforeEach(function() {
		array = [];
	});
 
	it('with a array of size 1', function () {
		array.push(10);
 
		var bst = createBst(array);
 
		expect(bst).not.toBe(null);
		expect(bst.data).toBe(10);
	});
 
	it('with a array of size 2', function () {
		array.push(10);
		array.push(9);
 
		var bst = createBst(array);
 
		expect(bst).not.toBe(null);
		expect(bst.data).toBe(10);
		expect(bst.left.data).toBe(9);
	});
 
	it('with a array of size 3', function () {
		array.push(10);
		array.push(9);
		array.push(8);
 
		var bst = createBst(array);
 
		expect(bst).not.toBe(null);
		expect(bst.data).toBe(9);
		expect(bst.left.data).toBe(8);
		expect(bst.right.data).toBe(10);
	});
 
	it('with a array of size 4', function () {
		array.push(10);
		array.push(9);
		array.push(8);
		array.push(7);
 
		var bst = createBst(array);
 
		expect(bst).not.toBe(null);
		expect(bst.data).toBe(9);
		expect(bst.left.data).toBe(8);
		expect(bst.right.data).toBe(10);
	});
});