1
0

nyesno.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 insensitive)").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",
  41. index + extraInAnsCount, index);
  42. if (extraInOufCount > 0)
  43. quitf(_wa, "Output contains longer sequence [length = %d], but answer contains %d elements",
  44. index + extraInOufCount, index);
  45. if (index == 0)
  46. quitf(_ok, "Empty output");
  47. else if (index == 1)
  48. quitf(_ok, "%s", pa.c_str());
  49. else
  50. quitf(_ok, "%d token(s): yes count is %d, no count is %d", index, yesCount, noCount);
  51. quitf(_fail, "Impossible case");
  52. }