fp-ts-quickcheck
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -50,2 +50,3 @@ "use strict"; | ||
var modules_1 = require("./modules"); | ||
var fp_ts_2 = require("./modules/fp-ts"); | ||
/** | ||
@@ -59,3 +60,3 @@ * @category Model | ||
*/ | ||
var of = function (a) { return ({ arbitrary: fp_ts_1.state.of(a) }); }; | ||
var of = function (a) { return ({ arbitrary: fp_ts_2.state.of(a) }); }; | ||
exports.of = of; | ||
@@ -66,3 +67,3 @@ /** | ||
var map = function (f) { return function (fa) { return ({ | ||
arbitrary: (0, function_1.pipe)(fa.arbitrary, fp_ts_1.state.map(f)), | ||
arbitrary: (0, function_1.pipe)(fa.arbitrary, fp_ts_2.state.map(f)), | ||
}); }; }; | ||
@@ -74,3 +75,3 @@ exports.map = map; | ||
var ap = function (fa) { return function (fab) { return ({ | ||
arbitrary: (0, function_1.pipe)(fab.arbitrary, fp_ts_1.state.ap(fa.arbitrary)), | ||
arbitrary: (0, function_1.pipe)(fab.arbitrary, fp_ts_2.state.ap(fa.arbitrary)), | ||
}); }; }; | ||
@@ -82,3 +83,3 @@ exports.ap = ap; | ||
var chain = function (f) { return function (fa) { return ({ | ||
arbitrary: (0, function_1.pipe)(fa.arbitrary, fp_ts_1.state.chain((0, function_1.flow)(f, function (b) { return b.arbitrary; }))), | ||
arbitrary: (0, function_1.pipe)(fa.arbitrary, fp_ts_2.state.chain((0, function_1.flow)(f, function (b) { return b.arbitrary; }))), | ||
}); }; }; | ||
@@ -116,3 +117,5 @@ exports.chain = chain; | ||
return function (fa) { return ({ | ||
arbitrary: (0, function_1.pipe)(fa.arbitrary, modules_1.generator.chain((0, function_1.flow)(fp_ts_1.option.fromPredicate(predicate), fp_ts_1.option.match(function () { return (0, function_1.pipe)(fa.arbitrary, fp_ts_1.state.apFirst(modules_1.generator.nextSeed)); }, modules_1.generator.of)))), | ||
arbitrary: (0, function_1.pipe)(fa.arbitrary, fp_ts_2.state.chain(fp_ts_2.state.chainRec((0, function_1.flow)(fp_ts_1.either.fromPredicate(predicate, function_1.identity), fp_ts_1.either.map(function (a) { return modules_1.generator.of(fp_ts_1.either.right(a)); }), fp_ts_1.either.getOrElse(function () { | ||
return (0, function_1.pipe)(fa.arbitrary, fp_ts_2.state.apFirst(modules_1.generator.nextSeed), modules_1.generator.map(function (e) { return fp_ts_1.either.left(e); })); | ||
}))))), | ||
}); }; | ||
@@ -119,0 +122,0 @@ } |
@@ -7,6 +7,7 @@ /** | ||
*/ | ||
import { option as O, state as S } from "fp-ts"; | ||
import { either as E } from "fp-ts"; | ||
import { sequenceS, sequenceT } from "fp-ts/lib/Apply"; | ||
import { flow, pipe, unsafeCoerce } from "fp-ts/lib/function"; | ||
import { flow, identity, pipe, unsafeCoerce } from "fp-ts/lib/function"; | ||
import { generator as gen } from "./modules"; | ||
import { state as S } from "./modules/fp-ts"; | ||
/** | ||
@@ -68,3 +69,3 @@ * @category Model | ||
return (fa) => ({ | ||
arbitrary: pipe(fa.arbitrary, gen.chain(flow(O.fromPredicate(predicate), O.match(() => pipe(fa.arbitrary, S.apFirst(gen.nextSeed)), gen.of)))), | ||
arbitrary: pipe(fa.arbitrary, S.chain(S.chainRec(flow(E.fromPredicate(predicate, identity), E.map((a) => gen.of(E.right(a))), E.getOrElse(() => pipe(fa.arbitrary, S.apFirst(gen.nextSeed), gen.map((e) => E.left(e)))))))), | ||
}); | ||
@@ -71,0 +72,0 @@ } |
@@ -7,3 +7,3 @@ { | ||
"homepage": "https://github.com/fp-ts-quickcheck", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"files": [ | ||
@@ -19,2 +19,3 @@ "dist" | ||
"prettier": "^2.4.1", | ||
"standard-version": "^9.3.2", | ||
"ts-jest": "^27.0.5", | ||
@@ -30,3 +31,4 @@ "ts-node": "^10.2.1", | ||
"fp-ts-std": "^0.13.1", | ||
"monocle-ts": "^2.3.11" | ||
"monocle-ts": "^2.3.11", | ||
"newtype-ts": "^0.3.5" | ||
}, | ||
@@ -38,3 +40,3 @@ "scripts": { | ||
}, | ||
"readme": "# fp-ts-test\n\nfp-ts port of Haskell's QuickCheck.\n\n> **NOTE**\n> Please note that shrinking is not yet available.\n> Purescript did the same, so this should be enough to get you started.\n> When shrinking is available, it will be transparently added as major release.\n\n## Features\n\n- [x] Purely functional implementation.\n- [x] Compatible - Easily integrates into existing testing frameworks.\n- [x] Polymorphic - Create custom assert functions using fp-ts typeclass instances.\n- [x] Extensible - Simply add compatibilty assertions for data structures\n\n## Installation\n\n```sh\nyarn add -D fp-ts-test\n```\n\n## Quick Start\n\nGrab your favourite test library, in this case `jest`, and put the assertion call of this library into the test caller.\n\n```ts\n// main.ts\nexport function subtract(x: number, y: number) {\n return x - y\n}\n\n// main.spec.ts\nimport { quickcheck as qc, arbitrary as AT } from \"fp-ts-test\"\nimport { expect, it, describe } from \"@jest/globals\"\n\nimport { pipe } from \"fp-ts/function\"\n\nimport { subtract } from \"./main\"\n\ndescribe(subtract, () => {\n const arbitrary = AT.tuple(AT.number, AT.number)\n\n it(\n \"should always be smaller than the first argument\",\n pipe(\n arbitrary,\n // returns a thunk by default, because `qc.assert` throws\n qc.assert(([x, y]) => x > subract(x, y)),\n ),\n )\n\n it(\n \"should matter which order the arguments are passed\",\n pipe(\n arbitrary,\n // returns a thunk by default, because `qc.assert` throws\n qc.assert(([x, y]) => subtract(y, x) !== subract(x, y)),\n ),\n )\n})\n```\n" | ||
"readme": "# fp-ts-test\n\nfp-ts port of Haskell's QuickCheck.\n\n> **NOTE**\n> Please note that shrinking is not yet available.\n> Purescript did the same, so this should be enough to get you started.\n> When shrinking is available, it will be transparently added as major release.\n\n## Features\n\n- [x] Purely functional implementation.\n- [x] Compatible - Easily integrates into existing testing frameworks.\n- [x] Polymorphic - Create custom assert functions using fp-ts typeclass instances.\n- [x] Extensible - Simply add compatibilty assertions for data structures\n\n## Installation\n\n```sh\nyarn add -D fp-ts-test\n```\n\n## Quick Start\n\nGrab your favourite test library, in this case `jest`, and put the assertion call of this library into the test caller.\n\n```ts\n// main.ts\nexport function subtract(x: number, y: number) {\n return x - y\n}\n\n// main.spec.ts\nimport { quickcheck as qc, arbitrary as AT } from \"fp-ts-test\"\nimport { expect, it, describe } from \"@jest/globals\"\n\nimport { pipe } from \"fp-ts/function\"\n\nimport { subtract } from \"./main\"\n\ndescribe(subtract, () => {\n const numnum = AT.tuple(AT.number, AT.number)\n\n it(\n \"should always be smaller than the first argument\",\n // returns a thunk by default, because `qc.assert` throws\n qc.assertIO(numnum, ([x, y]) => x > subract(x, y)),\n )\n\n it(\n \"should matter which order the arguments are passed\",\n // returns a thunk by default, because `qc.assert` throws\n qc.assertIO(numnum, ([x, y]) => subtract(y, x) !== subract(x, y)),\n )\n})\n```\n" | ||
} |
@@ -42,11 +42,8 @@ # fp-ts-test | ||
describe(subtract, () => { | ||
const arbitrary = AT.tuple(AT.number, AT.number) | ||
const numnum = AT.tuple(AT.number, AT.number) | ||
it( | ||
"should always be smaller than the first argument", | ||
pipe( | ||
arbitrary, | ||
// returns a thunk by default, because `qc.assert` throws | ||
qc.assert(([x, y]) => x > subract(x, y)), | ||
), | ||
// returns a thunk by default, because `qc.assert` throws | ||
qc.assertIO(numnum, ([x, y]) => x > subract(x, y)), | ||
) | ||
@@ -56,9 +53,6 @@ | ||
"should matter which order the arguments are passed", | ||
pipe( | ||
arbitrary, | ||
// returns a thunk by default, because `qc.assert` throws | ||
qc.assert(([x, y]) => subtract(y, x) !== subract(x, y)), | ||
), | ||
// returns a thunk by default, because `qc.assert` throws | ||
qc.assertIO(numnum, ([x, y]) => subtract(y, x) !== subract(x, y)), | ||
) | ||
}) | ||
``` |
147024
3648
7
10
57
+ Addednewtype-ts@^0.3.5