caseicmp.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. vector<long long> result;
  16. for (int testCase = 1; !in.seekEof(); testCase++) {
  17. string caseStr = in.readToken();
  18. if (caseStr != "Case")
  19. in.quitf(_pe, "Expected 'Case' but found '%s' [test case %d]", compress(caseStr).c_str(), testCase);
  20. string numExpStr = to_string(testCase) + ":";
  21. string numStr = in.readToken();
  22. if (numExpStr != numStr)
  23. in.quitf(_pe, "Expected '%s' but found '%s' [test case %d]", compress(numExpStr).c_str(),
  24. 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. } else {
  44. for (int i = 0; i < 3; i++)
  45. message += " " + vtos(ja[i]);
  46. message += " ...";
  47. for (int i = 0; i < 2; i++)
  48. message += " " + vtos(ja[ja.size() - 2 + i]);
  49. }
  50. quitf(_ok, "%s", message.c_str());
  51. }