Skip to content

Instantly share code, notes, and snippets.

@DominicFinn
Created May 19, 2013 20:10
Show Gist options
  • Save DominicFinn/5608818 to your computer and use it in GitHub Desktop.
Save DominicFinn/5608818 to your computer and use it in GitHub Desktop.
The specs below rely on Jasmine (http://pivotal.github.io/jasmine/). Just a little test with the Jasmine framework as I haven't really looked at it for more than a year now.
function addTwoNumbers(x, y) {
var oldX = x, oldY = y;
if (typeof oldY === "undefined") {
return function(newY) {
return oldX + newY;
};
}
return x + y;
}
describe("Currying", function() {
it("should calculate sums correctly", function () {
});
describe("when 2 numbers are passed", function() {
var result = addTwoNumbers(10, 20);
it("the correct total should be calculated", function() {
expect(result).toBe(30);
});
});
describe("when only 1 number is passed", function() {
var result = addTwoNumbers(10);
it("a function should be returned that will have the original passed in a closure", function () {
var isAFunction = helpers.isFunction(result);
expect(isAFunction).toBe(true);
});
it("if another number is passed to the function returned, it should return the sum of the partially applied original and the new number", function() {
var newResult = result(10);
expect(newResult).toBe(20);
});
});
});
var helpers = {
isFunction: function(functionToCheck) {
var getType = {};
return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]';
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment