0.8.0 • Published 2 years ago

fp-ts-quickcheck v0.8.0

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

fp-ts-test

fp-ts port of Haskell's QuickCheck.

NOTE Please note that shrinking is not yet available. Purescript did the same, so this should be enough to get you started. When shrinking is available, it will be transparently added as major release.

Features

  • Purely functional implementation.
  • Compatible - Easily integrates into existing testing frameworks.
  • Polymorphic - Create custom assert functions using fp-ts typeclass instances.
  • Extensible - Simply add compatibilty assertions for data structures

Installation

yarn add -D fp-ts-test

Quick Start

Grab your favourite test library, in this case jest, and put the assertion call of this library into the test caller.

// main.ts
export function subtract(x: number, y: number) {
  return x - y
}

// main.spec.ts
import { quickcheck as qc, arbitrary as AT } from "fp-ts-test"
import { expect, it, describe } from "@jest/globals"

import { pipe } from "fp-ts/function"

import { subtract } from "./main"

describe(subtract, () => {
  const numnum = AT.tuple(AT.number, AT.number)

  it(
    "should always be smaller than the first argument",
    // returns a thunk by default, because `qc.assert` throws
    qc.assertIO(numnum, ([x, y]) => x > subract(x, y)),
  )

  it(
    "should matter which order the arguments are passed",
    // returns a thunk by default, because `qc.assert` throws
    qc.assertIO(numnum, ([x, y]) => subtract(y, x) !== subract(x, y)),
  )
})
0.8.0

2 years ago

0.7.0

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.5.0

2 years ago

0.3.2

2 years ago

0.4.0

2 years ago

0.3.1

2 years ago

0.6.0

2 years ago

0.1.0

2 years ago