Skip to content

Commit

Permalink
more test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
peterkhayes committed Jul 15, 2014
1 parent 29d9b51 commit eed95bd
Showing 1 changed file with 32 additions and 30 deletions.
62 changes: 32 additions & 30 deletions FunctionalProgramming/spec/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,38 @@ describe("Basic building blocks", function() {
});
});



describe("More specialized functions", function() {

it("every", function() {
expect(every([1, 2, 3, 4, 5, 6], function(x) {return x < 10;})).to.be(true);
expect(every([1, 2, 3, 4, 25, 6], function(x) {return x < 10;})).to.be(false);
});

it("some", function() {
expect(every([1, 2, 3, 4, 25, 6], function(x) {return x > 10;})).to.be(true);
expect(every([1, 2, 3, 4, 5, 6], function(x) {return x > 10;})).to.be(false);
});

it("unique", function() {
var result = unique(["a", "ab", "a", "b", "ab", "ba"]);
assertArrayEquals(result, ["a", "ab", "b", "ba"]);
});

it("flatten", function() {
var result = flatten([1, 2, [3, [4]]]);
assertArrayEquals(result, [1, 2, 3, 4]);
});

it("contains", function() {
expect(contains([1, 2, 3, 4], 1)).to.be(true);
expect(contains([1, 2, 3, 4], 0)).to.be(false);
});

});


checkIfFunctionalSolution = function(func) {
func = func.toString();
expect(func).to.not.contain("for(");
Expand Down Expand Up @@ -109,33 +141,3 @@ describe("Applied problems", function() {
checkIfFunctionalSolution(olderOrWithChildren);
});
});


describe("More specialized functions", function() {

describe("every", function() {
expect(every([1, 2, 3, 4, 5, 6], function(x) {return x < 10;})).to.be(true);
expect(every([1, 2, 3, 4, 25, 6], function(x) {return x < 10;})).to.be(false);
});

describe("some", function() {
expect(every([1, 2, 3, 4, 25, 6], function(x) {return x > 10;})).to.be(true);
expect(every([1, 2, 3, 4, 5, 6], function(x) {return x > 10;})).to.be(false);
});

describe("unique", function() {
var result = unique(["a", "ab", "a", "b", "ab", "ba"]);
assertArrayEquals(result, ["a", "ab", "b", "ba"]);
});

describe("flatten", function() {
var result = flatten([1, 2, [3, [4]]]);
assertArrayEquals(result, [1, 2, 3, 4]);
});

describe("contains", function() {
expect(contains([1, 2, 3, 4], 1)).to.be(true);
expect(contains([1, 2, 3, 4], 0)).to.be(false);
});

});

0 comments on commit eed95bd

Please sign in to comment.