Skip to content

Commit

Permalink
feat(ch18): add a factory of numerical data types
Browse files Browse the repository at this point in the history
  • Loading branch information
poulzinho committed Mar 7, 2020
1 parent d52a75a commit 096d9be
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/ch-18_composable_data_types/18.1_composable_data_types.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {expect} from 'chai';

describe("Composable custom Data Types", () => {
it("should describe a factory that returns instances (functions) of numerical data types", () => {
const t = value => {
const add = n => t(value + n);

return Object.assign(add, {
toString: () => `t(${value})`,
valueOf: () => value,
})
};

const [x, y, z] = [1, 2, 3];

// Identity
expect(t(x)(0).valueOf()).equal(1);
expect(t(x)(0).valueOf()).equal(t(x).valueOf());

// Associativity
expect(t(x)(t(y))(t(z)).valueOf()).equal(6);
expect(t(x)(t(y)(t(z))).valueOf()).equal(6);
expect(t(x)(t(y))(t(z)).valueOf()).equal(t(x)(t(y)(t(z))).valueOf());
});
});

0 comments on commit 096d9be

Please sign in to comment.