QuickCheck++  0.0.3
Automated testing library
Public Member Functions | Private Member Functions | List of all members
quickcheck::Property< A, B, C, D, E > Class Template Reference

5-argument property. More...

#include <Property.hh>

Inheritance diagram for quickcheck::Property< A, B, C, D, E >:
quickcheck::PropertyBase< A, B, C, D, E >

Public Member Functions

virtual void addFixed (const A &a, const B &b, const C &c, const D &d, const E &e)
 Adds a fixed test case for with the given arguments.
- Public Member Functions inherited from quickcheck::PropertyBase< A, B, C, D, E >
 PropertyBase ()
 Constructor.
virtual ~PropertyBase ()
 Destructor.
bool check (size_t n=100, size_t max=0, bool isVerbose=false, std::ostream &out=std::cout)
 Checks this property.

Private Member Functions

virtual bool accepts (const A &a, const B &b, const C &c, const D &d, const E &e)
 Tells whether or not this property should accept given arguments.
virtual const std::string classify (const A &a, const B &b, const C &c, const D &d, const E &e)
 Classifies input to allow observation of input distribution.
virtual void generateInput (size_t n, A &a, B &b, C &c, D &d, E &e)
 Generates input randomly.
virtual bool holdsFor (const A &a, const B &b, const C &c, const D &d, const E &e)=0
 Tells whether or not this property holds for the given input.
virtual bool isTrivialFor (const A &a, const B &b, const C &c, const D &d, const E &e)
 Tells whether or not the property is trivially true for the given input.
bool _accepts (const A &a, const B &b, const C &c, const D &d, const E &e)
const std::string _classify (const A &a, const B &b, const C &c, const D &d, const E &e)
void _generateInput (size_t n, A &a, B &b, C &c, D &d, E &e)
bool _holdsFor (const A &a, const B &b, const C &c, const D &d, const E &e)
bool _isTrivialFor (const A &a, const B &b, const C &c, const D &d, const E &e)

Additional Inherited Members

- Protected Member Functions inherited from quickcheck::PropertyBase< A, B, C, D, E >
void _addFixed (const A &a, const B &b, const C &c, const D &d, const E &e)
 Adds a fixed test case for with the given arguments.

Detailed Description

template<class A, class B = Unit, class C = Unit, class D = Unit, class E = Unit>
class quickcheck::Property< A, B, C, D, E >

5-argument property.

This class models a property (see PropertyBase) with 5-argument input. Default parameters serve the purpose of simulating variadic templates.

e.g. Property<A, B, C> (which is the same as Property<A, B, C, Unit, Unit>) is in fact a property of 3 arguments.

All templates arguments should have both a generator and an output stream operator.

Specialisation of this template class are provided for properties of 1, 2, 3 and 4 arguments.

Template Parameters
Atype of first argument
Btype of second argument (if Unit, then all later arguments should also be Unit and 1-argument property will be used instead)
Ctype of third argument (if Unit, then all later arguments should also be Unit and n-argument property ( n = 1 or 2) will be used instead)
Dtype of fourth argument (if Unit, then all later arguments should also be Unit and n-argument property ( n = 1, 2 or 3) will be used instead)
Etype of fourth argument (if Unit, then n-argument property (n = 1, 2, 3 or 4) will be used instead)

Member Function Documentation

template<class A , class B , class C , class D , class E >
bool quickcheck::Property< A, B, C, D, E >::_accepts ( const A &  a,
const B &  b,
const C &  c,
const D &  d,
const E &  e 
)
private
template<class A , class B , class C , class D , class E >
const std::string quickcheck::Property< A, B, C, D, E >::_classify ( const A &  a,
const B &  b,
const C &  c,
const D &  d,
const E &  e 
)
private
template<class A , class B , class C , class D , class E >
void quickcheck::Property< A, B, C, D, E >::_generateInput ( size_t  n,
A &  a,
B &  b,
C &  c,
D &  d,
E &  e 
)
private
template<class A , class B , class C , class D , class E >
bool quickcheck::Property< A, B, C, D, E >::_holdsFor ( const A &  a,
const B &  b,
const C &  c,
const D &  d,
const E &  e 
)
private
template<class A , class B , class C , class D , class E >
bool quickcheck::Property< A, B, C, D, E >::_isTrivialFor ( const A &  a,
const B &  b,
const C &  c,
const D &  d,
const E &  e 
)
private
template<class A , class B , class C , class D , class E >
bool quickcheck::Property< A, B, C, D, E >::accepts ( const A &  a,
const B &  b,
const C &  c,
const D &  d,
const E &  e 
)
privatevirtual

