var Immutable = require("../../seamless-immutable.js");
var JSC       = require("jscheck");
var TestUtils = require("../TestUtils.js");
var assert    = require("chai").assert;
var _         = require("lodash")
var check     = TestUtils.check;

module.exports = function() {
  describe("#flatMap", function() {
    // Sanity check to make sure our QuickCheck logic isn't off the rails.
    it("passes a basic sanity check on canned input", function() {
      var expected = Immutable(["foo", "foo2", "bar", "bar2", "baz", "baz2"]);
      var actual   = Immutable(["foo", "bar", "baz"]).flatMap(function(elem) {
        return [elem, elem + "2"];
      });

      assert.deepEqual(actual, expected);
    });
  });
};
@@ -698,16 +698,1330 @@
 %0A    %7D);
+%0A%0A    it(%22works the same way as map when the iterator function returns non-arrays%22, function() %7B%0A      check(100, %5BJSC.array()%5D, function(array) %7B%0A        var returnValues = array.map(function() %7B return JSC.any()(); %7D);%0A        var iterator = function(value, index) %7B return returnValues%5Bindex%5D; %7D;%0A        var expected = _.map(array, iterator);%0A        var actual   = Immutable(array).flatMap(iterator);%0A%0A        assert.deepEqual(actual, expected);%0A      %7D);%0A    %7D);%0A%0A    it(%22works the same way as map followed by flatten when the iterator function returns arrays%22, function() %7B%0A      check(100, %5BJSC.array()%5D, function(array) %7B%0A        var returnValues = array.map(function() %7B return %5BJSC.any()()%5D; %7D);%0A        var iterator = function(value, index) %7B return returnValues%5Bindex%5D; %7D;%0A        var expected = _.flatten(_.map(array, iterator));%0A        var actual   = Immutable(array).flatMap(iterator);%0A%0A        assert.deepEqual(actual, expected);%0A      %7D);%0A    %7D);%0A%0A    it(%22results in an empty array if the iterator function returns empty array%22, function() %7B%0A      var expected = Immutable(%5B%5D);%0A      var iterator = function() %7B return %5B%5D %7D;%0A%0A      check(100, %5BJSC.array()%5D, function(array) %7B%0A        var actual = Immutable(array).flatMap(iterator);%0A%0A        assert.deepEqual(actual, expected);%0A      %7D);%0A    %7D);
 %0A  %7D);%0A%7D

Add more flatMap tests.