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

Statements: 94.74% (18 / 19)      Branches: 50% (1 / 2)      Functions: 100% (4 / 4)      Lines: 94.74% (18 / 19)      Ignored: none     

All files » spec/algo/4-binaryTrees/ » printSum.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 701 1   1   1 1 1                                                                               1 6 6 6 6 13   6           1 1     1 1 1      
var printSum = require("../../../lib/algorithms/4-binaryTrees/printSum.js");
var bst = require("../../../lib/dataStructures/binarySearchTree.js");
 
describe('Given a binary tree and a value, print every path that sums to that number', function () {
 
	var callsToPrint = 0;
	var sum = 6;
	var withSum = {
		head: {
			data: 1,
			left: {
				data: 2,
				left: {
					data: 3,
					left: {
						data: 3,
						left: null,
						right: null
					},
					right: {
						data: 1,
						left: null,
						right: null
					}
				},
				right: {
					data: 7,
					left: null,
					right: null
				}
			},
			right: {
				data: 5,
				left: {
					data: 1,
					left: null,
					right: null
				},
				right: {
					data: 6,
					left: null,
					right: null
				}
			}
		}
	};
 
	function print(value) {
		callsToPrint++;
		Eif (typeof value === 'object') {
			var total = 0;
			for(var i = 0, len = value.length; i < len; i++) {
				total = total + value[i];
			}
			expect(total).toEqual(sum);
		} else {
			expect(value).toEqual(sum);
		}
	};
 
	beforeEach(function() {
		callsToPrint = 0;
	});
 
	it('print() should be called 6 times', function () {
		printSum(withSum, sum, print);
		expect(callsToPrint).toEqual(6);
	});
 
});