@ -38,29 +38,29 @@ class ratio_test
{
// check basic initialisation
ratio * ratio_a = new ratio ( ) ;
BOOST_RE T QUIRE( ratio_a - > numerator ( ) = = 0 ) ;
BOOST_RE T QUIRE( ratio_a - > denominator ( ) = = 1 ) ;
BOOST_RE QUIRE( ratio_a - > numerator ( ) = = 0 ) ;
BOOST_RE QUIRE( ratio_a - > denominator ( ) = = 1 ) ;
// a denominator with value 0 is never allowed
ratio * ratio_b = new ratio ( 2 , 0 ) ;
BOOST_RE T QUIRE( ratio_b - > numerator ( ) = = 2 ) ;
BOOST_RE T QUIRE( ratio_b - > denominator ( ) = = 1 ) ; // division by zero not allowed
BOOST_RE QUIRE( ratio_b - > numerator ( ) = = 2 ) ;
BOOST_RE QUIRE( ratio_b - > denominator ( ) = = 1 ) ; // division by zero not allowed
// a new ratio should always be reduced
ratio * ratio_c = new ratio ( 2 , 4 ) ;
BOOST_RE T QUIRE( ratio_c - > numerator ( ) = = 1 ) ;
BOOST_RE T QUIRE( ratio_c - > denominator ( ) = = 2 ) ;
BOOST_RE QUIRE( ratio_c - > numerator ( ) = = 1 ) ;
BOOST_RE QUIRE( ratio_c - > denominator ( ) = = 2 ) ;
// check copy constructor
ratio * ratio_d = new ratio ( * ratio_c ) ;
BOOST_RE T QUIRE( ratio_d - > numerator ( ) = = 1 ) ;
BOOST_RE T QUIRE( ratio_d - > denominator ( ) = = 2 ) ;
BOOST_RE QUIRE( ratio_d - > numerator ( ) = = 1 ) ;
BOOST_RE QUIRE( ratio_d - > denominator ( ) = = 2 ) ;
// the copy constructor is not allowed to reduce the new ratio
ratio_d - > setNumerator ( 4 , false ) ;
ratio * ratio_e = new ratio ( * ratio_d ) ;
BOOST_RE T QUIRE( ratio_e - > numerator ( ) = = 4 ) ;
BOOST_RE T QUIRE( ratio_e - > denominator ( ) = = 2 ) ;
BOOST_RE QUIRE( ratio_e - > numerator ( ) = = 4 ) ;
BOOST_RE QUIRE( ratio_e - > denominator ( ) = = 2 ) ;
delete ( ratio_a ) ;
delete ( ratio_b ) ;
@ -77,33 +77,33 @@ class ratio_test
// check setNumerator() and numerator() (get)
ratio * ratio_a = new ratio ( ) ;
ratio_a - > setNumerator ( 10 ) ;
BOOST_RE T QUIRE( ratio_a - > numerator ( ) = = 10 ) ;
BOOST_RE T QUIRE( ratio_a - > denominator ( ) = = 1 ) ;
BOOST_RE QUIRE( ratio_a - > numerator ( ) = = 10 ) ;
BOOST_RE QUIRE( ratio_a - > denominator ( ) = = 1 ) ;
// check setDenominator() and denominator() (get)
ratio_a - > setDenominator ( 7 ) ;
BOOST_RE T QUIRE( ratio_a - > numerator ( ) = = 10 ) ;
BOOST_RE T QUIRE( ratio_a - > denominator ( ) = = 7 ) ;
BOOST_RE QUIRE( ratio_a - > numerator ( ) = = 10 ) ;
BOOST_RE QUIRE( ratio_a - > denominator ( ) = = 7 ) ;
// now check if the ratio gets reduced
ratio_a - > setNumerator ( 14 ) ;
BOOST_RE T QUIRE( ratio_a - > numerator ( ) = = 2 ) ;
BOOST_RE T QUIRE( ratio_a - > denominator ( ) = = 1 ) ;
BOOST_RE QUIRE( ratio_a - > numerator ( ) = = 2 ) ;
BOOST_RE QUIRE( ratio_a - > denominator ( ) = = 1 ) ;
// lets do the same, but with out reducing
ratio_a - > setNumerator ( 14 , false ) ;
ratio_a - > setDenominator ( 7 , false ) ;
BOOST_RE T QUIRE( ratio_a - > numerator ( ) = = 14 ) ;
BOOST_RE T QUIRE( ratio_a - > denominator ( ) = = 7 ) ;
BOOST_RE QUIRE( ratio_a - > numerator ( ) = = 14 ) ;
BOOST_RE QUIRE( ratio_a - > denominator ( ) = = 7 ) ;
// now the = operator
ratio * ratio_b = new ratio ( ) ;
* ratio_b = * ratio_a ;
BOOST_RE T QUIRE( ratio_b - > numerator ( ) = = 14 ) ;
BOOST_RE T QUIRE( ratio_b - > denominator ( ) = = 7 ) ;
BOOST_RE QUIRE( ratio_b - > numerator ( ) = = 14 ) ;
BOOST_RE QUIRE( ratio_b - > denominator ( ) = = 7 ) ;
// make sure we didn't just copied the pointers
BOOST_RE T QUIRE( ratio_a ! = ratio_b ) ;
BOOST_RE QUIRE( ratio_a ! = ratio_b ) ;
delete ( ratio_a ) ;
delete ( ratio_b ) ;
@ -116,13 +116,13 @@ class ratio_test
{
ratio ratio_a ;
ratio_a = 8 ;
BOOST_RE T QUIRE( ratio_a . numerator ( ) = = 8 ) ;
BOOST_RE T QUIRE( ratio_a . denominator ( ) = = 1 ) ;
BOOST_RE QUIRE( ratio_a . numerator ( ) = = 8 ) ;
BOOST_RE QUIRE( ratio_a . denominator ( ) = = 1 ) ;
ratio ratio_b ( 2 , 3 ) ;
ratio_a = ratio_b ;
BOOST_RE T QUIRE( ratio_a . numerator ( ) = = 2 ) ;
BOOST_RE T QUIRE( ratio_a . denominator ( ) = = 3 ) ;
BOOST_RE QUIRE( ratio_a . numerator ( ) = = 2 ) ;
BOOST_RE QUIRE( ratio_a . denominator ( ) = = 3 ) ;
return ;
}
@ -140,29 +140,29 @@ class ratio_test
// check + operator
ratio ratio_c = * ratio_a + * ratio_b ;
BOOST_RE T QUIRE( ratio_c . numerator ( ) = = 5 ) ;
BOOST_RE T QUIRE( ratio_c . denominator ( ) = = 2 ) ;
BOOST_RE QUIRE( ratio_c . numerator ( ) = = 5 ) ;
BOOST_RE QUIRE( ratio_c . denominator ( ) = = 2 ) ;
// it should be the same if we change the addends
ratio_c = * ratio_b + * ratio_a ;
BOOST_RE T QUIRE( ratio_c . numerator ( ) = = 5 ) ;
BOOST_RE T QUIRE( ratio_c . denominator ( ) = = 2 ) ;
BOOST_RE QUIRE( ratio_c . numerator ( ) = = 5 ) ;
BOOST_RE QUIRE( ratio_c . denominator ( ) = = 2 ) ;
// check - operator
ratio_c = * ratio_b - * ratio_a ;
BOOST_RE T QUIRE( ratio_c . numerator ( ) = = - 3 ) ;
BOOST_RE T QUIRE( ratio_c . denominator ( ) = = 2 ) ;
BOOST_RE QUIRE( ratio_c . numerator ( ) = = - 3 ) ;
BOOST_RE QUIRE( ratio_c . denominator ( ) = = 2 ) ;
// it should not be the same if we change the subtrahends
ratio_c = * ratio_a - * ratio_b ;
BOOST_RE T QUIRE( ratio_c . numerator ( ) = = 3 ) ;
BOOST_RE T QUIRE( ratio_c . denominator ( ) = = 2 ) ;
BOOST_RE QUIRE( ratio_c . numerator ( ) = = 3 ) ;
BOOST_RE QUIRE( ratio_c . denominator ( ) = = 2 ) ;
// now check if we can get 0/1
* ratio_a = * ratio_b ;
ratio_c = * ratio_a - * ratio_b ;
BOOST_RE T QUIRE( ratio_c . numerator ( ) = = 0 ) ;
BOOST_RE T QUIRE( ratio_c . denominator ( ) = = 1 ) ;
BOOST_RE QUIRE( ratio_c . numerator ( ) = = 0 ) ;
BOOST_RE QUIRE( ratio_c . denominator ( ) = = 1 ) ;
delete ( ratio_a ) ;
delete ( ratio_b ) ;
@ -183,32 +183,32 @@ class ratio_test
// check * operator
ratio ratio_c = * ratio_a * * ratio_b ;
BOOST_RE T QUIRE( ratio_c . numerator ( ) = = 1 ) ;
BOOST_RE T QUIRE( ratio_c . denominator ( ) = = 2 ) ;
BOOST_RE QUIRE( ratio_c . numerator ( ) = = 1 ) ;
BOOST_RE QUIRE( ratio_c . denominator ( ) = = 2 ) ;
// it should be the same if we change the addends
ratio_c = * ratio_b * * ratio_a ;
BOOST_RE T QUIRE( ratio_c . numerator ( ) = = 1 ) ;
BOOST_RE T QUIRE( ratio_c . denominator ( ) = = 2 ) ;
BOOST_RE QUIRE( ratio_c . numerator ( ) = = 1 ) ;
BOOST_RE QUIRE( ratio_c . denominator ( ) = = 2 ) ;
// check / operator
ratio_c = * ratio_b / * ratio_a ;
BOOST_RE T QUIRE( ratio_c . numerator ( ) = = 1 ) ;
BOOST_RE T QUIRE( ratio_c . denominator ( ) = = 8 ) ;
BOOST_RE QUIRE( ratio_c . numerator ( ) = = 1 ) ;
BOOST_RE QUIRE( ratio_c . denominator ( ) = = 8 ) ;
// it should not be the same if we change the subtrahends
ratio_c = * ratio_a / * ratio_b ;
BOOST_RE T QUIRE( ratio_c . numerator ( ) = = 8 ) ;
BOOST_RE T QUIRE( ratio_c . denominator ( ) = = 1 ) ;
BOOST_RE QUIRE( ratio_c . numerator ( ) = = 8 ) ;
BOOST_RE QUIRE( ratio_c . denominator ( ) = = 1 ) ;
// now check if we can get 0/1
* ratio_a = 0 ;
ratio_c = * ratio_a * * ratio_b ;
BOOST_RE T QUIRE( ratio_c . numerator ( ) = = 0 ) ;
BOOST_RE T QUIRE( ratio_c . denominator ( ) = = 1 ) ;
BOOST_RE QUIRE( ratio_c . numerator ( ) = = 0 ) ;
BOOST_RE QUIRE( ratio_c . denominator ( ) = = 1 ) ;
ratio_c = * ratio_a / * ratio_b ;
BOOST_RE T QUIRE( ratio_c . numerator ( ) = = 0 ) ;
BOOST_RE T QUIRE( ratio_c . denominator ( ) = = 1 ) ;
BOOST_RE QUIRE( ratio_c . numerator ( ) = = 0 ) ;
BOOST_RE QUIRE( ratio_c . denominator ( ) = = 1 ) ;
delete ( ratio_a ) ;
delete ( ratio_b ) ;
@ -221,8 +221,8 @@ class ratio_test
{
ratio ratio_a ( 2 , 3 ) ;
ratio_a . reziproc ( ) ;
BOOST_RE T QUIRE( ratio_a . numerator ( ) = = 3 ) ;
BOOST_RE T QUIRE( ratio_a . denominator ( ) = = 2 ) ;
BOOST_RE QUIRE( ratio_a . numerator ( ) = = 3 ) ;
BOOST_RE QUIRE( ratio_a . denominator ( ) = = 2 ) ;
return ;
}
@ -234,8 +234,8 @@ class ratio_test
ratio_a . setNumerator ( 51 , false ) ;
ratio_a . setDenominator ( 17 , false ) ;
ratio_a . reduce ( ) ;
BOOST_RE T QUIRE( ratio_a . numerator ( ) = = 3 ) ;
BOOST_RE T QUIRE( ratio_a . denominator ( ) = = 1 ) ;
BOOST_RE QUIRE( ratio_a . numerator ( ) = = 3 ) ;
BOOST_RE QUIRE( ratio_a . denominator ( ) = = 1 ) ;
return ;
}
@ -249,11 +249,11 @@ class ratio_test
ratio ratio_d ( 2 , - 3 ) ;
ratio ratio_e ( - 2 , 3 ) ;
BOOST_RE T QUIRE( ( ratio_a = = ratio_a ) = = true ) ;
BOOST_RE T QUIRE( ( ratio_a = = ratio_b ) = = true ) ;
BOOST_RE T QUIRE( ( ratio_a = = ratio_c ) = = true ) ;
BOOST_RE T QUIRE( ( ratio_a = = ratio_d ) = = false ) ;
BOOST_RE T QUIRE( ( ratio_a = = ratio_e ) = = false ) ;
BOOST_RE QUIRE( ( ratio_a = = ratio_a ) = = true ) ;
BOOST_RE QUIRE( ( ratio_a = = ratio_b ) = = true ) ;
BOOST_RE QUIRE( ( ratio_a = = ratio_c ) = = true ) ;
BOOST_RE QUIRE( ( ratio_a = = ratio_d ) = = false ) ;
BOOST_RE QUIRE( ( ratio_a = = ratio_e ) = = false ) ;
return ;
}
@ -267,21 +267,21 @@ class ratio_test
ratio ratio_d ( 2 , - 3 ) ;
ratio ratio_e ( - 2 , 3 ) ;
BOOST_RE T QUIRE( ( ratio_a < ratio_a ) = = false ) ;
BOOST_RE T QUIRE( ( ratio_a < ratio_b ) = = false ) ;
BOOST_RE T QUIRE( ( ratio_a < ratio_c ) = = false ) ;
BOOST_RE T QUIRE( ( ratio_a < ratio_d ) = = false ) ;
BOOST_RE T QUIRE( ( ratio_a < ratio_e ) = = false ) ;
BOOST_RE QUIRE( ( ratio_a < ratio_a ) = = false ) ;
BOOST_RE QUIRE( ( ratio_a < ratio_b ) = = false ) ;
BOOST_RE QUIRE( ( ratio_a < ratio_c ) = = false ) ;
BOOST_RE QUIRE( ( ratio_a < ratio_d ) = = false ) ;
BOOST_RE QUIRE( ( ratio_a < ratio_e ) = = false ) ;
ratio_a = ratio ( - 2 , 3 ) ;
BOOST_RE T QUIRE( ( ratio_a < ratio_a ) = = false ) ;
BOOST_RE T QUIRE( ( ratio_a < ratio_b ) = = true ) ;
BOOST_RE T QUIRE( ( ratio_a < ratio_c ) = = true ) ;
BOOST_RE T QUIRE( ( ratio_a < ratio_d ) = = false ) ;
BOOST_RE T QUIRE( ( ratio_a < ratio_e ) = = false ) ;
BOOST_RE QUIRE( ( ratio_a < ratio_a ) = = false ) ;
BOOST_RE QUIRE( ( ratio_a < ratio_b ) = = true ) ;
BOOST_RE QUIRE( ( ratio_a < ratio_c ) = = true ) ;
BOOST_RE QUIRE( ( ratio_a < ratio_d ) = = false ) ;
BOOST_RE QUIRE( ( ratio_a < ratio_e ) = = false ) ;
BOOST_RE T QUIRE( ( ratio ( 5 , 8 ) < ratio ( 2 , 1 ) ) = = true ) ;
BOOST_RE QUIRE( ( ratio ( 5 , 8 ) < ratio ( 2 , 1 ) ) = = true ) ;
return ;
}
@ -296,21 +296,21 @@ class ratio_test
ratio ratio_e ( - 2 , 3 ) ;
ratio ratio_f ( - 4 , 3 ) ;
BOOST_RE T QUIRE( ( ratio_a > ratio_a ) = = false ) ;
BOOST_RE T QUIRE( ( ratio_a > ratio_b ) = = false ) ;
BOOST_RE T QUIRE( ( ratio_a > ratio_c ) = = false ) ;
BOOST_RE T QUIRE( ( ratio_a > ratio_d ) = = true ) ;
BOOST_RE T QUIRE( ( ratio_a > ratio_e ) = = true ) ;
BOOST_RE T QUIRE( ( ratio_a > ratio_f ) = = true ) ;
BOOST_RE QUIRE( ( ratio_a > ratio_a ) = = false ) ;
BOOST_RE QUIRE( ( ratio_a > ratio_b ) = = false ) ;
BOOST_RE QUIRE( ( ratio_a > ratio_c ) = = false ) ;
BOOST_RE QUIRE( ( ratio_a > ratio_d ) = = true ) ;
BOOST_RE QUIRE( ( ratio_a > ratio_e ) = = true ) ;
BOOST_RE QUIRE( ( ratio_a > ratio_f ) = = true ) ;
ratio_a = ratio ( - 2 , 3 ) ;
BOOST_RE T QUIRE( ( ratio_a > ratio_a ) = = false ) ;
BOOST_RE T QUIRE( ( ratio_a > ratio_b ) = = false ) ;
BOOST_RE T QUIRE( ( ratio_a > ratio_c ) = = false ) ;
BOOST_RE T QUIRE( ( ratio_a > ratio_d ) = = false ) ;
BOOST_RE T QUIRE( ( ratio_a > ratio_e ) = = false ) ;
BOOST_RE T QUIRE( ( ratio_a > ratio_f ) = = true ) ;
BOOST_RE QUIRE( ( ratio_a > ratio_a ) = = false ) ;
BOOST_RE QUIRE( ( ratio_a > ratio_b ) = = false ) ;
BOOST_RE QUIRE( ( ratio_a > ratio_c ) = = false ) ;
BOOST_RE QUIRE( ( ratio_a > ratio_d ) = = false ) ;
BOOST_RE QUIRE( ( ratio_a > ratio_e ) = = false ) ;
BOOST_RE QUIRE( ( ratio_a > ratio_f ) = = true ) ;
return ;
}