// Generated by purs version 0.12.5
"use strict";
var Control_Bind = require("../Control.Bind/index.js");
var Data_Foldable = require("../Data.Foldable/index.js");
var Data_List_Types = require("../Data.List.Types/index.js");
var Data_Maybe = require("../Data.Maybe/index.js");
var Data_Show = require("../Data.Show/index.js");
var Effect_Aff = require("../Effect.Aff/index.js");
var Effect_Class = require("../Effect.Class/index.js");
var Random_LCG = require("../Random.LCG/index.js");
var Test_QuickCheck = require("../Test.QuickCheck/index.js");
var Test_Unit = require("../Test.Unit/index.js");
var quickCheck$prime = function (dictTestable) {
    return function (tries) {
        return function (prop) {
            return Control_Bind.bind(Effect_Aff.bindAff)(Effect_Class.liftEffect(Effect_Aff.monadEffectAff)(Random_LCG.randomSeed))(function (v) {
                var wins$prime = function (acc) {
                    return function (v1) {
                        if (v1 instanceof Test_QuickCheck.Success) {
                            return acc + 1 | 0;
                        };
                        return acc;
                    };
                };
                var results = Test_QuickCheck.quickCheckPure(dictTestable)(v)(tries)(prop);
                var wins = Data_Foldable.foldl(Data_List_Types.foldableList)(wins$prime)(0)(results);
                var findErr = function ($copy_v1) {
                    var $tco_done = false;
                    var $tco_result;
                    function $tco_loop(v1) {
                        if (v1 instanceof Data_List_Types.Nil) {
                            $tco_done = true;
                            return Data_Maybe.Nothing.value;
                        };
                        if (v1 instanceof Data_List_Types.Cons && v1.value0 instanceof Test_QuickCheck.Failed) {
                            $tco_done = true;
                            return new Data_Maybe.Just(v1.value0.value0);
                        };
                        if (v1 instanceof Data_List_Types.Cons) {
                            $copy_v1 = v1.value1;
                            return;
                        };
                        throw new Error("Failed pattern match at Test.Unit.QuickCheck (line 23, column 7 - line 23, column 28): " + [ v1.constructor.name ]);
                    };
                    while (!$tco_done) {
                        $tco_result = $tco_loop($copy_v1);
                    };
                    return $tco_result;
                };
                var v1 = findErr(results);
                if (v1 instanceof Data_Maybe.Nothing) {
                    return Test_Unit.success;
                };
                if (v1 instanceof Data_Maybe.Just) {
                    return Test_Unit.failure(Data_Show.show(Data_Show.showInt)(tries - wins | 0) + ("/" + (Data_Show.show(Data_Show.showInt)(tries) + (" tests failed: " + v1.value0))));
                };
                throw new Error("Failed pattern match at Test.Unit.QuickCheck (line 26, column 3 - line 28, column 95): " + [ v1.constructor.name ]);
            });
        };
    };
};
var quickCheck = function (dictTestable) {
    return quickCheck$prime(dictTestable)(100);
};
module.exports = {
    quickCheck: quickCheck,
    "quickCheck'": quickCheck$prime
};
