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

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

All files » spec/algo/4-binaryTrees/ » makeList.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 651 1   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   1 1 1 1 1 1 1 1    
var bst = require("../../../lib/dataStructures/binarySearchTree.js");
var makeList =  require("../../../lib/algorithms/4-binaryTrees/makeList.js");
 
describe('Given a binary search tree, create a linked list at each depth', function () {
    var tree;
 
    beforeEach(function() {
        tree = new bst();
    });
 
    it('with a binary search tree of size 1', function () {
        tree.add(10);
 
        var list = makeList(tree.head);
 
        expect(list).not.toBe(null);
        expect(list.data.start.data).toBe(10);
    });
 
    it('with a tree of size 2', function () {
        tree.add(10);
        tree.add(9);
 
        var list = makeList(tree.head);
 
        expect(list).not.toBe(null);
        expect(list.data.start.data).toBe(10);
        expect(list.next.data.start.data).toBe(9);
    });
 
    it('with a tree of size 3', function () {
        tree.add(9);
        tree.add(10);
        tree.add(8);
 
        var list = makeList(tree.head);
 
        expect(list).not.toBe(null);
        expect(list.data.start.data).toBe(9);
        expect(list.next.data.length).toBe(2);
        expect(list.next.data.start.data).toBe(8);
        expect(list.next.data.end.data).toBe(10);
    });
 
    it('with a tree of size 4', function () {
        tree.add(5);
        tree.add(8);
        tree.add(3);
        tree.add(1);
        tree.add(4);
        tree.add(6);
        tree.add(9);
 
        var list = makeList(tree.head);
 
        expect(list).not.toBe(null);
        expect(list.data.start.data).toBe(5);
        expect(list.next.data.length).toBe(2);
        expect(list.next.data.start.data).toBe(3);
        expect(list.next.data.end.data).toBe(8);
        expect(list.next.next.data.length).toBe(4);
        expect(list.next.next.data.start.data).toBe(1);
        expect(list.next.next.data.end.data).toBe(9);
    });
});