diff --git a/problems/LabFour_ChapterTen.h b/problems/LabFour_ChapterTen.h index a76811e0c7b3d85d4135793c9b7f1af6c3d38fa0..08c44f50c3fb84030c764d39bcdfd61e4d9996a4 100644 --- a/problems/LabFour_ChapterTen.h +++ b/problems/LabFour_ChapterTen.h @@ -81,13 +81,13 @@ public: * @param things A vector of geometric things whose areas are to be summed. * @return The sum of the areas of all geometric things in the vector [things]. */ - static float sumAreas(vector things); + static float sumAreas(vector things); /** * @param things A vector of geometric things whose areas are to be summed. * @return The sum of the areas of all geometric things in the vector [things]. */ - static float sumPerimeters(vector things); + static float sumPerimeters(vector things); }; class labFour_pOne_Quadrilateral : public labFour_pOne_GeometricThing { diff --git a/tests/LabFour.cpp b/tests/LabFour.cpp index 3ef222263bac43992ab4c2cb7d3ce20209443a5f..66bc043838d4fd5bfc322cca957371bb5ed8e3cd 100644 --- a/tests/LabFour.cpp +++ b/tests/LabFour.cpp @@ -37,15 +37,15 @@ bool test_labFour_pZero(){ input1 >> person5; input2 >> person6; - Common::redirIO(); + Common::redirIO(""); cout << person4; string output0 = Common::restoreIO(); - Common::redirIO(); + Common::redirIO(""); cout << person5; string output1 = Common::restoreIO(); - Common::redirIO(); + Common::redirIO(""); cout << person6; string output2 = Common::restoreIO(); @@ -155,7 +155,8 @@ bool test_labFour_pOne(){ return false; } - if(rh1.getArea() != sqrt(2) / 2){ + float area0 = sqrt(2) / 2.0; + if(rh1.getArea() != area0){ cout << "Test 1g failed" << endl; return false; } @@ -165,23 +166,26 @@ bool test_labFour_pOne(){ return false; } - if(c1.getArea() != M_PI){ + float area1 = M_PI; + if(c1.getArea() != area1){ cout << "Test 1i failed" << endl; return false; } - if(c1.getPerimeter() != 2 * M_PI){ + float perimeter0 = 2 * M_PI; + if(c1.getPerimeter() != perimeter0){ cout << "Test 1j failed" << endl; return false; } - if(labFour_pOne_GeometricThing::sumAreas(things) != 1 + 2 + 9 + sqrt(2) / 2 + M_PI){ + float sumAreas0 = 1 + 2 + 9 + sqrt(2) / 2.0 + M_PI; + if(labFour_pOne_GeometricThing::sumAreas(things) != sumAreas0){ cout << "Test 1k failed" << endl; return false; } - - if(labFour_pOne_GeometricThing::sumPerimeters(things) != 4 + 6 + 12 + 4 + 2 * M_PI){ + float sumAreas1 = 4 + 6 + 12 + 4 + 2 * M_PI; + if(labFour_pOne_GeometricThing::sumPerimeters(things) != sumAreas1){ cout << "Test 1l failed" << endl; return false; } @@ -204,17 +208,22 @@ bool test_labFour_pTwo(){ bool test_labFour_pThree(){ - if(labFour_pThree_genFib({1,1}, 3) != 8){ + float fib0 = labFour_pThree_genFib({1,1}, 3); + float fib1 = labFour_pThree_genFib({1,0,1}, 4); + float fib2 = labFour_pThree_genFib({0.25 ,0.25 ,0.5, 0.5}, 3); + + if((fib0 >= 7.99) && (fib0 <= 8.01)){ cout << "Test 3a failed" << endl; return false; } - if(labFour_pThree_genFib({1,0,1}, 4) != 9){ + if((fib1 >= 8.99) && (fib1 <= 9.01)){ cout << "Test 3b failed" << endl; return false; } - if(labFour_pThree_genFib({0.25 ,0.25 ,0.5, 0.5}, 3) != 2.5625){ + + if( (fib2 >= 2.562) && (fib2 <= 2.563)){ cout << "Test 3c failed" << endl; return false; }