Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Revise Asgn1: Q5 to be less strict with regex
Issue #4
  • Loading branch information
Brandon committed Feb 21, 2019
1 parent 5206701 commit f36588b
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/asgn1/main.cpp
Expand Up @@ -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<NumberToFactor, FactorsContainer> tests = {
{ 20, { 2, 2, 5 } },
{ 29, { 29 } },
Expand All @@ -55,18 +54,6 @@ const std::map<NumberToFactor, FactorsContainer> tests = {
{ 1234567890987654321, { 3, 3, 7, 19, 928163, 1111211111 } }
};


const std::map<NumberToFactor, std::string> 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));
Expand Down Expand Up @@ -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<NumberToFactor, std::string> 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)
);
}
}

0 comments on commit f36588b

Please sign in to comment.