Fixing and extending tests
This commit is contained in:
parent
91a796d2cc
commit
8bbe5591c3
3 changed files with 79 additions and 30 deletions
62
test/test.cc
62
test/test.cc
|
|
@ -29,6 +29,7 @@ void test_contains_at() {
|
|||
void test_contains_but_not_at() {
|
||||
assert(contains_but_not_at("apple", 'p', 0));
|
||||
assert(!contains_but_not_at("apple", 'a', 0));
|
||||
assert(!contains_but_not_at("abc", 'k', 1000));
|
||||
std::cout << "test_contains_but_not_at passed.\n";
|
||||
}
|
||||
|
||||
|
|
@ -40,7 +41,7 @@ void test_wrong_fn() {
|
|||
}
|
||||
|
||||
void test_correct_fn() {
|
||||
IndexMap green = {{0, "a"}, {4, "e"}};
|
||||
IndexMap green = {{0, 'a'}, {4, 'e'}};
|
||||
correct_fn correct(green);
|
||||
assert(correct("apple"));
|
||||
assert(correct("ample"));
|
||||
|
|
@ -49,11 +50,12 @@ void test_correct_fn() {
|
|||
}
|
||||
|
||||
void test_misplaced_fn() {
|
||||
IndexMap yellow = {{1, "p"}, {2, "p"}};
|
||||
IndexMap yellow = {{1, 'p'}, {2, 'p'}};
|
||||
misplaced_fn misplaced(yellow);
|
||||
|
||||
assert(!misplaced("apple"));
|
||||
assert(misplaced("puppy"));
|
||||
assert(!misplaced("joink"));
|
||||
|
||||
std::cout << "test_misplaced_fn passed.\n";
|
||||
}
|
||||
|
|
@ -61,20 +63,58 @@ void test_misplaced_fn() {
|
|||
void test_do_filter() {
|
||||
std::vector<std::string> candidates = {"apple", "ample", "angle"};
|
||||
std::string wrong = "iou";
|
||||
IndexMap green = {{0, "a"}};
|
||||
IndexMap yellow = {{4, "e"}};
|
||||
IndexMap green = {{0, 'a'}, {1, 'p'}};
|
||||
IndexMap yellow = {{3, 'e'}};
|
||||
|
||||
do_filter(candidates, wrong, green, yellow);
|
||||
|
||||
std::for_each(candidates.begin(), candidates.end(),
|
||||
[&](auto &word) { std::cout << word << std::endl; });
|
||||
|
||||
assert(candidates == std::vector<std::string>{"apple"});
|
||||
std::cout << "test_do_filter passed.\n";
|
||||
}
|
||||
|
||||
void test_build_list() {
|
||||
auto result = build_list("a:0 e:4");
|
||||
auto l = IndexMap{{0, "a"}, {4, "e"}};
|
||||
assert(result == l);
|
||||
std::cout << "test_build_list passed.\n";
|
||||
{
|
||||
std::string input = "a0 b1 c2";
|
||||
IndexMap result = build_list(input);
|
||||
|
||||
assert(result.size() == 3);
|
||||
assert(result[0] == 'a');
|
||||
assert(result[1] == 'b');
|
||||
assert(result[2] == 'c');
|
||||
|
||||
std::cout << "Test case 1 passed.\n";
|
||||
}
|
||||
{ // Empty input
|
||||
std::string input = "";
|
||||
IndexMap result = build_list(input);
|
||||
|
||||
assert(result.empty());
|
||||
|
||||
std::cout << "Test case 2 passed.\n";
|
||||
}
|
||||
{ // Single input
|
||||
std::string input = "z9";
|
||||
IndexMap result = build_list(input);
|
||||
|
||||
assert(result.size() == 1);
|
||||
assert(result[9] == 'z');
|
||||
|
||||
std::cout << "Test case 3 passed.\n";
|
||||
}
|
||||
{ // Irregular spacing
|
||||
std::string input = "x3 y4 z5";
|
||||
IndexMap result = build_list(input);
|
||||
|
||||
assert(result.size() == 3);
|
||||
assert(result[3] == 'x');
|
||||
assert(result[4] == 'y');
|
||||
assert(result[5] == 'z');
|
||||
|
||||
std::cout << "Test case 4 passed.\n";
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
|
@ -84,9 +124,9 @@ int main() {
|
|||
test_contains_but_not_at();
|
||||
test_wrong_fn();
|
||||
test_correct_fn();
|
||||
// test_misplaced_fn(); // Misbehaves
|
||||
// test_do_filter(); // Misbehaves
|
||||
// test_build_list(); // Misbehaves
|
||||
test_misplaced_fn();
|
||||
test_do_filter();
|
||||
test_build_list();
|
||||
|
||||
std::cout << "All tests passed!\n";
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue