More function tests #7

Merged
merged 4 commits into from Apr 15, 2012

2 participants

@jakubmal

Hey,
Could you give me some initial feedback, so I know your expectations and how to contribute?

Btw, cool project, looking forward to testing someone ;)

@rmurphey rmurphey commented on an outdated diff Apr 13, 2012
tests/app/functions.js
@@ -34,5 +34,57 @@ 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 () {
+ // define a function for fn so that the following will pass
@rmurphey
Owner

You may want to be clear that you're expecting that a single function will meet all of the expectations below.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@rmurphey rmurphey commented on an outdated diff Apr 13, 2012
tests/app/functions.js
@@ -34,5 +34,57 @@ 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 () {
+ // define a function for fn so that the following will pass
+
+ //sum all arguments that are passed to the function
+ expect(fn(1)).to.be(1);
+ expect(fn(1, 2)).to.be(3);
+ expect(fn(1, 2, 3)).to.be(6);
+ expect(fn(1, 2, 3, 4)).to.be(10);
+ expect(fn(1, 2, 3, 4, 5)).to.be(15);
+ expect(fn(1, 2, 3, 4, 5, 6)).to.be(21);
+ expect(fn(54, 6, 543, 6543, 32, 321)).to.be(7499);
+ });
+
+ it("you should be able to curry existing functions", function () {
@rmurphey
Owner

Ditto here, it wasn't clear at a glance that the same function should cause all tests to pass. Maybe move curryMe2 up to the top and put all the expectations together?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@rmurphey rmurphey commented on an outdated diff Apr 13, 2012
tests/app/functions.js
+ expect(fn(curryMe1, "Mark")("Zuckerberg", "Facebook")).to.be("Hey! I'm Mark Zuckerberg from Facebook");
+ expect(fn(curryMe1, "Mark", "Zuckerberg")("Facebook")).to.be("Hey! I'm Mark Zuckerberg from Facebook");
+ expect(fn(curryMe1, "Mark", "Zuckerberg", "Facebook")()).to.be("Hey! I'm Mark Zuckerberg from Facebook");
+
+ var curryMe2 = function (x, y, z) {
+ return x / y * z;
+ };
+
+ expect(fn(curryMe2)(12, 3, 5)).to.be(20);
+ expect(fn(curryMe2, 12)(3, 5)).to.be(20);
+ expect(fn(curryMe2, 12, 3)(5)).to.be(20);
+ expect(fn(curryMe2, 12, 3, 5)()).to.be(20);
+ });
+
+ it('you should be able to use closure', function () {
+ var arr = [54, 2345, 32, 45, 127];
@rmurphey
Owner

Super nitpicky: If the actual numbers aren't important here, might be better to use strings like 'a', b', ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@rmurphey rmurphey commented on an outdated diff Apr 13, 2012
tests/app/functions.js
+ expect(fn(curryMe1)("Mark", "Zuckerberg", "Facebook")).to.be("Hey! I'm Mark Zuckerberg from Facebook");
+ expect(fn(curryMe1, "Mark")("Zuckerberg", "Facebook")).to.be("Hey! I'm Mark Zuckerberg from Facebook");
+ expect(fn(curryMe1, "Mark", "Zuckerberg")("Facebook")).to.be("Hey! I'm Mark Zuckerberg from Facebook");
+ expect(fn(curryMe1, "Mark", "Zuckerberg", "Facebook")()).to.be("Hey! I'm Mark Zuckerberg from Facebook");
+
+ var curryMe2 = function (x, y, z) {
+ return x / y * z;
+ };
+
+ expect(fn(curryMe2)(12, 3, 5)).to.be(20);
+ expect(fn(curryMe2, 12)(3, 5)).to.be(20);
+ expect(fn(curryMe2, 12, 3)(5)).to.be(20);
+ expect(fn(curryMe2, 12, 3, 5)()).to.be(20);
+ });
+
+ it('you should be able to use closure', function () {
@rmurphey
Owner

I think this should say "closures" not "closure"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@rmurphey
Owner

Minor comments but this is great stuff. Thanks!

@rmurphey
Owner

I have some tiny language tweaks, but I'm going to go ahead and merge this. Thanks!

@rmurphey rmurphey merged commit 2145b5f into rmurphey:master Apr 15, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment