1
0

uncmp.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "testlib.h"
  2. #include <vector>
  3. using namespace std;
  4. int main(int argc, char * argv[])
  5. {
  6. setName("compare unordered sequences of signed int%lu numbers", 8 * sizeof(long long));
  7. registerTestlibCmd(argc, argv);
  8. vector<long long> ja, pa;
  9. while (!ans.seekEof())
  10. ja.push_back(ans.readLong());
  11. while (!ouf.seekEof())
  12. pa.push_back(ouf.readLong());
  13. if (ja.size() != pa.size())
  14. quitf(_wa, "Expected %u elements, but %u found", (unsigned int)(ja.size()), (unsigned int)(pa.size()));
  15. sort(ja.begin(), ja.end());
  16. sort(pa.begin(), pa.end());
  17. if (ja != pa)
  18. quitf(_wa, "Expected sequence and output are different (as unordered sequences) [size=%u]", (unsigned int)(ja.size()));
  19. string message;
  20. if (ja.size() != 1)
  21. if (ja.empty())
  22. message = "empty sequence";
  23. else
  24. message = vtos(ja.size()) + " numbers (in increasing order):";
  25. else
  26. message = vtos(ja.size()) + " number:";
  27. if (ja.size() <= 5)
  28. for (int i = 0; i < min(int(ja.size()), 5); i++)
  29. message += " " + vtos(ja[i]);
  30. else
  31. {
  32. for (int i = 0; i < 2; i++)
  33. message += " " + vtos(ja[i]);
  34. message += " ...";
  35. for (int i = 0; i < 2; i++)
  36. message += " " + vtos(ja[ja.size() - 2 + i]);
  37. }
  38. quitf(_ok, "%s", message.c_str());
  39. }