Last active
June 18, 2019 04:06
-
-
Save ShivrajRath/b9e9957e7cfe1bc87a95c9a4590ff6d8 to your computer and use it in GitHub Desktop.
Code to run quick assertion on your function algorithms
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 characters
| const equalityCheck = function(input1, input2) { | |
| if (typeof input1 !== typeof input2) { | |
| return false; | |
| } | |
| if (input1 === input2) { | |
| return true; | |
| } | |
| if (Array.isArray(input1) && Array.isArray(input2)) { | |
| return input1.reduce((acc, el, index) => acc && el === input2[index], true); | |
| } | |
| return false; | |
| }; | |
| const testAlgo = function(expectedOutput, ...algoArgs) { | |
| const output = algo(...algoArgs); | |
| console.assert( | |
| equalityCheck(output, expectedOutput), | |
| `Expected output ${expectedOutput} for ${algoArgs} and found ${output}` | |
| ); | |
| }; | |
| // testAlgo([0, 1], [1, 8 , 7, 9], 9); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment