Created
November 4, 2016 20:52
-
-
Save angel333/bca5b05362ec65bb24802a8b7544251a to your computer and use it in GitHub Desktop.
This file contains 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
<script src='bench.js'></script> |
This file contains 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
if (undefined === window.testMeTests) | |
window.testMeTests = []; | |
Function.prototype.testMe = function (input, expected) { | |
testMeTests.push({ | |
unit: this, | |
input: input, | |
expected: expected, | |
}); | |
return this; | |
} | |
window.setInterval(function() { | |
var results = window.testMeTests.map(function(test) { | |
var result = test.unit.apply(null, test.input) | |
return Object.assign({}, test, { | |
result: result, | |
ok: result === test.expected | |
}); | |
}); | |
document.open(); | |
results.forEach(function (result) { | |
document.write('<pre style=\'color:'+(result.ok?'green':'red')+'\'>'); | |
document.write(JSON.stringify(result, null, ' ')); | |
document.write('</pre>'); | |
}); | |
}, 300) | |
// Open DevTools and modify this function... | |
var add = function(a,b) { | |
return a + b; | |
} | |
.testMe([1, 2], 3) | |
.testMe([1, -1], 0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment