All files roundmath.js

83.33% Statements 15/18
100% Branches 2/2
50% Functions 3/6
100% Lines 13/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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          3x   1x       2x   1x   1x   1x 2x 1x   1x                 1x 1x 1x 1x  
/*       */
"use strict";
 
// These won't be exported:
 
const roundToCents = (x        )         => Math.round(x * 100) / 100;
 
const changeSign = (x        )         => -x;
 
// The following will be exported:
 
const addR = (x        , y        )         => roundToCents(x + y);
 
const subR = (x        , y        )         => addR(x, changeSign(y));
 
const multR = (x        , y        )         => roundToCents(x * y);
 
const divR = (x        , y        )         => {
    if (y === 0) {
        throw new Error("Divisor must be nonzero");
    } else {
        return roundToCents(x / y);
    }
};
 
/*
    NOTES:
    1. Exports are all together, at the end, per convention
    2. roundToCents and changeSign are not exported, on purpose
*/
exports.addR = addR;
exports.subR = subR;
exports.multR = multR;
exports.divR = divR;