rcmp6.cpp 986 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include "testlib.h"
  2. #include <cmath>
  3. using namespace std;
  4. const double EPS = 1E-6;
  5. string ending(int x)
  6. {
  7. x %= 100;
  8. if (x / 10 == 1)
  9. return "th";
  10. if (x % 10 == 1)
  11. return "st";
  12. if (x % 10 == 2)
  13. return "nd";
  14. if (x % 10 == 3)
  15. return "rd";
  16. return "th";
  17. }
  18. int main(int argc, char * argv[])
  19. {
  20. setName("compare two sequences of doubles, max absolute or relative error = %.7lf", EPS);
  21. registerTestlibCmd(argc, argv);
  22. int n = 0;
  23. double j, p;
  24. while (!ans.seekEof())
  25. {
  26. n++;
  27. j = ans.readDouble();
  28. p = ouf.readDouble();
  29. if (!doubleCompare(j, p, EPS))
  30. quitf(_wa, "%d%s numbers differ - expected: '%.7lf', found: '%.7lf', error = '%.7lf'", n, ending(n).c_str(), j, p, doubleDelta(j, p));
  31. }
  32. quitif(n == 1, _ok, "found '%.7lf', expected '%.7lf', error '%.7lf'",
  33. p, j, doubleDelta(j, p));
  34. quitf(_ok, "%d numbers", n);
  35. }