Loading CMakeLists.txt +8 −0 Original line number Diff line number Diff line Loading @@ -15,3 +15,11 @@ add_executable(problem1 tests/testProblem1.cpp tests/testProblem1.cpp ) add_executable(problem0extra tests/extraTestsProb0.cpp ) add_executable(problem1 tests/extraTestsProb1.cpp ) ci_cd/problem0.yml +15 −1 Original line number Diff line number Diff line Loading @@ -68,3 +68,17 @@ internal_testing_problem_0: - cat homework-two-internal/internal_tests/output.txt tags: [c++-17] timeout: 10m HW1_Problem0_TestCase: stage: problem0 script: - echo "Grading HW1 Problem 0"; - git clone https://agile.bu.edu/gitlab/configs/ec327/hw-configs/hw2.git base_0 - cp problem0.cpp base_0/tests - cd base_0/tests - make problem0extra - ./problem0extra rules: - if: '$CI_COMMIT_REF_NAME == "problem0"' tags: [c++-17] timeout: 5m No newline at end of file tests/Makefile +15 −3 Original line number Diff line number Diff line Loading @@ -7,19 +7,25 @@ CXXFLAGS = -Wall -std=c++17 # Source files PROBLEM0_SRCS = testProblem0.cpp problem0.cpp PROBLEM1_SRCS = testProblem1.cpp problem1.cpp SRCS = $(PROBLEM0_SRCS) $(PROBLEM1_SRCS) PROBLEM0EXTRA_SRCS = extraTestsProb0.cpp problem0.cpp PROBLEM1EXTRA_SRCS = extraTestsProb1.cpp problem1.cpp SRCS = $(PROBLEM0_SRCS) $(PROBLEM1_SRCS) $(PROBLEM0EXTRA_SRCS) $(PROBLEM1EXTRA_SRCS) # Object files PROBLEM0_OBJS = testProblem0.o problem0.o PROBLEM1_OBJS = testProblem1.o problem1.o OBJS = $(PROBLEM0_OBJS) $(PROBLEM1_OBJS) PROBLEM0EXTRA_OBJS = extraTestsProb0.o problem0.o PROBLEM1EXTRA_OBJS = extraTestsProb1.o problem1.o OBJS = $(PROBLEM0_OBJS) $(PROBLEM1_OBJS) $(PROBLEM0EXTRA_OBJS) $(PROBLEM1EXTRA_OBJS) # Executable names PROBLEM0_EXEC = problem0 PROBLEM1_EXEC = problem1 PROBLEM0EXTRA_EXEC = problem0extra PROBLEM1EXTRA_EXEC = problem1extra # Default target to build the executable all: $(PROBLEM0_EXEC) $(PROBLEM1_EXEC) all: $(PROBLEM0_EXEC) $(PROBLEM1_EXEC) $(PROBLEM0EXTRA_EXEC) $(PROBLEM1EXTRA_EXEC) # Rule to build the executable from object files $(PROBLEM0_EXEC): $(PROBLEM0_OBJS) Makefile Loading @@ -28,6 +34,12 @@ $(PROBLEM0_EXEC): $(PROBLEM0_OBJS) Makefile $(PROBLEM1_EXEC): $(PROBLEM1_OBJS) Makefile $(CXX) $(CXXFLAGS) -o $(PROBLEM1_EXEC) $(PROBLEM1_OBJS) $(PROBLEM0EXTRA_EXEC): $(PROBLEM0EXTRA_OBJS) Makefile $(CXX) $(CXXFLAGS) -o $(PROBLEM0EXTRA_EXEC) $(PROBLEM0EXTRA_OBJS) $(PROBLEM1EXTRA_EXEC): $(PROBLEM1EXTRA_OBJS) Makefile $(CXX) $(CXXFLAGS) -o $(PROBLEM1EXTRA_EXEC) $(PROBLEM1EXTRA_OBJS) # Rules to build object files from source files, with dependency on the Common.h header %.o: %.cpp %.h Makefile $(CXX) $(CXXFLAGS) -c $< -o $@ Loading tests/extraTestsProb0.cpp 0 → 100644 +147 −0 Original line number Diff line number Diff line #include <iostream> using namespace std; #define PROB_0A 8.0 #define PROB_0B 12.0 #define PROB_0C 12.0 // prototype definitions int Hamming(unsigned long aa, unsigned long bb); long tau(long nn); int primorial(int nn); int test_0a(){ float total = PROB_0A; int case0 = Hamming(0, 0); // = 0 int case1 = Hamming(5, 4); // = 1 int case2 = Hamming(17, 26); // = 3 int case3 = Hamming(4294967295, 0); // = 32 int case4 = Hamming(3725, 845); // = 9 if (case0 != 0){ cout << "-1: Hamming(0,0) = 0, but your function returned Hamming(0, 0) = " << case0 << endl; total -= 1; } if (case1 != 1){ cout << "-1: Hamming(5,4) = 1, but your function returned Hamming(5, 4) = " << case1 << endl; total -= 1; } if (case2 != 3){ cout << "-1: Hamming(17,26) = 3, but your function returned Hamming(17, 26) = " << case2 << endl; total -= 1; } if (case3 != 32){ cout << "-1: Hamming(4294967295,0) = 32, but your function returned Hamming(4294967295,0) = " << case3 << endl; total -= 2.5; } if (case4 != 9){ cout << "-1: Hamming(3725,845) = 59, but your function returned Hamming(3725,845) = " << case4 << endl; total -= 2.5; } //Returns total points earned for this problem return total; } float test_0b() { float total = PROB_0B; int case0 = tau(7); // = 7 int case1 = tau(113); // = 113 int case2 = tau(15); // = 8 int case3 = tau(117649); // = 42 int case4 = tau(69300); // = 38 if (case0 != 7){ cout << "-1: tau(7) = 7, but your function returned tau(7) = " << case0 << endl; total -= 2; } if (case1 != 113){ cout << "-1: tau(113) = 113, but your function returned tau(113) = " << case1 << endl; total -= 2; } if (case2 != 8){ cout << "-1: tau(15) = 8, but your function returned tau(15) = " << case2 << endl; total -= 2; } if (case3 != 42){ cout << "-1: tau(117649) = 42, but your function returned tau(117649) = " << case3 << endl; total -= 3; } if (case4 != 38){ cout << "-1: tau(69300) = 38, but your function returned tau(69300) = " << case4 << endl; total -= 3; } //Returns total points earned for this problem return total; } float test_0c() { float total = PROB_0C; int case0 = primorial(2); // = 2 int case1 = primorial(5); // = 30 int case2 = primorial(12); // = 2310 int case3 = primorial(25); // = 92870 int case4 = primorial(100); // = 56070 if (case0 != 2){ cout << "-1: primorial(2) = 2, but your function returned primorial(2) = " << case0 << endl; total -= 3; } if (case1 != 30){ cout << "-1: primorial(5) = 30, but your function returned primorial(5) = " << case1 << endl; total -= 3; } if (case2 != 2310){ cout << "-1: primorial(12) = 2310, but your function returned primorial(12) = " << case2 << endl; total -= 3; } if (case3 != 92870){ cout << "-1: primorial(25) = 92870, but your function returned primorial(25) = " << case3 << endl; total -= 3; } if (case4 != 56070){ cout << "-1: primorial(100) = 56070, but your function returned primorial(100) = " << case4 << endl; total -= 3; } return total; } int main() { float t0a = test_0a(); float t0b = test_0b(); float t0c = test_0c(); cout << "Score problem 0a: " << t0a << "/8.0" << endl; cout << "Score problem 0b: " << t0c << "/12.0" << endl; cout << "Score problem 0c: " << t0a << "/12.0" << endl; if (t0a && t0b && t0c) { // all tests passed exit(0); } else { // at least one test was failed exit (-1); } } No newline at end of file Loading
CMakeLists.txt +8 −0 Original line number Diff line number Diff line Loading @@ -15,3 +15,11 @@ add_executable(problem1 tests/testProblem1.cpp tests/testProblem1.cpp ) add_executable(problem0extra tests/extraTestsProb0.cpp ) add_executable(problem1 tests/extraTestsProb1.cpp )
ci_cd/problem0.yml +15 −1 Original line number Diff line number Diff line Loading @@ -68,3 +68,17 @@ internal_testing_problem_0: - cat homework-two-internal/internal_tests/output.txt tags: [c++-17] timeout: 10m HW1_Problem0_TestCase: stage: problem0 script: - echo "Grading HW1 Problem 0"; - git clone https://agile.bu.edu/gitlab/configs/ec327/hw-configs/hw2.git base_0 - cp problem0.cpp base_0/tests - cd base_0/tests - make problem0extra - ./problem0extra rules: - if: '$CI_COMMIT_REF_NAME == "problem0"' tags: [c++-17] timeout: 5m No newline at end of file
tests/Makefile +15 −3 Original line number Diff line number Diff line Loading @@ -7,19 +7,25 @@ CXXFLAGS = -Wall -std=c++17 # Source files PROBLEM0_SRCS = testProblem0.cpp problem0.cpp PROBLEM1_SRCS = testProblem1.cpp problem1.cpp SRCS = $(PROBLEM0_SRCS) $(PROBLEM1_SRCS) PROBLEM0EXTRA_SRCS = extraTestsProb0.cpp problem0.cpp PROBLEM1EXTRA_SRCS = extraTestsProb1.cpp problem1.cpp SRCS = $(PROBLEM0_SRCS) $(PROBLEM1_SRCS) $(PROBLEM0EXTRA_SRCS) $(PROBLEM1EXTRA_SRCS) # Object files PROBLEM0_OBJS = testProblem0.o problem0.o PROBLEM1_OBJS = testProblem1.o problem1.o OBJS = $(PROBLEM0_OBJS) $(PROBLEM1_OBJS) PROBLEM0EXTRA_OBJS = extraTestsProb0.o problem0.o PROBLEM1EXTRA_OBJS = extraTestsProb1.o problem1.o OBJS = $(PROBLEM0_OBJS) $(PROBLEM1_OBJS) $(PROBLEM0EXTRA_OBJS) $(PROBLEM1EXTRA_OBJS) # Executable names PROBLEM0_EXEC = problem0 PROBLEM1_EXEC = problem1 PROBLEM0EXTRA_EXEC = problem0extra PROBLEM1EXTRA_EXEC = problem1extra # Default target to build the executable all: $(PROBLEM0_EXEC) $(PROBLEM1_EXEC) all: $(PROBLEM0_EXEC) $(PROBLEM1_EXEC) $(PROBLEM0EXTRA_EXEC) $(PROBLEM1EXTRA_EXEC) # Rule to build the executable from object files $(PROBLEM0_EXEC): $(PROBLEM0_OBJS) Makefile Loading @@ -28,6 +34,12 @@ $(PROBLEM0_EXEC): $(PROBLEM0_OBJS) Makefile $(PROBLEM1_EXEC): $(PROBLEM1_OBJS) Makefile $(CXX) $(CXXFLAGS) -o $(PROBLEM1_EXEC) $(PROBLEM1_OBJS) $(PROBLEM0EXTRA_EXEC): $(PROBLEM0EXTRA_OBJS) Makefile $(CXX) $(CXXFLAGS) -o $(PROBLEM0EXTRA_EXEC) $(PROBLEM0EXTRA_OBJS) $(PROBLEM1EXTRA_EXEC): $(PROBLEM1EXTRA_OBJS) Makefile $(CXX) $(CXXFLAGS) -o $(PROBLEM1EXTRA_EXEC) $(PROBLEM1EXTRA_OBJS) # Rules to build object files from source files, with dependency on the Common.h header %.o: %.cpp %.h Makefile $(CXX) $(CXXFLAGS) -c $< -o $@ Loading
tests/extraTestsProb0.cpp 0 → 100644 +147 −0 Original line number Diff line number Diff line #include <iostream> using namespace std; #define PROB_0A 8.0 #define PROB_0B 12.0 #define PROB_0C 12.0 // prototype definitions int Hamming(unsigned long aa, unsigned long bb); long tau(long nn); int primorial(int nn); int test_0a(){ float total = PROB_0A; int case0 = Hamming(0, 0); // = 0 int case1 = Hamming(5, 4); // = 1 int case2 = Hamming(17, 26); // = 3 int case3 = Hamming(4294967295, 0); // = 32 int case4 = Hamming(3725, 845); // = 9 if (case0 != 0){ cout << "-1: Hamming(0,0) = 0, but your function returned Hamming(0, 0) = " << case0 << endl; total -= 1; } if (case1 != 1){ cout << "-1: Hamming(5,4) = 1, but your function returned Hamming(5, 4) = " << case1 << endl; total -= 1; } if (case2 != 3){ cout << "-1: Hamming(17,26) = 3, but your function returned Hamming(17, 26) = " << case2 << endl; total -= 1; } if (case3 != 32){ cout << "-1: Hamming(4294967295,0) = 32, but your function returned Hamming(4294967295,0) = " << case3 << endl; total -= 2.5; } if (case4 != 9){ cout << "-1: Hamming(3725,845) = 59, but your function returned Hamming(3725,845) = " << case4 << endl; total -= 2.5; } //Returns total points earned for this problem return total; } float test_0b() { float total = PROB_0B; int case0 = tau(7); // = 7 int case1 = tau(113); // = 113 int case2 = tau(15); // = 8 int case3 = tau(117649); // = 42 int case4 = tau(69300); // = 38 if (case0 != 7){ cout << "-1: tau(7) = 7, but your function returned tau(7) = " << case0 << endl; total -= 2; } if (case1 != 113){ cout << "-1: tau(113) = 113, but your function returned tau(113) = " << case1 << endl; total -= 2; } if (case2 != 8){ cout << "-1: tau(15) = 8, but your function returned tau(15) = " << case2 << endl; total -= 2; } if (case3 != 42){ cout << "-1: tau(117649) = 42, but your function returned tau(117649) = " << case3 << endl; total -= 3; } if (case4 != 38){ cout << "-1: tau(69300) = 38, but your function returned tau(69300) = " << case4 << endl; total -= 3; } //Returns total points earned for this problem return total; } float test_0c() { float total = PROB_0C; int case0 = primorial(2); // = 2 int case1 = primorial(5); // = 30 int case2 = primorial(12); // = 2310 int case3 = primorial(25); // = 92870 int case4 = primorial(100); // = 56070 if (case0 != 2){ cout << "-1: primorial(2) = 2, but your function returned primorial(2) = " << case0 << endl; total -= 3; } if (case1 != 30){ cout << "-1: primorial(5) = 30, but your function returned primorial(5) = " << case1 << endl; total -= 3; } if (case2 != 2310){ cout << "-1: primorial(12) = 2310, but your function returned primorial(12) = " << case2 << endl; total -= 3; } if (case3 != 92870){ cout << "-1: primorial(25) = 92870, but your function returned primorial(25) = " << case3 << endl; total -= 3; } if (case4 != 56070){ cout << "-1: primorial(100) = 56070, but your function returned primorial(100) = " << case4 << endl; total -= 3; } return total; } int main() { float t0a = test_0a(); float t0b = test_0b(); float t0c = test_0c(); cout << "Score problem 0a: " << t0a << "/8.0" << endl; cout << "Score problem 0b: " << t0c << "/12.0" << endl; cout << "Score problem 0c: " << t0a << "/12.0" << endl; if (t0a && t0b && t0c) { // all tests passed exit(0); } else { // at least one test was failed exit (-1); } } No newline at end of file