Code coverage report for spec/algo/3-stacks/hanoi.spec.js

Statements: 100% (43 / 43)      Branches: 100% (0 / 0)      Functions: 100% (13 / 13)      Lines: 100% (43 / 43)      Ignored: none     

All files » spec/algo/3-stacks/ » hanoi.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 661 1   1   1 1 1   1 10 10 10   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   9 18   9      
var towerOfHanoi = require("../../../lib/algorithms/3-stacks/hanoi.js");
var stack = require("../../../lib/dataStructures/stack.js");
 
describe('When dealing with the Tower of Hanoi', function () {
 
    var target;
    var helper;
    var source;
 
    beforeEach(function() {
        target = new stack();
        helper = new stack();
        source = new stack();
    });
    it("null is less than 1", function() {
        expect(null < 1).toBe(true);
    });
 
    it('the source stack, starting with 1 element, ends up having 0 elements', function () {
        test(1);
        expect(source.length).toBe(0);
    });
    it('the helper stack, starting with 0 elements, ends up having 0 elements', function () {
        test(1);
        expect(helper.length).toBe(0);
    });
    it('the target stack, starting with 0 elements, ends up having 1 element', function () {
        test(1);
        expect(target.length).toBe(1);
    });
 
    it('the source stack, starting with 2 elements, ends up having 0 elements', function () {
        test(2);
        expect(source.length).toBe(0);
    });
    it('the helper stack, starting with 0 elements, ends up having 0 elements', function () {
        test(2);
        expect(helper.length).toBe(0);
    });
    it('the target stack, starting with 0 elements, ends up having 2 elements', function () {
        test(2);
        expect(target.length).toBe(2);
    });
 
    it('the source stack, starting with 3 elements, ends up having 0 elements', function () {
        test(3);
        expect(source.length).toBe(0);
    });
    it('the helper stack, starting with 0 elements, ends up having 0 elements', function () {
        test(3);
        expect(helper.length).toBe(0);
    });
    it('the target stack, starting with 0 elements, ends up having 3 elements', function () {
        test(3);
        expect(target.length).toBe(3);
    });
 
    function test(number) {
 
        for(var i = number; i > 0; i--)
        source.push(i);
 
        towerOfHanoi(source, helper, target);
    }
 
});