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

var timeoutMs = 3000;

function assertImmutable(methodName, immutableArray, mutableArray, args) {
  var mutableResult   =   mutableArray[methodName].apply(mutableArray,   args);
  var immutableResult = Immutable(immutableArray[methodName].apply(immutableArray, args));

  assert.deepEqual(immutableResult, mutableResult);
}

function ImmutableArraySpecifier(JSC) {
  var args = Array.prototype.slice.call(arguments);

  return function generator() {
    var mutable = JSC.array.apply(JSC.array, args)();

    return Immutable(mutable);
  }
}

function check(runs, generators, runTest) {
  var completed;

  if (typeof generators === "function") {
    generators = [generators];
  } else if (!(generators instanceof Array)) {
    throw new TypeError("Not a valid generator list: " + JSON.stringify(generators))
  }

  for (completed=0; completed < runs; completed++) {
    var generated = generators.map(function(generator) { return generator() });

    runTest.apply(runTest, generated);
  }

  assert.strictEqual(completed, runs,
    "The expected " + runs + " runs were not completed.");

  return completed;
}

function checkImmutableMutable(runs, specifiers) {
  return function(callback, extraSpecifiers) {
    extraSpecifiers = extraSpecifiers || [];

  check(runs, specifiers.concat(extraSpecifiers), function(mutable) {
      var immutable = Immutable(mutable);
      var args      = Array.prototype.slice.call(arguments);

      callback.apply(callback, [immutable].concat(args));
    });
  };
}

module.exports = {
  assertImmutable:         assertImmutable,
  ImmutableArraySpecifier: ImmutableArraySpecifier,
  check:                   check,
  checkImmutableMutable:   checkImmutableMutable
}
@@ -127,31 +127,8 @@
 t;%0A%0A
-var timeoutMs = 3000;%0A%0A
 func
@@ -709,218 +709,8 @@
 d;%0A%0A
-  if (typeof generators === %22function%22) %7B%0A    generators = %5Bgenerators%5D;%0A  %7D else if (!(generators instanceof Array)) %7B%0A    throw new TypeError(%22Not a valid generator list: %22 + JSON.stringify(generators))%0A  %7D%0A%0A
   fo
@@ -1148,16 +1148,18 @@
 %7C%7C %5B%5D;%0A%0A
+  
   check(

Clean up some dead code.