QuickCheck++  0.0.3
Automated testing library
Classes | Enumerations | Functions
quickcheck Namespace Reference

All classes, data generators and printers exported by QuickCheck++ are in the quickcheck namespace. More...

Classes

class  PropertyBase
 Generic property. More...
class  Property
 5-argument property. More...
class  Property< A, B, C, D >
 4-argument property. More...
class  Property< A, B, C >
 3-argument property. More...
class  Property< A, B >
 2-argument property. More...
class  Property< A >
 1-argument property. More...

Enumerations

enum  Unit { UNIT }
 A dummy type to help simulating variadic templates. More...

Functions

template<class A >
generateInRange (A low, A high)
 Generates a value in a range.
template<class A , class Iter >
oneOf (Iter first, Iter last)
 Chooses randomly an element out of a sequence.
template<class A >
generateInteger (size_t n)
 Generates randomly an integer value.
static void generate (size_t, bool &out)
 Generates a boolean value randomly.
static void generate (size_t n, char &out)
 Generates a character at random.
static void generate (size_t n, unsigned char &out)
 Generates a character at random.
static void generate (size_t n, short &out)
 Generates a short integer in range [-n, n].
static void generate (size_t n, unsigned short &out)
 Generates an unsigned short integer in range [0, n].
static void generate (size_t n, int &out)
 Generates an integer in range [-n, n].
static void generate (size_t n, unsigned int &out)
 Generates an unsigned integer in range [0, n].
static void generate (size_t n, long &out)
 Generates a long integer in range [-n, n].
static void generate (size_t n, unsigned long &out)
 Generates an unsigned long integer in range [0, n].
static void generate (size_t n, float &out)
 Generates a single-precision floating point value in range [-n, n].
static void generate (size_t n, double &out)
 Generates a double-precision floating point value in range [-n, n].
static void generate (size_t n, long double &out)
 Generates a long double floating point value in range [-n, n].
template<class A >
void generate (size_t n, std::vector< A > &out)
 Generates a vector of 0 to n randomly-generated values of type A.
template<class A >
std::ostream & operator<< (std::ostream &out, const std::vector< A > &xs)
 Insertion operator for vectors.
template<class A >
void printArgument (std::ostream &out, size_t n, const A &a)
 Prints an argument.
template<>
void printArgument (std::ostream &, size_t, const Unit &)
 Specialisation of printArgument for Unit.
template<class Prop >
bool check (const char *msg, size_t n=100, size_t max=0, bool isVerbose=false, std::ostream &out=std::cout)
 Creates and verifies a property.

Detailed Description

All classes, data generators and printers exported by QuickCheck++ are in the quickcheck namespace.

Todo:
tools to build test suites

Enumeration Type Documentation

A dummy type to help simulating variadic templates.

The name comes from type theory (Unit is a type containing a single element, generally also called unit, and often denoted by ()).

Enumerator:
UNIT 

Function Documentation

template<class Prop >
bool quickcheck::check ( const char *  msg,
size_t  n = 100,
size_t  max = 0,
bool  isVerbose = false,
std::ostream &  out = std::cout 
)

Creates and verifies a property.

Prints "Checking that\c msg..." and then instantiate and verifies the property Prop.

Template Parameters
Propthe property type
Parameters
msgthe message identifying the property
nthe number of random tests to run
maxthe maximum number of attempts to generate valid input (defaults to 5 * n if lower than n)
isVerbosetrue if input should be printed before each test
outthe output stream to use
Returns
true if verification succeeded and false otherwise
static void quickcheck::generate ( size_t  ,
bool &  out 
)
inlinestatic

Generates a boolean value randomly.

The size hint is ignored.

Parameters
outthe reference to be set to true or false at random
static void quickcheck::generate ( size_t  n,
char &  out 
)
inlinestatic

Generates a character at random.

For low values of n, the character is alphanumeric. For intermediate values, it is ASCII and printable. For high values of n, the generated character can have any value in its range, even if it means it is not ASCII and/or not printable.

Warning
the zero character may be generated by this generator (n > 94)
the zero character is not generated very often by this generator (and only for n > 94)
Parameters
nthe size hint, influences the basicness of generated character
outthe reference to be set to the generated character
static void quickcheck::generate ( size_t  n,
unsigned char &  out 
)
inlinestatic

Generates a character at random.

For low values of n, the character is alphanumeric. For intermediate values, it is ASCII and printable. For high values of n, the generated character can have any value in its range, even if it means it is not ASCII and/or not printable.

Warning
the zero character may be generated by this generator (n > 94)
the zero character is not generated very often by this generator (and only for n > 94)
Parameters
nthe size hint, influences the basicness of generated character
outthe reference to be set to the generated character

static void quickcheck::generate ( size_t  n,
short &  out 
)
inlinestatic

Generates a short integer in range [-n, n].

Parameters
nthe size hint
outthe reference to be set to the generated value
static void quickcheck::generate ( size_t  n,
unsigned short &  out 
)
inlinestatic

Generates an unsigned short integer in range [0, n].

Parameters
nthe size hint
outthe reference to be set to the generated value
static void quickcheck::generate ( size_t  n,
int &  out 
)
inlinestatic

Generates an integer in range [-n, n].

Parameters
nthe size hint
outthe reference to be set to the generated value
static void quickcheck::generate ( size_t  n,
unsigned int &  out 
)
inlinestatic

Generates an unsigned integer in range [0, n].

Parameters
nthe size hint
outthe reference to be set to the generated value
static void quickcheck::generate ( size_t  n,
long &  out 
)
inlinestatic

Generates a long integer in range [-n, n].

Parameters
nthe size hint
outthe reference to be set to the generated value
static void quickcheck::generate ( size_t  n,
unsigned long &  out 
)
inlinestatic

Generates an unsigned long integer in range [0, n].

Parameters
nthe size hint
outthe reference to be set to the generated value
static void quickcheck::generate ( size_t  n,
float &  out 
)
inlinestatic

Generates a single-precision floating point value in range [-n, n].

Parameters
nthe size hint
outthe reference to be set to the generated value
static void quickcheck::generate ( size_t  n,
double &  out 
)
inlinestatic

Generates a double-precision floating point value in range [-n, n].

Parameters
nthe size hint
outthe reference to be set to the generated value
static void quickcheck::generate ( size_t  n,
long double &  out 
)
inlinestatic

Generates a long double floating point value in range [-n, n].

Parameters
nthe size hint
outthe reference to be set to the generated value
template<class A >
void quickcheck::generate ( size_t  n,
std::vector< A > &  out 
)

Generates a vector of 0 to n randomly-generated values of type A.

Template Parameters
Athe element type
Parameters
nthe size hint
outthe reference to be set to the generated value
template<class A >
A quickcheck::generateInRange ( low,
high 
)

Generates a value in a range.

Template Parameters
Athe value type (must be numeric)
Parameters
lowthe lower bound (inclusive)
highthe higher bound (inclusive)
Returns
a value between low and high (both inclusive).
template<class A >
A quickcheck::generateInteger ( size_t  n)

Generates randomly an integer value.

The value is taken in interval [0, n] for unsigned values and in interval [-n, n] for signed values. These intervals are of course clipped to the minimum and maximum values admissible for the returned type.

Template Parameters
Athe return type
Parameters
nthe size hint
Returns
a random integer in the intersection of [-n, n] and the A's range
template<class A , class Iter >
A quickcheck::oneOf ( Iter  first,
Iter  last 
)

Chooses randomly an element out of a sequence.

Parameters
firstan iterator pointing to first element
lastan iterator pointing to after-last element
Returns
the chosen element
template<class A >
std::ostream& quickcheck::operator<< ( std::ostream &  out,
const std::vector< A > &  xs 
)

Insertion operator for vectors.

Parameters
outthe output stream to be printed on
xsthe vector to print
Returns
the output stream after printing
template<class A >
void quickcheck::printArgument ( std::ostream &  out,
size_t  n,
const A &  a 
)

Prints an argument.

This template is used internally in PropertyBase to print input in case of failure or when verbose checking is requested.

Template Parameters
Athe argument type
Parameters
outthe output stream to use
nthe argument number
athe argument
template<>
void quickcheck::printArgument ( std::ostream &  ,
size_t  ,
const Unit &   
)

Specialisation of printArgument for Unit.

Prints nothing.