refactor: yesno checker

This commit is contained in:
Baoshuo Ren 2022-10-05 18:53:34 +08:00
parent 2e4e850891
commit 7c0bdf3d8d
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

View File

@ -1,27 +1,51 @@
#include "testlib.h" #include "testlib.h"
#include <string>
using namespace std; using namespace std;
const string YES = "YES"; const string YES = "YES";
const string NO = "NO"; const string NO = "NO";
int main(int argc, char * argv[]) int main(int argc, char* argv[]) {
{ setName("compare ordered sequences of YES or NO (case insensetive)");
setName("YES or NO (case insensetive)");
registerTestlibCmd(argc, argv); registerTestlibCmd(argc, argv);
std::string ja = upperCase(ans.readWord()); int n = 0;
std::string pa = upperCase(ouf.readWord());
if (ja != YES && ja != NO) while (!ans.seekEof() && !ouf.seekEof()) {
quitf(_fail, "%s or %s expected in answer, but %s found", YES.c_str(), NO.c_str(), compress(ja).c_str()); n++;
std::string ja = upperCase(ans.readWord());
std::string pa = upperCase(ouf.readWord());
if (pa != YES && pa != NO) if (ja != YES && ja != NO)
quitf(_pe, "%s or %s expected, but %s found", YES.c_str(), NO.c_str(), compress(pa).c_str()); quitf(_fail, "%d%s differ - %s or %s expected, but %s found", n, englishEnding(n).c_str(), YES.c_str(), NO.c_str(), compress(ja).c_str());
if (ja != pa) if (pa != YES && pa != NO)
quitf(_wa, "expected %s, found %s", compress(ja).c_str(), compress(pa).c_str()); quitf(_pe, "%d%s differ - %s or %s expected, but %s found", n, englishEnding(n).c_str(), YES.c_str(), NO.c_str(), compress(pa).c_str());
quitf(_ok, "answer is %s", ja.c_str()); if (ja != pa)
quitf(_wa, "%d%s differ - expected: '%s', found: '%s'", n, englishEnding(n).c_str(), vtos(ja).c_str(), vtos(pa).c_str());
}
int extraInAnsCount = 0;
while (!ans.seekEof()) {
ans.readToken();
extraInAnsCount++;
}
int extraInOufCount = 0;
while (!ouf.seekEof()) {
ouf.readToken();
extraInOufCount++;
}
if (extraInAnsCount > 0)
quitf(_wa, "Answer contains longer sequence [length = %d], but output contains %d elements", n + extraInAnsCount, n);
if (extraInOufCount > 0)
quitf(_wa, "Output contains longer sequence [length = %d], but answer contains %d elements", n + extraInOufCount, n);
quitf(_ok, "%d token(s)", n);
} }