Ir a la documentación de este archivo.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "BUnit.h"
00011 #include "rational.h"
00012
00013 USING_namespace(ADH);
00014
00015
00016
00017
00018
00019 class rational_TestFixture : public TestCase {
00020 protected:
00021 rational m_half, m_quarter, m_one;
00022 public:
00023 virtual void setUp();
00024 };
00025
00026 void rational_TestFixture::setUp() {
00027 m_half.set(1,2);
00028 m_quarter.set(1,4);
00029 m_one.set(1);
00030 }
00031
00032 class rational_Test_Add : public rational_TestFixture {
00033 public:
00034 bool run();
00035 };
00036
00037
00038
00039 bool rational_Test_Add::run() {
00040 assertTrue( m_half+m_quarter == rational(30,40) );
00041 assertTrue( rational(30,40) == m_quarter+m_half );
00042
00043 assertTrue( m_one+m_quarter == rational(125,100) );
00044 assertTrue( rational(125,100) == m_quarter+m_one );
00045
00046 assertTrue( rational(1,3) == rational(33,100) );
00047
00048
00049 m_half = m_quarter = m_one = 0;
00050 return wasSuccessful();
00051 }
00052
00053
00054 class rational_Test_Substract : public rational_TestFixture {
00055 public:
00056 bool run();
00057 };
00058
00059
00060
00061 bool rational_Test_Substract::run() {
00062 assertTrue( m_half-m_quarter == rational(10,40) );
00063 assertTrue( rational(10,40) == -m_quarter+m_half );
00064
00065 assertTrue( m_one-m_quarter == rational(75,100) );
00066 assertTrue( rational(-75,100) == m_quarter-m_one );
00067
00068 assertEquals( rational(75,100) , m_quarter-m_one );
00069 assertTrue( rational(75,100) == m_one+m_quarter );
00070
00071
00072 m_half = m_quarter = m_one = 0;
00073 return wasSuccessful();
00074 }
00075
00076 USING_namespace(std);
00077
00078
00079 int main() {
00080 rational_Test_Add tester_Add;
00081
00082 cout << endl << endl << "1) Prueba directa con \"TestFixture\"" << endl;
00083 tester_Add.setUp();
00084 tester_Add.run();
00085 cout << tester_Add.report();
00086
00087 rational_Test_Substract tester_Substract;
00088 cout << endl << endl << "2) Prueba directa con \"TestFixture\"" << endl;
00089 tester_Substract.setUp();
00090 tester_Substract.run();
00091 cout << tester_Substract.report();
00092
00093 return 0;
00094 }
00095
00096