From a3a80011e7721452a05376c32562765721eb038d Mon Sep 17 00:00:00 2001 From: "Sam A. Markelon" Date: Mon, 18 Feb 2019 13:20:59 -0500 Subject: [PATCH] Binary test for Assignment 1: Method 5 --- assignments/asgn1.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/assignments/asgn1.cpp b/assignments/asgn1.cpp index bc36ac7..391e22d 100644 --- a/assignments/asgn1.cpp +++ b/assignments/asgn1.cpp @@ -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 tests = { { 20, { 2, 2, 5 } }, { 29, { 29 } }, @@ -43,6 +56,18 @@ 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.\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)); @@ -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)); + } +}