Why Base_quickcheck?

Automatic property-based testing

Base_quickcheck provides simple tools for writing down invariants and testing that they hold for randomly-generated inputs.

Base compatibility

The library comes with random distributions for types provided by Base, including Int63.t, Set.t, and Map.t. Its interfaces follow Base idioms such as sexp serialization and parameterization via first-class modules.

Customized distributions

Use the [@@deriving quickcheck] syntax to automatically construct a random distribution for new types, or use the Generator module to build custom distributions of existing types.

Minimized test cases

Base_quickcheck supports, and automatically derives, Shrinker.t values that reduce failing inputs to a minimal value. This can help debug complex failures by eliminating “red herrings”.

open Base
open Base_quickcheck

type complex =
  { real : float; imaginary : float }
[@@deriving compare, quickcheck, sexp]

let add x y =
  { real      = x.real      +. y.real
  ; imaginary = x.imaginary +. y.imaginary
  }

let%expect_test "commutativity" =
  Test.run_exn
    (module struct
      type t = complex * complex
      [@@deriving quickcheck, sexp]
    end)
    ~f:(fun (x, y) ->
      [%test_eq: complex]
        (add x y)
        (add y x))

Getting Started

Installation

$ opam install base_quickcheck

See here for Base_quickcheck’s opam package file.

Usage

open Base
open Base_quickcheck

...

Documentation

More docs, including detailed API docs, are available here.

Documentation for the wrapper of Base_quickcheck exported as Core.Quickcheck can be found here.

Learn More