Skip to content

Commit

Permalink
Test more elements of the fn file
Browse files Browse the repository at this point in the history
  • Loading branch information
meschbach committed Feb 13, 2020
1 parent e32c96b commit 95499b1
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 11 deletions.
2 changes: 1 addition & 1 deletion fn.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function arg2(_arg1, arg2){
function filterEnvelope(low,high, element){
return function(o){
const value = element(o);
return low < value && value <= high;
return low <= value && value <= high;
}
}

Expand Down
72 changes: 72 additions & 0 deletions fn.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
const {expect} = require("chai");
const {identity, arg2} = require("./fn");

describe("Identity", function(){
describe("when invoked", function(){
it("gives the same value", function () {
expect(identity(1)).to.eq(1);
});
})
});

describe("arg2", function () {
describe("when given two values", function () {
it("returns the second value", function () {
expect(arg2(1,2)).to.eq(2);
});
});
});

const {filterEnvelope} = require("./fn");
describe("filterEnvelope", function (){
describe("When given a low value", function () {
it("is falsy", function () {
expect(filterEnvelope(10,20, identity)(1)).to.be.false;
});
});

describe("When given a high value", function () {
it("is falsy", function () {
expect(filterEnvelope(10,20, identity)(21)).to.be.false;
});
});

describe("When given a value within the envelope", function () {
it("is truthy", function () {
expect(filterEnvelope(10,20, identity)(15)).to.be.true;
});
});

describe("When given a value on the low side of the envelope", function () {
it("is truthy", function () {
expect(filterEnvelope(10,20, identity)(10)).to.be.true;
});
});

describe("When given a value on the high side of the envelope", function () {
it("is truthy", function () {
expect(filterEnvelope(10,20, identity)(20)).to.be.true;
});
});
});

const {y} = require("./fn");
describe("y combinator", function () {
describe("when given no functions", function () {
it("returns the input", function () {
expect(y()(42)).to.eq(42);
})
});

describe("when given a set of functions", function () {
it("calls each one", function () {
let called = 0;
const call = (c) => {
called++;
return called + c;
};
expect(y(call,call,call)(1)).to.eq(7);
expect(called).to.eq(3);
})
});
});
10 changes: 0 additions & 10 deletions tests/fn.js

This file was deleted.

0 comments on commit 95499b1

Please sign in to comment.