1
0

nyesno.cpp 2.0 KB

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