1
0

lcmp.cpp 1.1 KB

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