nyesno.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include "testlib.h"
  2. #include <string>
  3. using namespace std;
  4. const string YES = "YES";
  5. const string NO = "NO";
  6. int main(int argc, char * argv[])
  7. {
  8. setName("%s", ("multiple " + YES + "/" + NO + " (case insensetive)").c_str());
  9. registerTestlibCmd(argc, argv);
  10. int index = 0, yesCount = 0, noCount = 0;
  11. std::string pa;
  12. while (!ans.seekEof() && !ouf.seekEof())
  13. {
  14. index++;
  15. std::string ja = upperCase(ans.readToken());
  16. pa = upperCase(ouf.readToken());
  17. if (ja != YES && ja != NO)
  18. quitf(_fail, "%s or %s expected in answer, but %s found [%d%s token]",
  19. YES.c_str(), NO.c_str(), compress(ja).c_str(), index, englishEnding(index).c_str());
  20. if (pa == YES)
  21. yesCount++;
  22. else if (pa == NO)
  23. noCount++;
  24. else
  25. quitf(_pe, "%s or %s expected, but %s found [%d%s token]",
  26. YES.c_str(), NO.c_str(), compress(pa).c_str(), index, englishEnding(index).c_str());
  27. if (ja != pa)
  28. quitf(_wa, "expected %s, found %s [%d%s token]",
  29. compress(ja).c_str(), compress(pa).c_str(), index, englishEnding(index).c_str());
  30. }
  31. int extraInAnsCount = 0;
  32. while (!ans.seekEof())
  33. {
  34. ans.readToken();
  35. extraInAnsCount++;
  36. }
  37. int extraInOufCount = 0;
  38. while (!ouf.seekEof())
  39. {
  40. ouf.readToken();
  41. extraInOufCount++;
  42. }
  43. if (extraInAnsCount > 0)
  44. quitf(_wa, "Answer contains longer sequence [length = %d], but output contains %d elements", index + extraInAnsCount, index);
  45. if (extraInOufCount > 0)
  46. quitf(_wa, "Output contains longer sequence [length = %d], but answer contains %d elements", index + extraInOufCount, index);
  47. if (index == 0)
  48. quitf(_ok, "Empty output");
  49. else if (index == 1)
  50. quitf(_ok, "%s", pa.c_str());
  51. else
  52. quitf(_ok, "%d token(s): yes count is %d, no count is %d", index, yesCount, noCount);
  53. quitf(_fail, "Impossible case");
  54. }