lcmp.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "testlib.h"
  2. #include <string>
  3. #include <vector>
  4. #include <sstream>
  5. using namespace std;
  6. bool compareWords(const string& a, const string& b) {
  7. vector<string> va, vb;
  8. stringstream sa;
  9. sa << a;
  10. string cur;
  11. while (sa >> cur)
  12. va.push_back(cur);
  13. stringstream sb;
  14. sb << b;
  15. while (sb >> cur)
  16. vb.push_back(cur);
  17. return (va == vb);
  18. }
  19. int main(int argc, char *argv[]) {
  20. setName("compare files as sequence of tokens in lines");
  21. registerTestlibCmd(argc, argv);
  22. string strAnswer;
  23. int n = 0;
  24. while (!ans.eof()) {
  25. std::string j = ans.readString();
  26. if (j.empty() && ans.eof())
  27. break;
  28. string p = ouf.readString();
  29. strAnswer = p;
  30. n++;
  31. if (!compareWords(j, p))
  32. quitf(_wa, "%d%s lines differ - expected: '%s', found: '%s'", n, englishEnding(n).c_str(),
  33. compress(j).c_str(), compress(p).c_str());
  34. }
  35. if (n == 1)
  36. quitf(_ok, "single line: '%s'", compress(strAnswer).c_str());
  37. quitf(_ok, "%d lines", n);
  38. }