From f36588bb77d5b6b09bc51b50a83bc697b8fa0c64 Mon Sep 17 00:00:00 2001 From: Brandon Cheng Date: Thu, 21 Feb 2019 12:13:25 -0500 Subject: [PATCH] Revise Asgn1: Q5 to be less strict with regex Issue #4 --- src/asgn1/main.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/asgn1/main.cpp b/src/asgn1/main.cpp index 8502e90..1f7a8cf 100644 --- a/src/asgn1/main.cpp +++ b/src/asgn1/main.cpp @@ -40,11 +40,10 @@ std::string english_factor(const std::string path, const NumberToFactor n) { std::stringstream s; s << cmd.stdout().rdbuf(); std::string out = s.str(); - + return out; } - const std::map tests = { { 20, { 2, 2, 5 } }, { 29, { 29 } }, @@ -55,18 +54,6 @@ const std::map tests = { { 1234567890987654321, { 3, 3, 7, 19, 928163, 1111211111 } } }; - -const std::map english_tests = { - { 20, "The prime factors of 20 are 2, 2 and 5."}, - { 29, "The prime factor of 29 is 29."}, - { 49, "The prime factors of 49 are 7 and 7."}, - { 625, "The prime factors of 625 are 5, 5, 5 and 5."}, - { 324324, "The prime factors of 324324 are 2, 2, 3, 3, 3, 3, 7, 11 and 13."}, - { 9876543210, "The prime factors of 9876543210 are 2, 3, 3, 5, 17, 17 and 379721."}, - { 1234567890987654321, "The prime factors of 1234567890987654321 are 3, 3, 7, 19, 928163 and 1111211111."} -}; - - TEST_CASE("Method 1: Print the factors directly") { const auto binary = "./asgn1/q1"; // REQUIRE(std::experimental::filesystem::exists(binary)); @@ -96,8 +83,21 @@ TEST_CASE("Method 4: Store the factors in a stack") { } } -TEST_CASE("Method 5: Factoring a number in English"){ +TEST_CASE("Method 5: Factoring a number in English") { + const std::map english_tests = { + { 20, "(.|\n)*The prime factors? of 20 are 2, 2(,|, and| and) 5(.|\n)*"}, + { 29, "(.|\n)*The prime factors? of 29 is 29(.|\n)*"}, + { 49, "(.|\n)*The prime factors? of 49 are 7(,|, and| and) 7(.|\n)*"}, + { 625, "(.|\n)*The prime factors? of 625 are 5, 5, 5(,|, and| and) 5(.|\n)*"}, + { 324324, "(.|\n)*The prime factors? of 324324 are 2, 2, 3, 3, 3, 3, 7, 11(,|, and| and) 13(.|\n)*"}, + { 9876543210, "(.|\n)*The prime factors? of 9876543210 are 2, 3, 3, 5, 17, 17(,|, and| and) 379721(.|\n)*"}, + { 1234567890987654321, "(.|\n)*The prime factors? of 1234567890987654321 are 3, 3, 7, 19, 928163(,|, and| and) 1111211111(.|\n)*"} + }; + for (const auto p : english_tests) { - CHECK_THAT(english_factor("./asgn1/q5", p.first), Catch::Contains(p.second)); + CHECK_THAT( + english_factor("./asgn1/q5", p.first), + Catch::Matches(p.second, Catch::CaseSensitive::Choice::No) + ); } }