Code coverage report for spec/dataStructures/binaryHeap.Validator.js

Statements: 77.27% (17 / 22)      Branches: 55.56% (10 / 18)      Functions: 100% (2 / 2)      Lines: 80.95% (17 / 21)      Ignored: none     

All files » spec/dataStructures/ » binaryHeap.Validator.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 361 4 4     1   16 4 4     16 16 16 16   16 12     12     4             4       1
var validate = function(heap) {
	Iif(heap === undefined) throw "A valid heap must be provided to validate.";
	this.heap = heap;
}
 
validate.prototype.isValid = function(parent, length){
 
	if (arguments.length === 0) {
		parent = 0;
		length = this.heap.array.length;
	}
 
	Eif (parent < length) {
		var left = this.heap.getLeftChild(parent);
		var right = this.heap.getRightChild(parent);
		var isValid = true;
 
		if(left < length) {
			Iif(this.heap.shouldSwap(this.heap.array[left], this.heap.array[parent]))
				return false;
			else
				return isValid = isValid && this.isValid(left, length);
		}
 
		Iif(right < length) {
			if(this.heap.shouldSwap(this.heap.array[right], this.heap.array[parent]))
				return false;
			else
				return isValid = isValid && this.isValid(right, length);
		}
 
		return isValid;
	}
};
 
module.exports = validate;