Description

Library for generating random data sets and automated checking of test constraints

Package Information

Version0.1.0 (2014-Mar-27)
Repositoryhttps://github.com/NCrashed/DCheck
LicenseMIT
CopyrightCopyright © 2014, ncrashed
Authorsncrashed
Registered byAnton Gushcha
Dependenciesnone

Installation

To use this package, put the following dependency into your project's dependencies section:

dub.json
dub.sdl

Readme

DCheck

Build Status

Library for generating random data sets and automated checking of test constraints. The library design is inspired by Haskell one - QuickCheck. User define Arbitrary template (behaves like typeclass in haskell) for a type to add random generating feature and result shrinking. Then the library can pass random sets of data into special functions called constraints and provide you fancy formatted minimal fail case.

Usage

First, consider simple example:

unittest
{
  checkConstraint!((int a, int b) => a + b == b + a);
}

As the provided delegate is always true unittest passes clearly.

Negative result example:

unittest
{
  import std.math;
  checkConstraint!((int a, int b) => abs(a) < 100 && abs(b) < 100)
}

DCheck will find the fail case:

==============================
Constraint __lambda2 is failed!
Calls count: 1. Shrinks count: 24
Parameters: 
        0: int ""  = -61
        1: int ""  = -30

Result shrinking is performed to provide you concise fail case.

DCheck can detect parameter names for regular functions:

bool foo(bool a, bool b)
{
  return a && !b;
}

unittest
{
  checkConstraint!foo;
}

Output:

core.exception.AssertError: 
==============================
Constraint foo is failed!
Calls count: 1. Shrinks count: 0
Parameters: 
	0: bool "a"  = true
	1: bool "b"  = true

Building

To use DCheck as dependency in your project add the following in your dub.json file:

"dependencies": {
  "dcheck": ">=0.1.0"
}

To run unittests, clone the repo and run:

dub test

Available versions

0.1.0 ~master