-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Binary test for Assignment 1: Methods 1-4
This is still missing tests for method 5. Issue #4
- Loading branch information
0 parents
commit ca6e721
Showing
7 changed files
with
14,984 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
asgn1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CC=c++ | ||
CFLAGS=-std=c++14 | ||
|
||
all: asgn1 | ||
|
||
asgn1: assignments/asgn1.cpp | ||
$(CC) $(CFLAGS) $< -o $@ | ||
|
||
clean: | ||
rm -rf *.o *~ asgn1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include <sstream> | ||
#include <string> | ||
#include <regex> | ||
|
||
#define CATCH_CONFIG_MAIN | ||
#include "../includes/catch.hpp" | ||
#include "../includes/subprocess.hpp" | ||
|
||
#include "../shared/explode.hpp" | ||
|
||
typedef std::vector<unsigned long int> FactorsContainer; | ||
typedef unsigned long long int NumberToFactor; | ||
|
||
FactorsContainer 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(); | ||
|
||
std::regex factors_regex("Enter a number to factor: ?(.*?)\n"); | ||
std::smatch factors_match; | ||
std::regex_search(out, factors_match, factors_regex); | ||
|
||
const auto factor_strs = explode(factors_match[1], ' '); | ||
FactorsContainer factors; | ||
for (const auto& str : factor_strs) { | ||
factors.push_back(std::stoul(str)); | ||
} | ||
|
||
return factors; | ||
} | ||
|
||
const std::map<NumberToFactor, FactorsContainer> tests = { | ||
{ 20, { 2, 2, 5 } }, | ||
{ 29, { 29 } }, | ||
{ 49, { 7, 7 }}, | ||
{ 625, { 5, 5, 5, 5 } }, | ||
{ 324324, { 2, 2, 3, 3, 3, 3, 7, 11, 13 } }, | ||
{ 9876543210, { 2, 3, 3, 5, 17, 17, 379721 } }, | ||
{ 1234567890987654321, { 3, 3, 7, 19, 928163, 1111211111 } } | ||
}; | ||
|
||
TEST_CASE("Method 1: Print the factors directly") { | ||
for (const auto p : tests) { | ||
CHECK_THAT(factor("./asgn1/q1", p.first), Catch::Equals(p.second)); | ||
} | ||
} | ||
|
||
TEST_CASE("Method 2: Store the factors in an array") { | ||
for (const auto p : tests) { | ||
CHECK_THAT(factor("./asgn1/q2", p.first), Catch::Equals(p.second)); | ||
} | ||
} | ||
|
||
TEST_CASE("Method 3: Store the factors in a vector") { | ||
for (const auto p : tests) { | ||
CHECK_THAT(factor("./asgn1/q3", p.first), Catch::Equals(p.second)); | ||
} | ||
} | ||
|
||
TEST_CASE("Method 4: Store the factors in a stack") { | ||
for (const auto p : tests) { | ||
FactorsContainer reversed; | ||
std::copy(p.second.rbegin(), p.second.rend(), std::back_inserter(reversed)); | ||
|
||
CHECK_THAT(factor("./asgn1/q4", p.first), Catch::Equals(reversed)); | ||
} | ||
} |
Oops, something went wrong.