Skip to content

Instantly share code, notes, and snippets.

@berzniz
Created November 10, 2013 21:55
Show Gist options
  • Save berzniz/7404486 to your computer and use it in GitHub Desktop.
Save berzniz/7404486 to your computer and use it in GitHub Desktop.
var inline_test = function(func, inputs, expected_outputs) {
for (var i in inputs) {
var input = inputs[i];
var expected = expected_outputs[i];
var result = func(input);
if (result != expected) {
console.log('Test failed! Expected', expected, 'but got', result);
// Or throw an error...
}
}
return func;
};
var square = inline_test(function square(n) {
return n * n;
}, [2, 4, 8, 16], [4, 16, 64, 99999]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment