fork download
  1. #include <iostream>
  2. #include <cmath>
  3. #include <cassert>
  4. using namespace std;
  5. const double epsilon = 0.00001;
  6. // main() calls both findDistance() and test() correctly so they don't need to be shown.
  7. // Note: This is only a section of the full code as it is the only relevant part.
  8.  
  9. double findDistance(float x1, float y1, float x2, float y2) {
  10. double distanceTotal = sqrt( pow( (x2-x1),2 ) + pow( (y2-y1),2 )); // This line doesn't work with assert values.
  11. //double distanceTotal = (x2-x1) + (y2-y1); // This line works with assert values.
  12. return distanceTotal;
  13. }
  14.  
  15. int main() {
  16. assert(findDistance(4, 3, 5, 1) - 2.23607 <= epsilon);
  17. assert(findDistance(2, 4, 2, 4) <= 1.00);
  18. assert(findDistance(4, 4, 4, 4) <= 1.00);
  19. cout << "all tests passed..." << endl;
  20. cout << findDistance(3, 3, 1, 1)<<endl;
  21. }
  22.  
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
all tests passed...
2.82843