test.js
/**
 * Utility function to compare test output with expected values
 * 
 * @param {*} testName 
 * @param {*} expected 
 * @param {*} output 
 */
Utility function to compare test output with expected values


Utility function to compare test output with expected values
function compareOutput(testName, expected, output) {
    let errCnt = 0;
    for (let i = 0; i < expected.length; i++) {
        let ex = expected[i];
        let out = output[i];
        let ok = true;
        if (Array.isArray(ex)) {    
            for (let j = 0; j < ex.length; j++) {
                if (ex[j] != out[j]) {
                    ok = false;
                }
            }
        } else {
            if (ex != out) {
                ok = false;
            }
        }
        if (!ok) {
            errCnt++;
            console.error("Error: " + testName + " output[" + i + "]:" + out + " doesn't match expected value of " + ex);
        }
    }
    console.log(testName + " tests " + (errCnt === 0 ? "passed!" : " failed with " + errCnt + " failures"));
}
function compareOutput ( testName , expected , output ) { let errCnt = 0 ; for ( let i = 0 ; i < expected . length ; i ++ ) { let ex = expected [ i ] ; let out = output [ i ] ; let ok = true ; if ( Array . isArray ( ex ) ) { for ( let j = 0 ; j < ex . length ; j ++ ) { if ( ex [ j ] != out [ j ] ) { ok = false ; } } } else { if ( ex != out ) { ok = false ; } } if ( ! ok ) { errCnt ++ ; console . error ( "Error: " + testName + " output[" + i + "]:" + out + " doesn't match expected value of " + ex ) ; } } console . log ( testName + " tests " + ( errCnt === 0 ? "passed!" : " failed with " + errCnt + " failures" ) ) ; }
Utility function to compare test output with expected values
Utility function to compare test output with expected values
// Compare values, since shallow === doesn't work on arrays