Tells whether or not this property should accept given arguments.

This predicate is used to filter generated input arguments to respect this property possible precondition.

Note that if too much inputs are rejected, the property may fail verification due to the impossibility to generate a sufficient number of valid inputs in the given number of attempts. If this occurs, you can augment the maximum number of allowed attempts when calling check or define a custom generator generateInput.

Also pay attention to the fact that filtering input arguments may lead to a biased distribution which is not representative of the set of valid inputs. You should inspect your input distribution with isTrivialFor or classify when using this predicate and you will often do better by defining a custom generator by re-implementing generateInput.

Parameters
athe first argument
bthe second argument
cthe third argument
dthe fourth argument
ethe fifth argument
Returns
true if arguments forms valid input and false otherwise
template<class A , class B , class C , class D , class E >
void quickcheck::Property< A, B, C, D, E >::addFixed ( const A &  a,
const B &  b,
const C &  c,
const D &  d,
const E &  e 
)
virtual

Adds a fixed test case for with the given arguments.

Parameters
athe first argument of the test case
bthe second argument of the test case
cthe third argument of the test case
dthe fourth argument of the test case
ethe fifth argument of the test case
template<class A , class B , class C , class D , class E >
const std::string quickcheck::Property< A, B, C, D, E >::classify ( const A &  a,
const B &  b,
const C &  c,
const D &  d,
const E &  e 
)
privatevirtual

Classifies input to allow observation of input distribution.

An input class is simply represented by a string which is used both as an input class identifier (i.e. same class string means same input class) and as output to the user. The empty string "" is used as a no-class tag and is not printed in input distribution.

Parameters
athe first argument
bthe second argument
cthe third argument
dthe fourth argument
ethe fifth argument
Returns
the input class associated to input or empty string "" if none
template<class A , class B , class C , class D , class E >
void quickcheck::Property< A, B, C, D, E >::generateInput ( size_t  n,
A &  a,
B &  b,
C &  c,
D &  d,
E &  e 
)
privatevirtual

Generates input randomly.

Override this method if you need a custom input generator.

All input arguments given here are out values, i.e. they can be assumed default or empty on entry and should be initialised to a sensible random value by this method.

The size of generated values should be somehow correlated to the size hint n. When calling generators recursively to build compound data structures, you should pass a lower size hint to compound member generators to avoid the construction of overly large (or even infinite) data structures.

The quickcheck namespace contains a lot of generators that can be used to build your owns.

Parameters
nthe size hint
athe first argument
bthe second argument
cthe third argument
dthe fourth argument
ethe fifth argument
template<class A , class B = Unit, class C = Unit, class D = Unit, class E = Unit>
virtual bool quickcheck::Property< A, B, C, D, E >::holdsFor ( const A &  a,
const B &  b,
const C &  c,
const D &  d,
const E &  e 
)
privatepure virtual

Tells whether or not this property holds for the given input.

This method is the core of the property which define what the property is all about. If the code under test is correct, it should return true for all valid inputs. If the code under test is not correct, it should return false for at least some valid input.

Parameters
athe first argument
bthe second argument
cthe third argument
dthe fourth argument
ethe fifth argument
Returns
true if the property holds for given input and false otherwise
template<class A , class B , class C , class D , class E >
bool quickcheck::Property< A, B, C, D, E >::isTrivialFor ( const A &  a,
const B &  b,
const C &  c,
const D &  d,
const E &  e 
)
privatevirtual

Tells whether or not the property is trivially true for the given input.

This predicate allows to ensure that a sufficient number of tests were interesting. It is a restricted form of input classification.

See Also
classify
Parameters
athe first argument
bthe second argument
cthe third argument
dthe fourth argument
ethe fifth argument
Returns
true if the property is trivial for given input and false otherwise

The documentation for this class was generated from the following file: