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[]) {
|
int main(int argc, char *argv[]) {
|
||||||
std::vector<test_case> test_cases;
|
|
||||||
semicolon_is_space delimeter;
|
semicolon_is_space delimeter;
|
||||||
for (int i = 1; i < argc; i++) {
|
for (int i = 1; i < argc; i++) {
|
||||||
std::ifstream f(argv[i]);
|
std::ifstream f(argv[i]);
|
||||||
@ -132,21 +131,16 @@ int main(int argc, char *argv[]) {
|
|||||||
f >> t;
|
f >> t;
|
||||||
if (t.i.s.length()) { // skip empty line/string inputs
|
if (t.i.s.length()) { // skip empty line/string inputs
|
||||||
std::cout << t;
|
std::cout << t;
|
||||||
test_cases.push_back(t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cout << "\n===================================\n" << std::endl;
|
|
||||||
|
|
||||||
for (const test_case &t : test_cases) {
|
|
||||||
if (find(t.i.s, t.i.k) == t.r) {
|
if (find(t.i.s, t.i.k) == t.r) {
|
||||||
std::cout << "Test case with string \"" << t.i.s << "\" and k=" << t.i.k
|
std::cout << "Test case with string \"" << t.i.s
|
||||||
<< " passed.\n";
|
<< "\" and k=" << t.i.k << " passed.\n";
|
||||||
} else {
|
} else {
|
||||||
std::cout << std::flush;
|
std::cout << std::flush;
|
||||||
std::cerr << "TEST CASE WITH STRING \"" << t.i.s << "\" AND k=" << t.i.k
|
std::cerr << "TEST CASE WITH STRING \"" << t.i.s
|
||||||
<< " FAILED.\n";
|
<< "\" AND k=" << t.i.k << " FAILED.\n";
|
||||||
|
}
|
||||||
|
std::cout << "\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user