Last active
August 28, 2019 10:24
-
-
Save WizardOfArc/f64ab1f655c9d8c1f5029911f192a4e2 to your computer and use it in GitHub Desktop.
Revisions
-
WizardOfArc revised this gist
Aug 28, 2019 . 1 changed file with 28 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ function tester(func, input, expected){ let actual = func(...input); 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; } -
WizardOfArc created this gist
Aug 22, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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) ); }