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

Generic property. More...

#include <Property.hh>

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

Classes

struct  Input
 Input type. More...

Public Member Functions

 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.

Protected Member Functions

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.

Private Member Functions

void printInput (std::ostream &out, const A &a, const B &b, const C &c, const D &d, const E &e)
 Prints the given input arguments on the given output stream.
virtual size_t sizeHint (size_t testNo)
 Converts the random test number into a size hint.
virtual bool _accepts (const A &a, const B &b, const C &c, const D &d, const E &e)=0
 Generic wrapper for Property::accepts.
virtual const std::string _classify (const A &a, const B &b, const C &c, const D &d, const E &e)=0
 Generic wrapper for Property::classify.
virtual void _generateInput (size_t n, A &a, B &b, C &c, D &d, E &e)=0
 Generic wrapper for Property::generateInput.
virtual bool _holdsFor (const A &a, const B &b, const C &c, const D &d, const E &e)=0
 Generic wrappper for Property::holdsFor.
virtual bool _isTrivialFor (const A &a, const B &b, const C &c, const D &d, const E &e)=0
 Generic wrapper for Property::isTrivialFor.

Private Attributes

std::vector< Input_fixedInputs
 A vector of fixed inputs that are tested in addition to randomly-generated inputs.

Detailed Description

template<class A, class B, class C, class D, class E>
class quickcheck::PropertyBase< A, B, C, D, E >

Generic property.

This class models a verifiable property about some code fragment. It is not meant to be used or derived from directly but rather serves as a base for the various n-argument classes Property. This is just an artefact due to the fact that C++ 98 does not support variadic templates. It can model up to 5-arguments properties.

Template Parameters
Afirst argument type
Bsecond argument type or Unit if less than two arguments
Cthird argument type or Unit if less than three arguments
Dfourth argument type or Unit if less than four arguments
Efifth argument type or Unit if less than five arguments

Constructor & Destructor Documentation

template<class A , class B , class C , class D , class E >
quickcheck::PropertyBase< A, B, C, D, E >::PropertyBase ( )
explicit

Constructor.

template<class A , class B , class C , class D , class E >
quickcheck::PropertyBase< A, B, C, D, E >::~PropertyBase ( )
virtual

Destructor.

Member Function Documentation

template<class A, class B, class C, class D, class E>
virtual bool quickcheck::PropertyBase< A, B, C, D, E >::_accepts ( const A &  a,
const B &  b,
const C &  c,
const D &  d,
const E &  e 
)
privatepure virtual

Generic wrapper for Property::accepts.

Parameters
athe first argument
bthe second argument or UNIT if less than two arguments
cthe third argument or UNIT if less than three arguments
dthe fourth argument or UNIT if less than four arguments
ethe fifth argument or UNIT if less than five arguments
Returns
true if arguments forms valid input and false otherwise
template<class A, class B, class C, class D, class E>
void quickcheck::PropertyBase< A, B, C, D, E >::_addFixed ( const A &  a,
const B &  b,
const C &  c,
const D &  d,
const E &  e 
)
protected

Adds a fixed test case for with the given arguments.

This function allows to ensure that some carefully chosen test cases will be checked in addition to the randomly-generated ones.

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>
virtual const std::string quickcheck::PropertyBase< A, B, C, D, E >::_classify ( const A &  a,
const B &  b,
const C &  c,
const D &  d,
const E &  e 
)
privatepure virtual

Generic wrapper for Property::classify.

Parameters
athe first argument
bthe second argument or UNIT if less than two arguments
cthe third argument or UNIT if less than three arguments
dthe fourth argument or UNIT if less than four arguments
ethe fifth argument or UNIT if less than five arguments
Returns
a string representing the input class
template<class A, class B, class C, class D, class E>
virtual void quickcheck::PropertyBase< A, B, C, D, E >::_generateInput ( size_t  n,
A &  a,
B &  b,
C &  c,
D &  d,
E &  e 
)
privatepure virtual

Generic wrapper for Property::generateInput.

Parameters
nthe size hint
athe first argument
bthe second argument or UNIT if less than two arguments
cthe third argument or UNIT if less than three arguments
dthe fourth argument or UNIT if less than four arguments
ethe fifth argument or UNIT if less than five arguments
template<class A, class B, class C, class D, class E>
virtual bool quickcheck::PropertyBase< A, B, C, D, E >::_holdsFor ( const A &  a,
const B &  b,
const C &  c,
const D &  d,
const E &  e 
)
privatepure virtual

Generic wrappper for Property::holdsFor.

Parameters
athe first argument
bthe second argument or UNIT if less than two arguments
cthe third argument or UNIT if less than three arguments
dthe fourth argument or UNIT if less than four arguments
ethe fifth argument or UNIT if less than five arguments
Returns
true if the property holds and false otherwise
template<class A, class B, class C, class D, class E>
virtual bool quickcheck::PropertyBase< A, B, C, D, E >::_isTrivialFor ( const A &  a,
const B &  b,
const C &  c,
const D &  d,
const E &  e 
)
privatepure virtual

Generic wrapper for Property::isTrivialFor.

Parameters
athe first argument
bthe second argument or UNIT if less than two arguments
cthe third argument or UNIT if less than three arguments
dthe fourth argument or UNIT if less than four arguments
ethe fifth argument or UNIT if less than five arguments
Returns
true if the property is trivial for given arguments and false otherwise
template<class A , class B , class C , class D , class E >
bool quickcheck::PropertyBase< A, B, C, D, E >::check ( size_t  n = 100,
size_t  max = 0,
bool  isVerbose = false,
std::ostream &  out = std::cout 
)

Checks this property.

This method will verify that this property holds for all the fixed inputs and for a number of randomly generated inputs. It prints messages about success or failure (and optionally process) on the given output stream.

Parameters
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 all tests succeeded and false if a test failed or if a sufficient number of tests could not be generated
template<class A, class B, class C, class D, class E>
void quickcheck::PropertyBase< A, B, C, D, E >::printInput ( std::ostream &  out,
const A &  a,
const B &  b,
const C &  c,
const D &  d,
const E &  e 
)
private

Prints the given input arguments on the given output stream.

Parameters
outthe output stream to use
athe first argument
bthe second argument or UNIT if less than two arguments
cthe third argument or UNIT if less than three arguments
dthe fourth argument or UNIT if less than four arguments
ethe fifth argument or UNIT if less than five arguments
template<class A , class B , class C , class D , class E >
size_t quickcheck::PropertyBase< A, B, C, D, E >::sizeHint ( size_t  testNo)
privatevirtual

Converts the random test number into a size hint.

Parameters
testNothe number of the current random test
Returns
a size hint for _generateInput

Member Data Documentation

template<class A, class B, class C, class D, class E>
std::vector<Input> quickcheck::PropertyBase< A, B, C, D, E >::_fixedInputs
private

A vector of fixed inputs that are tested in addition to randomly-generated inputs.


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