/**
 * maryamyriameliamurphies.js
 * A library of Haskell-style morphisms ported to ES2015 JavaScript.
 *
 * test/functor-test.js
 *
 * @file Tests for Functor type class.
 * @license ISC
 */

/* global describe, it */

import {
  $,
  id,
  isEq,
  fmap,
  fmapReplaceBy,
  just,
  tuple,
  list
} from '../source';

describe(`Functor type class`, function() {
  let lst1 = list(1,2,3);
  let lst2 = list(1100,2200,3300);
  let mb = just(5)
  let tup = tuple(1,2);
  describe(`fmap()`, function() {
    it(`should map a function over a functor and return the correct value`, function() {
      let f = x => x * 11;
      let g = x => x * 100;
      isEq(fmap(id, mb), mb).should.be.true;
      isEq(fmap(f, mb), just(55)).should.be.true;
      isEq(fmap(id, tup), tup).should.be.true;
      isEq(fmap(f, tup), tuple(1,22)).should.be.true;
      isEq(fmap(id, lst1), lst1).should.be.true;
      isEq(fmap(f, lst1), list(11,22,33)).should.be.true;
      isEq($(fmap(f))(fmap(g))(lst1), lst2).should.be.true;
      isEq(fmap($(f)(g))(lst1), lst2).should.be.true;
    });
  });
  describe(`fmapReplaceBy()`, function() {
    it(`should replace all locations in a functor with the same value`, function() {
      isEq(fmapReplaceBy(1, mb), just(1)).should.be.true;
      isEq(fmapReplaceBy(2, tup), tuple(2,2)).should.be.true;
      isEq(fmapReplaceBy(5, lst1), list(5,5,5)).should.be.true;
    });
  });
});

@@ -459,16 +459,63 @@
 e(1,2);%0A
+  let f = x =%3E x * 11;%0A  let g = x =%3E x * 100;%0A
   descri
@@ -633,63 +633,8 @@
 ) %7B%0A
-      let f = x =%3E x * 11;%0A      let g = x =%3E x * 100;%0A
     
@@ -1050,24 +1050,159 @@
 ue;%0A    %7D);%0A
+    it(%60should throw an error if the second argument is not a functor%60, function() %7B%0A      fmap.bind(null, f, 0).should.throw;%0A    %7D);%0A
   %7D);%0A  desc

Add test to Functor to assert an error exception