Skip to content

Instantly share code, notes, and snippets.

@WizardOfArc
Last active August 28, 2019 10:24
Show Gist options
  • Select an option

  • Save WizardOfArc/f64ab1f655c9d8c1f5029911f192a4e2 to your computer and use it in GitHub Desktop.

Select an option

Save WizardOfArc/f64ab1f655c9d8c1f5029911f192a4e2 to your computer and use it in GitHub Desktop.

Revisions

  1. WizardOfArc revised this gist Aug 28, 2019. 1 changed file with 28 additions and 2 deletions.
    30 changes: 28 additions & 2 deletions tiny_tester.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    function tester(func, input, expected){
    let actual = func(...input);
    if ( actual === expected ){
    if ( compare(actual, expected) ){
    console.log( "PASS" );
    } else {
    console.log( "FAIL: actual [" + actual + "] did not equal expected [" + expected + "]");
    @@ -9,4 +9,30 @@ function tester(func, input, expected){

    function batchTester(func, testCases){
    testCases.forEach( tc => tester(func, tc.input, tc.expected) );
    }
    }

    const compare = (a,b) => {
    let aType = typeof a;
    let bType = typeof b;
    if(aType === "undefined" || bType === "undefined" || aType != bType){
    return false;
    }
    if(aType === "string" || aType === "number" || aType === "boolean"){
    return a == b
    }
    if(aType === "object"){
    let aKeys = Object.keys(a);
    let bKeys = Object.keys(b);
    if(aKeys.length != bKeys.length){
    return false;
    }
    for(let i = 0; i < aKeys.length; i++){
    if(b[aKeys[i]] != a[aKeys[i]]){
    return false;
    }
    }
    return true;
    }
    return undefined;
    }

  2. WizardOfArc created this gist Aug 22, 2019.
    12 changes: 12 additions & 0 deletions tiny_tester.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    function tester(func, input, expected){
    let actual = func(...input);
    if ( actual === expected ){
    console.log( "PASS" );
    } else {
    console.log( "FAIL: actual [" + actual + "] did not equal expected [" + expected + "]");
    }
    }

    function batchTester(func, testCases){
    testCases.forEach( tc => tester(func, tc.input, tc.expected) );
    }