#include "ordle.h" #include #include #include #include void test_read_candidates() { std::istringstream input("apple\nbanana\ncherry\nimbus\n"); auto words = read_candidates(input); auto w = std::vector{"apple", "imbus"}; assert(words == w); std::cout << "test_read_candidates passed.\n"; } void test_contains_any_of() { assert(contains_any_of("apple", "aeiou")); assert(!contains_any_of("brrr", "aeiou")); std::cout << "test_contains_any_of passed.\n"; } void test_contains_at() { assert(contains_at("apple", 'a', 0)); assert(!contains_at("apple", 'p', 0)); assert(!contains_at("apple", 'p', 100)); std::cout << "test_contains_at passed.\n"; } void test_contains_but_not_at() { assert(contains_but_not_at("apple", 'p', 0)); assert(!contains_but_not_at("apple", 'a', 0)); std::cout << "test_contains_but_not_at passed.\n"; } void test_wrong_fn() { wrong_fn wrong("aeiou"); assert(wrong("apple")); // Contains a,e assert(!wrong("brrr")); // Contains none std::cout << "test_wrong_fn passed.\n"; } void test_correct_fn() { IndexMap green = {{0, "a"}, {4, "e"}}; correct_fn correct(green); assert(correct("apple")); assert(correct("ample")); assert(!correct("jedi")); std::cout << "test_correct_fn passed.\n"; } void test_misplaced_fn() { IndexMap yellow = {{1, "p"}, {2, "p"}}; misplaced_fn misplaced(yellow); assert(!misplaced("apple")); assert(misplaced("puppy")); std::cout << "test_misplaced_fn passed.\n"; } void test_do_filter() { std::vector candidates = {"apple", "ample", "angle"}; std::string wrong = "iou"; IndexMap green = {{0, "a"}}; IndexMap yellow = {{4, "e"}}; do_filter(candidates, wrong, green, yellow); assert(candidates == std::vector{"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"; } int main() { test_read_candidates(); test_contains_any_of(); test_contains_at(); test_contains_but_not_at(); test_wrong_fn(); test_correct_fn(); // test_misplaced_fn(); // Misbehaves // test_do_filter(); // Misbehaves // test_build_list(); // Misbehaves std::cout << "All tests passed!\n"; return 0; }