Improvement: directly test 'test cases' read from file instead of first reading all test cases into memory
This commit is contained in:
parent
790303e7da
commit
b2fac0ffd3
@ -122,7 +122,6 @@ result find(const std::string &s, const unsigned long k) {
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
std::vector<test_case> test_cases;
|
||||
semicolon_is_space delimeter;
|
||||
for (int i = 1; i < argc; i++) {
|
||||
std::ifstream f(argv[i]);
|
||||
@ -132,22 +131,17 @@ int main(int argc, char *argv[]) {
|
||||
f >> t;
|
||||
if (t.i.s.length()) { // skip empty line/string inputs
|
||||
std::cout << t;
|
||||
test_cases.push_back(t);
|
||||
if (find(t.i.s, t.i.k) == t.r) {
|
||||
std::cout << "Test case with string \"" << t.i.s
|
||||
<< "\" and k=" << t.i.k << " passed.\n";
|
||||
} else {
|
||||
std::cout << std::flush;
|
||||
std::cerr << "TEST CASE WITH STRING \"" << t.i.s
|
||||
<< "\" AND k=" << t.i.k << " FAILED.\n";
|
||||
}
|
||||
std::cout << "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "\n===================================\n" << std::endl;
|
||||
|
||||
for (const test_case &t : test_cases) {
|
||||
if (find(t.i.s, t.i.k) == t.r) {
|
||||
std::cout << "Test case with string \"" << t.i.s << "\" and k=" << t.i.k
|
||||
<< " passed.\n";
|
||||
} else {
|
||||
std::cout << std::flush;
|
||||
std::cerr << "TEST CASE WITH STRING \"" << t.i.s << "\" AND k=" << t.i.k
|
||||
<< " FAILED.\n";
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user