romaklimenko
9/4/2016 - 8:11 PM

Testing Typescript code highlight

Testing Typescript code highlight

// compose : (A → B) -> (B → C) -> (A → C)
const compose = (f: Function, g: Function) => (x) => g(f(x))
it('(g ∘ f)(a) = g(f(a)) where a ∈ A', () => {
  const a: A = new A('s')         // a ∈ A
  const actual = compose(f, g)(a) // (g ∘ f)(a)
  const expected = g(f(a))        // g(f(a))
  expect(actual).to.deep.equal(expected)
  expect(actual instanceof C).to.be.true   // c ∈ C
  expect(expected instanceof C).to.be.true // c ∈ C
})