wcmp.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "testlib.h"
  2. using namespace std;
  3. string ending(int x)
  4. {
  5. x %= 100;
  6. if (x / 10 == 1)
  7. return "th";
  8. if (x % 10 == 1)
  9. return "st";
  10. if (x % 10 == 2)
  11. return "nd";
  12. if (x % 10 == 3)
  13. return "rd";
  14. return "th";
  15. }
  16. string part(const string& s)
  17. {
  18. if (s.length() <= 64)
  19. return s;
  20. else
  21. return s.substr(0, 30) + "..." + s.substr(s.length() - 31, 31);
  22. }
  23. int main(int argc, char * argv[])
  24. {
  25. setName("compare sequences of tokens");
  26. registerTestlibCmd(argc, argv);
  27. std::string strAnswer;
  28. int n = 0;
  29. while (!ans.seekEof() && !ouf.seekEof())
  30. {
  31. n++;
  32. std::string j = ans.readWord();
  33. std::string p = ouf.readWord();
  34. strAnswer = p;
  35. if (j != p)
  36. quitf(_wa, "%d%s words differ - expected: '%s', found: '%s'", n, ending(n).c_str(), part(j).c_str(), part(p).c_str());
  37. }
  38. if (ans.seekEof() && ouf.seekEof())
  39. {
  40. if (n == 1)
  41. quitf(_ok, "%s", part(strAnswer).c_str());
  42. else
  43. quitf(_ok, "%d words", n);
  44. }
  45. else
  46. {
  47. if (ans.seekEof())
  48. quitf(_wa, "Participant output contains extra tokens");
  49. else
  50. quitf(_wa, "Unexpected EOF in the participants output");
  51. }
  52. }