caseicmp.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * Checker to compare output and answer in the form:
  3. *
  4. * Case 1: <number>
  5. * Case 2: <number>
  6. * ...
  7. * Case n: <number>
  8. *
  9. */
  10. #include "testlib.h"
  11. #include <vector>
  12. #include <string>
  13. using namespace std;
  14. vector<long long> readStream(InStream& in)
  15. {
  16. vector<long long> result;
  17. for (int testCase = 1; !in.seekEof(); testCase++) {
  18. string caseStr = in.readToken();
  19. if (caseStr != "Case")
  20. in.quitf(_pe, "Expected 'Case' but found '%s' [test case %d]", compress(caseStr).c_str(), testCase);
  21. string numExpStr = to_string(testCase) + ":";
  22. string numStr = in.readToken();
  23. if (numExpStr != numStr)
  24. in.quitf(_pe, "Expected '%s' but found '%s' [test case %d]", compress(numExpStr).c_str(), compress(numStr).c_str(), testCase);
  25. result.push_back(in.readLong());
  26. }
  27. return result;
  28. }
  29. int main(int argc, char* argv[]) {
  30. setName("Single int64 checker with testcase-support");
  31. registerTestlibCmd(argc, argv);
  32. vector<long long> ja = readStream(ans);
  33. vector<long long> pa = readStream(ouf);
  34. for (unsigned int i = 0; i < min(ja.size(), pa.size()); i++)
  35. if (ja[i] != pa[i])
  36. quitf(_wa, "Expected %s found %s [test case %d]", vtos(ja[i]).c_str(), vtos(pa[i]).c_str(), i + 1);
  37. if (ja.size() != pa.size())
  38. quitf(_pe, "Expected %u test case(s) but found %u", (unsigned int)(ja.size()), (unsigned int)(pa.size()));
  39. string message = format("%u case(s):", (unsigned int)(ja.size()));
  40. if (ja.size() <= 5) {
  41. for (auto elem : ja)
  42. message += " " + vtos(elem);
  43. }
  44. else
  45. {
  46. for (int i = 0; i < 3; i++)
  47. message += " " + vtos(ja[i]);
  48. message += " ...";
  49. for (int i = 0; i < 2; i++)
  50. message += " " + vtos(ja[ja.size() - 2 + i]);
  51. }
  52. quitf(_ok, "%s", message.c_str());
  53. }