Last active
August 29, 2015 13:57
-
-
Save GZShi/9502278 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
function assert(expectation, fn) { | |
var args = Array.prototype.slice.call(arguments, 2); | |
var ret = fn.apply(fn, args); | |
if(ret === expectation) { | |
return ret; | |
} else { | |
throw new TypeError("调用" + fn.name + | |
"函数时,返回值" + ret + "与预期的" + expectation + "不同"); | |
} | |
} | |
// test case | |
function plus(a, b) { return a + b;} | |
// ok | |
assert(10, plus, 5, 5); | |
// throw error | |
assert(11, plus, 5, 5); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment