[B]asic module for [unit] program testing:
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Defines
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Friends
test_rational< INT > Class Template Reference

Prueba la clase rational<INT>. More...

Inheritance diagram for test_rational< INT >:
TestCase

List of all members.

Public Member Functions

virtual void setUp ()
 Establece el ambiente de prueba.
void super_numerotes (bool sl=false)
 Define si se corren o no las pruebas con super-numerotototes.
void super_lerdo (bool sl=false)
 Define si se corren las pruebas que duran mucho.
bool run ()
 Método principal de la prueba.
void rat_tst ()
 Antiguo programa de prueba para la clase rational<INT>.
void run_rest ()
 Método complementario de prueba.
void test_quiebra_Narvaja ()
 Datos de prueba que sirven para quebrar la implementación BigNum de Narvaja.
void test_constructor ()
 Datos de prueba para los constructores de la clase rational<INT>.
void test_destructor ()
 Datos de prueba para el destructor de la clase rational<INT>.
void test_set ()
 Datos de prueba para rational<INT>::set().
void test_op_equal ()
 Datos de prueba para rational<INT>::operator=().
void test_num_den ()
 Datos de prueba para rational<INT>::num() y rational<INT>::den().
void test_swap ()
 Datos de prueba para rational<INT>::swap().
void test_op_add_equal ()
 Datos de prueba para rational<INT>::operator +=() y rational<INT>::operator -=() .
void test_op_add ()
 Datos de prueba para rational<INT>::operator +() y rational<INT>::operator -() .
void test_op_mult_equal ()
 Datos de prueba para rational<INT>::operator *=() y rational<INT>::operator /=().
void test_op_mult ()
 Datos de prueba para rational<INT>::operator *() y rational<INT>::operator /().
void test_op_minus ()
 Datos de prueba para rational<INT>::operator -().
void test_fromString ()
 Datos de prueba para rational<INT>::test_fromString().
void test_op_comp ()
 Datos de prueba para todos los operadores de comparación de rational<INT>.
void test_op_in ()
 Datos de prueba para operator>>().
void test_op_out ()
 Datos de prueba para operator<<().
void test_simplify ()
 Datos de prueba para rational<INT>::test_simplify().
void test_check_ok ()
 Datos de prueba para check_ok( const rational<INT>& ).
void test_mcd ()
 Datos de prueba para la función mcd().
void test_op_cpp ()
 Datos de prueba para los incrementadores c++ y --c.
void runBare ()
 Excecutes the test run setUp(); run(); tearDown();.
bool Run ()
 Synonym for run().
bool runTest ()
 Synonym for run().
virtual void tearDown ()
 Destroys the test environment.
int countTestCases () const
 1 == Number of test cases.
int runCount () const
 Number of test runs.
virtual int failureCount () const
 Number of test runs that failed.
int errorCount () const
 Always returns 0 (cero): "Number of errors".
virtual int successCount () const
 Number of successful test runs.
bool wasSuccessful () const
 Returns "true" when all test runs where successful.
virtual void reset ()
 Discards all test runs.
std::string getName () const
 Gets the test case name.
void setName (const char *name=0)
 Sets the test case name to "name".
virtual const std::string toString () const
 Huuuge string that holds a copy of non successfull test, separated by "\n".
virtual const std::string summary () const
 Returns a string with the name, number of successes and failures.
virtual const std::string toXML () const
 XML string that holds a copy of all unsuccessful tests.
const std::string report () const
 Returns string summary() followed by toString().
const std::string failureString () const
 Synonym for toString().

Static Public Member Functions

template<class T >
static std::string toString (const T &val)
 Returns a std::string constructed form value val.

Protected Member Functions

void recordSuccess ()
 Records the test run as a success.
void recordFailure (const char *label, const char *fname, int lineno, bool must_copy=false)
 Records that the test run did not succeed.
void recordFailure (const std::string &label, const char *fname, int lineno)
 Records that the test did not succeed.
void testThis (bool cond, const char *label, const char *fname, long lineno, bool must_copy=false)
 Executes the test and records its result.
void testThis (bool cond, const std::string &label, const char *fname, long lineno)
 Synonym for testThis().
int nPass () const
 Synonym for successCount() [OBSOLETE].
int nError () const
 Synonym for failureCount() [OBSOLETE].

Protected Attributes

rational< INT > m_half
rational< INT > m_quarter
rational< INT > m_one
rational< INT > m_half_neg
rational< INT > m_quarter_neg
rational< INT > m_one_neg
rational< INT > m_sep
rational< INT > m_sep_neg
bool m_super_lerdo
 Indica si hay que probar con numerotototes.
bool m_super_numerotes
 Indica si se corren las pruebas que duran mucho.
int m_pass
 Number of successful tests.
int m_failure
 Number of test that produced failed.
const char * m_name
 Test case name.
bool m_test_suite_destroy
 Holds "true" if the test case is stored in dynamic memory.
std::list< TestCaseFailurem_failureList
 Container where test cases that produced failures are stored.

Friends

class TestSuite
 Colección de pruebas.
template<class TestCase >
void do_toXML (const TestCase *tc, std::basic_ostringstream< char > &ost)
 Adds to ost the string of al unsuccessful test from *tc in XML format.
template<class TestCase >
void do_toString (const TestCase *tc, std::basic_ostringstream< char > &ost)
 Adds to ost the string of al unsuccessful test from *tc.

Detailed Description

template<class INT>
class test_rational< INT >

Prueba la clase rational<INT>.

Definition at line 33 of file test_rational.cpp.


Member Function Documentation

template<class INT >
void test_rational< INT >::setUp ( ) [virtual]

Establece el ambiente de prueba.

Reimplemented from TestCase.

Definition at line 108 of file test_rational.cpp.

template<class INT>
void test_rational< INT >::super_numerotes ( bool  sl = false) [inline]

Define si se corren o no las pruebas con super-numerotototes.

Definition at line 43 of file test_rational.cpp.

template<class INT>
void test_rational< INT >::super_lerdo ( bool  sl = false) [inline]

Define si se corren las pruebas que duran mucho.

Definition at line 47 of file test_rational.cpp.

template<class INT >
bool test_rational< INT >::run ( ) [virtual]

Método principal de la prueba.

  • Requiere que recién haya sido ejecutado setUp()

Implements TestCase.

Definition at line 81 of file test_rational.cpp.

template<class INT >
void test_rational< INT >::rat_tst ( )

Antiguo programa de prueba para la clase rational<INT>.

Definition at line 458 of file test_rational.cpp.

template<class INT >
void test_rational< INT >::run_rest ( )

Método complementario de prueba.

Definition at line 575 of file test_rational.cpp.

template<class INT >
void test_rational< INT >::test_quiebra_Narvaja ( )

Datos de prueba que sirven para quebrar la implementación BigNum de Narvaja.

Definition at line 131 of file test_rational.cpp.

template<class INT >
void test_rational< INT >::test_constructor ( )

Datos de prueba para los constructores de la clase rational<INT>.

Definition at line 166 of file test_rational.cpp.

template<class INT >
void test_rational< INT >::test_destructor ( )

Datos de prueba para el destructor de la clase rational<INT>.

Definition at line 181 of file test_rational.cpp.

template<class INT >
void test_rational< INT >::test_set ( )

Datos de prueba para rational<INT>::set().

Definition at line 187 of file test_rational.cpp.

template<class INT >
void test_rational< INT >::test_op_equal ( )

Datos de prueba para rational<INT>::operator=().

Definition at line 213 of file test_rational.cpp.

template<class INT >
void test_rational< INT >::test_num_den ( )

Datos de prueba para rational<INT>::num() y rational<INT>::den().

Definition at line 200 of file test_rational.cpp.

template<class INT >
void test_rational< INT >::test_swap ( )

Datos de prueba para rational<INT>::swap().

Definition at line 226 of file test_rational.cpp.

template<class INT >
void test_rational< INT >::test_op_add_equal ( )

Datos de prueba para rational<INT>::operator +=() y rational<INT>::operator -=() .

Definition at line 238 of file test_rational.cpp.

template<class INT >
void test_rational< INT >::test_op_add ( )

Datos de prueba para rational<INT>::operator +() y rational<INT>::operator -() .

Definition at line 253 of file test_rational.cpp.

template<class INT >
void test_rational< INT >::test_op_mult_equal ( )

Datos de prueba para rational<INT>::operator *=() y rational<INT>::operator /=().

Definition at line 268 of file test_rational.cpp.

template<class INT >
void test_rational< INT >::test_op_mult ( )

Datos de prueba para rational<INT>::operator *() y rational<INT>::operator /().

Definition at line 283 of file test_rational.cpp.

template<class INT >
void test_rational< INT >::test_op_minus ( )

Datos de prueba para rational<INT>::operator -().

Definition at line 298 of file test_rational.cpp.

template<class INT >
void test_rational< INT >::test_fromString ( )

Datos de prueba para rational<INT>::test_fromString().

Definition at line 311 of file test_rational.cpp.

template<class INT >
void test_rational< INT >::test_op_comp ( )

Datos de prueba para todos los operadores de comparación de rational<INT>.

Definition at line 355 of file test_rational.cpp.

template<class INT >
void test_rational< INT >::test_op_in ( )

Datos de prueba para operator>>().

Definition at line 393 of file test_rational.cpp.

template<class INT >
void test_rational< INT >::test_op_out ( )

Datos de prueba para operator<<().

Definition at line 371 of file test_rational.cpp.

template<class INT >
void test_rational< INT >::test_simplify ( )

Datos de prueba para rational<INT>::test_simplify().

Definition at line 325 of file test_rational.cpp.

template<class INT >
void test_rational< INT >::test_check_ok ( )

Datos de prueba para check_ok( const rational<INT>& ).

Definition at line 340 of file test_rational.cpp.

template<class INT >
void test_rational< INT >::test_mcd ( )

Datos de prueba para la función mcd().

Definition at line 409 of file test_rational.cpp.

template<class INT >
void test_rational< INT >::test_op_cpp ( )

Datos de prueba para los incrementadores c++ y --c.

Definition at line 421 of file test_rational.cpp.

void TestCase::runBare ( ) [inline, inherited]

Excecutes the test run setUp(); run(); tearDown();.

Reimplemented in TestSuite< TestCase >.

Definition at line 777 of file BUnit.h.

bool TestCase::Run ( ) [inline, inherited]

Synonym for run().

Definition at line 123 of file BUnit.h.

bool TestCase::runTest ( ) [inline, inherited]

Synonym for run().

Definition at line 124 of file BUnit.h.

void TestCase::tearDown ( ) [inline, virtual, inherited]

Destroys the test environment.

Definition at line 839 of file BUnit.h.

int TestCase::countTestCases ( ) const [inline, inherited]

1 == Number of test cases.

The value returned always is one 1 because class TestCase represents a single test case. For the container TestSuite<> the value returned can be bigger than 1.

  • A "test case" is a class, derived from class TestCase.
  • A "test run" gets counted when either a specific test succeeds or fails.
  • A "test run" gets counted when protected method TestCase::testThis() is executed, either directly or through any BUnit "assert()" macro, as assertTrue(), fail_Msg(), assertEquals_Delta(), or others like BUnit_SUCCESS() or BUnit_TEST().
  • A "test case" ussually has many "test runs". A collection of "test cases" resided within an instance derived from class TestSuite<>.

Reimplemented in TestSuite< TestCase >.

Definition at line 127 of file BUnit.h.

int TestCase::runCount ( ) const [inline, inherited]

Number of test runs.

Definition at line 129 of file BUnit.h.

int TestCase::failureCount ( ) const [inline, virtual, inherited]

Number of test runs that failed.

See also:
reset().

Reimplemented in TestSuite< TestCase >.

Definition at line 130 of file BUnit.h.

int TestCase::errorCount ( ) const [inline, inherited]

Always returns 0 (cero): "Number of errors".

Definition at line 131 of file BUnit.h.

int TestCase::successCount ( ) const [inline, virtual, inherited]

Number of successful test runs.

See also:
reset().

Reimplemented in TestSuite< TestCase >.

Definition at line 132 of file BUnit.h.

bool TestCase::wasSuccessful ( ) const [inline, inherited]

Returns "true" when all test runs where successful.

Definition at line 134 of file BUnit.h.

void TestCase::reset ( ) [inline, virtual, inherited]

Discards all test runs.

  • Resets to cero al counters because the test case is left in the state it had when initially contructed.
  • Deletes the record for not successful tests.
  • Does not change the test case name.
        {{  // test::reset()
            class MyTest : public TestCase {
            public:
                bool run() {
                    assertTrue( 1 == 2 ); // Failure !!!
                    assertTrue( 1 == 1 ); // Ok
                    assertTrue( 2 == 2 ); // Ok
                    return wasSuccessful();
                }
            }; // MyTest
            MyTest thisTest;
            for ( int i=0; i<11; ++i ) {
                thisTest.run(); // runs the same test 11 times
            }
            assertTrue( 11 == thisTest.failureCount() );   // ( 1 == 2 ) x 11
            assertTrue( 22 == thisTest.successCount() ); // ( 1 == 1 ) && ( 2 == 2 )
            assertTrue( 33 == thisTest.runCount() );     // 33 == 11+22
            assertTrue( "" != thisTest.failureString() );  // 11 recorded failures
            std::string remember = thisTest.getName();
    
            thisTest.reset(); // Anula los contadores
    
            assertTrue( 0 == thisTest.failureCount() );
            assertTrue( 0 == thisTest.successCount() );
            assertTrue( 0 == thisTest.runCount() );
            assertTrue( "" == thisTest.failureString() );
            assertTrue( remember == thisTest.getName() ); // reset() won´t change the name
        }}
    
    See also:
    test_BUnit::test_reset()

Reimplemented in TestSuite< TestCase >.

Definition at line 726 of file BUnit.h.

std::string TestCase::getName ( ) const [inline, inherited]

Gets the test case name.

See also:
setName().

Definition at line 731 of file BUnit.h.

void TestCase::setName ( const char *  name = 0) [inline, inherited]

Sets the test case name to "name".

  • When "name" is a null string or pointer, later typeid(*this).name() will be invoked to get the test´s name.
        {{  // test::setName()
            class MyTest : public TestCase {
            public:
                bool run() {
                    assertTrue( 2 == 2 );
                    return wasSuccessful();
                }
            }; // MyTest
            MyTest thisTest;
            assertTrue(       "chorlito" != thisTest.getName() );
            thisTest.setName( "chorlito" );
            assertTrue(       "chorlito" == thisTest.getName() );
            {
            //  thisTest.setName( std::string("chorlito") ); // won´t compile
                thisTest.setName( std::string("chorlito").c_str() ); // bad practice
                std::string V("boom!");
                assertTrue( 0==strcmp( V.c_str() , "boom!") );
                assertTrue( "chorlito" != thisTest.getName() ); // c_str() uses
                assertTrue( "boom!"    == thisTest.getName() ); // static data
            }
        }}
    
    See also:
    test_BUnit::test_setName()

Definition at line 754 of file BUnit.h.

const std::string TestCase::toString ( ) const [inline, virtual, inherited]

Huuuge string that holds a copy of non successfull test, separated by "\n".

    =_fail: 1 == 0
    =/ (125) X:/DIR/SubDir/test_BUnit.cpp
    =_fail: 4 == 0
    =/ (128) X:/DIR/SubDir/test_BUnit.cpp

Reimplemented in TestSuite< TestCase >.

Definition at line 1036 of file BUnit.h.

template<class T >
std::string TestCase::toString ( const T &  val) [static, inherited]

Returns a std::string constructed form value val.

Definition at line 1895 of file BUnit.h.

const std::string TestCase::summary ( ) const [inline, virtual, inherited]

Returns a string with the name, number of successes and failures.

Reimplemented in TestSuite< TestCase >.

Definition at line 1252 of file BUnit.h.

const std::string TestCase::toXML ( ) const [inline, virtual, inherited]

XML string that holds a copy of all unsuccessful tests.

    <fail file="X:/DIR/SubDir/test_BUnit.cpp" line="125" message="1 == 0"/>
    <fail file="X:/DIR/SubDir/test_BUnit.cpp" line="128" message="4 == 0"/>

Reimplemented in TestSuite< TestCase >.

Definition at line 1083 of file BUnit.h.

const std::string TestCase::report ( ) const [inline, inherited]

Returns string summary() followed by toString().

Definition at line 142 of file BUnit.h.

const std::string TestCase::failureString ( ) const [inline, inherited]

Synonym for toString().

Definition at line 143 of file BUnit.h.

void TestCase::recordSuccess ( ) [inline, protected, inherited]

Records the test run as a success.

Definition at line 146 of file BUnit.h.

void TestCase::recordFailure ( const char *  label,
const char *  fname,
int  lineno,
bool  must_copy = false 
) [inline, protected, inherited]

Records that the test run did not succeed.

  • Values "fname" and "lineno" indicate the file and line where the test run is executed.
  • The values form "fname" and "lineno" are usuallly obtained invoking global macros "__FILE__" and "__LINE__".
  • "must_copy" forces a copy of string label to be created in dynamic memory. This dynamic memory will be destroyed when the test case gets destroyed or when method TestCase::reset() gets invoked.
  • Oftentimes string "label" is a constant string generated by the preprocessor macro using #cond; this string constant is not stored in dynamic memory and it must not be destroyed.

This method is invoked using macro BUnit_FAILURE().

Definition at line 945 of file BUnit.h.

void TestCase::recordFailure ( const std::string &  label,
const char *  fname,
int  lineno 
) [inline, protected, inherited]

Records that the test did not succeed.

  • En BUnit.h there is no difference between "failures" and "errors".

Definition at line 1004 of file BUnit.h.

void TestCase::testThis ( bool  cond,
const char *  label,
const char *  fname,
long  lineno,
bool  must_copy = false 
) [inline, protected, inherited]

Executes the test and records its result.

  • If the test is successful only increases the numbero of success successCount().
  • If the test is not successful reports in toString() this fact.
  • The result of the test is "cond".
  • Values "fname" and "lineno" show the file and line of the executed test.
  • Usuallyy "fname" and "lineno" are values obtained with global macros "__FILE__" and "__LINE__".
  • The value for "must_copy" indicates whether it is necessary to make a copy of string "label"; this copy will be destroyed when the record of not successful test is deleted.
  • Most of the time string "label" is a constant genertated by the preprocessor when using macro #cond its memory must not be returned. This method is invoked using macro BUnit_TEST().
        {{  // test::testThis()
            class MyTest : public TestCase {
            public:
                bool run() {
                    bool dont_copy = false;
                    testThis( 2 == 2, "2 is 2", __FILE__, __LINE__, dont_copy ); // Ok
                    testThis( 1 == 2, "1 is 2", __FILE__, __LINE__, dont_copy ); // failure #1
                    testThis( 2 == 1, "2 is 1", __FILE__, __LINE__, dont_copy ); // failure #2
                    return wasSuccessful();
                }
            }; // MyTest
            MyTest thisTest;
            assertTrue( thisTest.wasSuccessful() ); // run() has not been executed
            thisTest.run(); // 2 failures
            assertTrue( thisTest.failureCount() == 2 );
            assertTrue( ! thisTest.wasSuccessful() );
        }}
    
    See also:
    test_BUnit::test_testThis()

Definition at line 884 of file BUnit.h.

void TestCase::testThis ( bool  cond,
const std::string &  label,
const char *  fname,
long  lineno 
) [inline, protected, inherited]

Synonym for testThis().

Definition at line 901 of file BUnit.h.

int TestCase::nPass ( ) const [inline, protected, inherited]

Synonym for successCount() [OBSOLETE].

Deprecated:

Definition at line 162 of file BUnit.h.

int TestCase::nError ( ) const [inline, protected, inherited]

Synonym for failureCount() [OBSOLETE].

Deprecated:

Definition at line 163 of file BUnit.h.


Friends And Related Function Documentation

friend class TestSuite [friend, inherited]

Colección de pruebas.

Definition at line 161 of file BUnit.h.

template<class TestCase >
void do_toXML ( const TestCase tc,
std::basic_ostringstream< char > &  ost 
) [friend, inherited]

Adds to ost the string of al unsuccessful test from *tc in XML format.

Definition at line 1097 of file BUnit.h.

template<class TestCase >
void do_toString ( const TestCase tc,
std::basic_ostringstream< char > &  ost 
) [friend, inherited]

Adds to ost the string of al unsuccessful test from *tc.

Definition at line 1050 of file BUnit.h.


Member Data Documentation

template<class INT>
rational<INT> test_rational< INT >::m_half [protected]

Definition at line 35 of file test_rational.cpp.

template<class INT>
rational<INT> test_rational< INT >::m_quarter [protected]

Definition at line 35 of file test_rational.cpp.

template<class INT>
rational<INT> test_rational< INT >::m_one [protected]

Definition at line 35 of file test_rational.cpp.

template<class INT>
rational<INT> test_rational< INT >::m_half_neg [protected]

Definition at line 36 of file test_rational.cpp.

template<class INT>
rational<INT> test_rational< INT >::m_quarter_neg [protected]

Definition at line 36 of file test_rational.cpp.

template<class INT>
rational<INT> test_rational< INT >::m_one_neg [protected]

Definition at line 36 of file test_rational.cpp.

template<class INT>
rational<INT> test_rational< INT >::m_sep [protected]

Definition at line 37 of file test_rational.cpp.

template<class INT>
rational<INT> test_rational< INT >::m_sep_neg [protected]

Definition at line 37 of file test_rational.cpp.

template<class INT>
bool test_rational< INT >::m_super_lerdo [protected]

Indica si hay que probar con numerotototes.

Definition at line 38 of file test_rational.cpp.

template<class INT>
bool test_rational< INT >::m_super_numerotes [protected]

Indica si se corren las pruebas que duran mucho.

Definition at line 39 of file test_rational.cpp.

int TestCase::m_pass [protected, inherited]

Number of successful tests.

Definition at line 113 of file BUnit.h.

int TestCase::m_failure [protected, inherited]

Number of test that produced failed.

Definition at line 114 of file BUnit.h.

const char * TestCase::m_name [protected, inherited]

Test case name.

Definition at line 115 of file BUnit.h.

bool TestCase::m_test_suite_destroy [protected, inherited]

Holds "true" if the test case is stored in dynamic memory.

Definition at line 116 of file BUnit.h.

std::list< TestCaseFailure > TestCase::m_failureList [protected, inherited]

Container where test cases that produced failures are stored.

Definition at line 117 of file BUnit.h.


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