Code coverage report for src/diamond.js

Statements: 89.83% (53 / 59)      Branches: 80% (16 / 20)      Functions: 90% (9 / 10)      Lines: 89.83% (53 / 59)      Ignored: 7 statements, 1 function, 4 branches     

All files » src/ » diamond.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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108  1 1 1 1   1   1   1   1       1                     1 16 16     1 2 2 2   2 1     2     1 9 9   9   9 5     9     1 12   12   12     1 12 12   12 1     11   11     1 41 1     40     1 3 3   3 6     3     1 3   3 2 4       3  
/* istanbul ignore next */
function notTested(input) {
    if (true) {
        if (true) {
            var lala = 'lulu';
        } else {
            var lala = 'lulu';
        }
        var lala = 'lulu';
    } else {
        var lala = 'lulu';
    }
    return 'Input: ' + input;
 
}
 
function test(input) {
    var value = 1;
    if (input < 10) {
        value = 2;
    }
    if (input % 2 === 0) {
        value *= input;
    }
    return value;
}
 
function Diamond (value) {
    this.value = value;
    this.codeOfA = 'A'.charCodeAt(0);
}
 
Diamond.prototype.toString = function () {
    var lines = this.upperHalf(this.value);
    var result = lines.join('\n');
    var lowerHalf = this.lowerHalf(lines);
 
    if (lowerHalf) {
        result += '\n' + lowerHalf;
    }
 
    return result;
};
 
Diamond.prototype.line = function (current, widest) {
    var outerSpace = this.outerSpace(current, widest);
    var innerSpace = this.innerSpace(current);
 
    var line = outerSpace + current;
 
    if (innerSpace) {
        line += innerSpace + current;
    }
 
    return line;
};
 
Diamond.prototype.innerSpace = function (value) {
    var index = this.getIndexOf(value);
 
    var spaces = 2 * (index - 1) - 1;
 
    return new Array(spaces + 1).join(' ');
};
 
Diamond.prototype.outerSpace = function (current, widest) {
    var currentValue = this.getIndexOf(current);
    var widestValue = this.getIndexOf(widest);
 
    if (currentValue > widestValue) {
        throw new Error('Invalid combination of arguments');
    }
 
    var spaces = widestValue - currentValue;
 
    return new Array(spaces + 1).join(' ');
};
 
Diamond.prototype.getIndexOf = function (char) {
    if (false === /^[A-Z]$/.test(char)) {
        throw new Error('Invalid Argument');
    }
 
    return char.charCodeAt(0) - this.codeOfA +1;
};
 
Diamond.prototype.upperHalf = function (char) {
    var index = this.getIndexOf(char);
    var result = [];
 
    for (var i = 0; i < index; i++) {
        result.push(this.line(String.fromCharCode(i + this.codeOfA), char));
    }
 
    return result;
};
 
Diamond.prototype.lowerHalf = function (lines) {
    var result = [];
 
    if (lines && lines.length > 1) {
        for (var i = lines.length - 2; i >= 0; i--) {
            result.push(lines[i]);
        }
    }
 
    return result.join('\n');
};