Skip to content

Instantly share code, notes, and snippets.

@madmax911
Last active September 6, 2022 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madmax911/480435e38bffa1198cd1996838116d3b to your computer and use it in GitHub Desktop.
Save madmax911/480435e38bffa1198cd1996838116d3b to your computer and use it in GitHub Desktop.
An example of unit tests for a currying function. One of the Casidoo challenges.
// Currying (cool stuff)
function addg(a) {
if (a === undefined) return a;
return function g(b) {
if (b !== undefined) {
return addg(a+b);
}
return a;
};
}
Unit test for addg:
console.assert(addg() === undefined, `addg() === ${addg()}, should be undefined`);
console.assert(typeof addg(1) === "function", `typeof addg(1) === ${typeof addg(1)}, should be function`);
console.assert(addg(1)(2)() === 3, `addg(1)(2)() === ${addg(1)(2)()}, should be 3`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment