Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #7 from jakubmal/new

More function tests
  • Loading branch information...
commit 2145b5fa4b2b22e25f6419a8a0b8840186074d9b 2 parents ded1bd0 + c908ee9
Rebecca Murphey rmurphey authored
Showing with 79 additions and 0 deletions.
  1. +79 −0 tests/app/functions.js
79 tests/app/functions.js
View
@@ -34,5 +34,84 @@ define([ 'use!underscore' ], function(_) {
var partial = fn(sayIt, 'Hello', 'Ellie');
expect(partial('!!!')).to.be('Hello, Ellie!!!');
});
+
+ it("you should be able to use arguments", function () {
+ fn = function () {
+ // you can only edit function body here
+ };
+
+ var a = Math.random(), b = Math.random(), c = Math.random(), d = Math.random();
+ expect(fn(a)).to.be(a);
+ expect(fn(a, b)).to.be(a + b);
+ expect(fn(a, b, c)).to.be(a + b + c);
+ expect(fn(a, b, c, d)).to.be(a + b + c + d);
+ });
+
+ it("you should be able to apply functions", function () {
+ fn = function (fun) {
+ // you can only edit function body here
+ };
+
+ (function () {
+ var a = Math.random(), b = Math.random(), c = Math.random();
+
+ var wasITake2ArgumentsCalled = false;
+ var iTake2Arguments = function (firstArgument, secondArgument) {
+ expect(arguments.length).to.be(2);
+ expect(firstArgument).to.be(a);
+ expect(secondArgument).to.be(b);
+
+ wasITake2ArgumentsCalled = true;
+ };
+
+ var wasITake3ArgumentsCalled = false;
+ var iTake3Arguments = function (firstArgument, secondArgument, thirdArgument) {
+ expect(arguments.length).to.be(3);
+ expect(firstArgument).to.be(a);
+ expect(secondArgument).to.be(b);
+ expect(thirdArgument).to.be(c);
+
+ wasITake3ArgumentsCalled = true;
+ };
+
+ fn(iTake2Arguments, a, b);
+ fn(iTake3Arguments, a, b, c);
+ })();
+ });
+
+ it("you should be able to curry existing functions", function () {
+ fn = function (fun) {
+ // you can only edit function body here
+ };
+
+ var curryMe = function (x, y, z) {
+ return x / y * z;
+ };
+
+ var a = Math.random(), b = Math.random(), c = Math.random();
+ expect(fn(curryMe)(a, b, c)).to.be(curryMe(a, b, c));
+ expect(fn(curryMe, a)(b, c)).to.be(curryMe(a, b, c));
+ expect(fn(curryMe, a, b)(c)).to.be(curryMe(a, b, c));
+ expect(fn(curryMe, a, b, c)()).to.be(curryMe(a, b, c));
+ expect(fn(curryMe, a, b, c)()).to.be(curryMe(a, b, c));
+ expect(fn(curryMe, b, a, c)()).to.be(curryMe(b, a, c));
+ });
+
+ it('you should be able to use closures', function () {
+ var arr = [Math.random(), Math.random(), Math.random(), Math.random()];
+ var doSomeStuff;
+
+ fn = function (vals) {
+ // you can only edit function body here
+ };
+
+ doSomeStuff = function (x) { return x * x; };
+
+ var funcs = fn(arr);
+ expect(funcs).to.have.length(5);
+ for (var i = funcs.length - 1; i >= 0; i--) {
+ expect(funcs[i]()).to.be(doSomeStuff(arr[i]));
+ };
+ });
});
});
Please sign in to comment.
Something went wrong with that request. Please try again.