Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Binary test for Assignment 1: Method 5
  • Loading branch information
Sam A. Markelon committed Feb 18, 2019
1 parent ca6e721 commit a3a8001
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions assignments/asgn1.cpp
Expand Up @@ -33,6 +33,19 @@ FactorsContainer factor(const std::string path, const NumberToFactor n) {
return factors;
}

std::string english_factor(const std::string path, const NumberToFactor n) {
subprocess::popen cmd(path, {});
cmd.stdin() << n << std::endl;
cmd.close();

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 @@ -43,6 +56,18 @@ const std::map<NumberToFactor, FactorsContainer> tests = {
{ 1234567890987654321, { 3, 3, 7, 19, 928163, 1111211111 } }
};


const std::map<NumberToFactor, std::string> english_tests = {

This comment has been minimized.

Copy link
@Brandon

Brandon Feb 18, 2019

Owner

@sam15124
I'm wondering if we should be picky about the s in factors. I lean towards no since Dr. Michel said to be lenient towards grading during the beginning of the semester.

What do you think?

This comment has been minimized.

Copy link
@Brandon

Brandon Feb 18, 2019

Owner

Along the similar lines, I think we should make the and optional.

This comment has been minimized.

Copy link
@ldm02003

ldm02003 Feb 18, 2019

Collaborator

Leniency at the start is best.

This comment has been minimized.

Copy link
@Brandon

Brandon Feb 19, 2019

Owner

Cool. Let's amend this to be a regex expression using Catch::Matches. @sam15124 Do you want to do this since you started this commit? I don't mind making the change otherwise.

This comment has been minimized.

Copy link
@sam

sam Feb 19, 2019

Collaborator

@Brandon I am not very experienced with using regex in an applied setting, so if you want to make the changes that would be good.

{ 20, "The prime factors of 20 are 2, 2 and 5.\n"},
{ 29, "The prime factor of 29 is 29.\n"},
{ 49, "The prime factors of 49 are 7 and 7.\n"},
{ 625, "The prime factors of 625 are 5, 5, 5 and 5.\n"},
{ 324324, "The prime factors of 324324 are 2, 2, 3, 3, 3, 3, 7, 11 and 13.\n"},
{ 9876543210, "The prime factors of 9876543210 are 2, 3, 3, 5, 17, 17 and 379721.\n"},
{ 1234567890987654321, "The prime factors of 1234567890987654321 are 3, 3, 7, 19, 928163 and 1111211111.\n"}
};


TEST_CASE("Method 1: Print the factors directly") {
for (const auto p : tests) {
CHECK_THAT(factor("./asgn1/q1", p.first), Catch::Equals(p.second));
Expand All @@ -69,3 +94,9 @@ TEST_CASE("Method 4: Store the factors in a stack") {
CHECK_THAT(factor("./asgn1/q4", p.first), Catch::Equals(reversed));
}
}

TEST_CASE("Method 5: Factoring a number in English"){
for (const auto p : english_tests) {
CHECK_THAT(english_factor("./asgn1/q5", p.first), Catch::Contains(p.second));
}
}

0 comments on commit a3a8001

Please sign in to comment.