From fc38cea1f51c9a3d73ddc7de750e017078f5471e Mon Sep 17 00:00:00 2001 From: Rayan Syed Date: Sat, 14 Feb 2026 17:38:24 -0500 Subject: [PATCH 1/2] more tests --- tests/Makefile | 18 ++++-- tests/testMoreBinPrime.cpp | 69 ++++++++++++++++++++++ tests/testMoreIntegerPP.cpp | 110 ++++++++++++++++++++++++++++++++++++ 3 files changed, 193 insertions(+), 4 deletions(-) create mode 100644 tests/testMoreBinPrime.cpp create mode 100644 tests/testMoreIntegerPP.cpp diff --git a/tests/Makefile b/tests/Makefile index 4439336..32aaa6e 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -7,26 +7,36 @@ CXXFLAGS = -std=c++17 # Source files PROBLEM0_SRCS = testIntegerPP.cpp IntegerPP.cpp IntegerP.cpp BigNum.cpp PROBLEM1_SRCS = testBinPrime.cpp binPrime.cpp IntegerPP.cpp IntegerP.cpp BigNum.cpp -SRCS = $(PROBLEM0_SRCS) $(PROBLEM1_SRCS) +MORE_PROBLEM0_SRCS = testMoreIntegerPP.cpp IntegerPP.cpp IntegerP.cpp BigNum.cpp +MORE_PROBLEM1_SRCS = testMoreBinPrime.cpp binPrime.cpp IntegerPP.cpp IntegerP.cpp BigNum.cpp +SRCS = $(PROBLEM0_SRCS) $(PROBLEM1_SRCS) $(MORE_PROBLEM0_SRCS) $(MORE_PROBLEM1_SRCS) # Object files PROBLEM0_OBJS = testIntegerPP.o IntegerPP.o IntegerP.o BigNum.o PROBLEM1_OBJS = testBinPrime.o binPrime.o IntegerPP.o IntegerP.o BigNum.o -OBJS = $(PROBLEM0_OBJS) $(PROBLEM1_OBJS) +MORE_PROBLEM0_OBJS = testMoreIntegerPP.o IntegerPP.o IntegerP.o BigNum.o +MORE_PROBLEM1_OBJS = testMoreBinPrime.o binPrime.o IntegerPP.o IntegerP.o BigNum.o +OBJS = $(PROBLEM0_OBJS) $(PROBLEM1_OBJS) $(MORE_PROBLEM0_OBJS) $(MORE_PROBLEM1_OBJS) # Executable names PROBLEM0_EXEC = problem2a PROBLEM1_EXEC = problem2b -EXECS = $(PROBLEM0_EXEC) $(PROBLEM1_EXEC) +MORE_PROBLEM0_EXEC = more2a +MORE_PROBLEM1_EXEC = more2b +EXECS = $(PROBLEM0_EXEC) $(PROBLEM1_EXEC) $(MORE_PROBLEM0_EXEC) $(MORE_PROBLEM1_EXEC) # Default target to build the executable -all: $(PROBLEM0_EXEC) $(PROBLEM1_EXEC) +all: $(PROBLEM0_EXEC) $(PROBLEM1_EXEC) $(MORE_PROBLEM0_EXEC) $(MORE_PROBLEM1_EXEC) # Rule to build the executable from object files $(PROBLEM0_EXEC): $(PROBLEM0_OBJS) Makefile $(CXX) $(CXXFLAGS) -o $(PROBLEM0_EXEC) $(PROBLEM0_OBJS) $(PROBLEM1_EXEC): $(PROBLEM1_OBJS) Makefile $(CXX) $(CXXFLAGS) -o $(PROBLEM1_EXEC) $(PROBLEM1_OBJS) +$(MORE_PROBLEM0_EXEC): $(MORE_PROBLEM0_OBJS) Makefile + $(CXX) $(CXXFLAGS) -o $(MORE_PROBLEM0_EXEC) $(MORE_PROBLEM0_OBJS) +$(MORE_PROBLEM1_EXEC): $(MORE_PROBLEM1_OBJS) Makefile + $(CXX) $(CXXFLAGS) -o $(MORE_PROBLEM1_EXEC) $(MORE_PROBLEM1_OBJS) # Rules to build object files from source files, with dependency on the Common.h header %.o: %.cpp Makefile diff --git a/tests/testMoreBinPrime.cpp b/tests/testMoreBinPrime.cpp new file mode 100644 index 0000000..62b52ac --- /dev/null +++ b/tests/testMoreBinPrime.cpp @@ -0,0 +1,69 @@ +// Developed by Rayan 2/13/2026, adapted from Kevin's testMoreIntegerP.cpp +#include +#include +#include + +#include "BigNum.h" + +using namespace std; + +const float PTS = 1.25; +float total = 0; + +BigNum binPrime(const int pascalRow); + +/** + * If expected == actual, increments the total by points. Prints out information about what happened + * @param category The category of test + * @param test The specific test + * @param expected Expected outcome + * @param actual Actual outcome + * @param points Points for a correct response. + */ +template +void scoreExample(string category, string test, T expected, T actual, float points) { + string score; + if (expected == actual) { + score = "CORRECT! +" + to_string(points); + total += points; + } + else { + score = "incorrect: +0"; + } + cout << category << " - " << test << ": " << score << endl; +} + +static string bnToString(const BigNum& x) { + std::ostringstream oss; + oss << x; + return oss.str(); +} + +// -------------------- Regression: assignment examples -------------------- +void test_a() { + const char* TEST_CATEGORY = "Regression: assignment examples"; + + scoreExample(TEST_CATEGORY, "binPrime(2) == 1", string("1"), bnToString(binPrime(2)), PTS); + scoreExample(TEST_CATEGORY, "binPrime(4) == 10", string("10"), bnToString(binPrime(4)), PTS); + scoreExample(TEST_CATEGORY, "binPrime(7) == 78", string("78"), bnToString(binPrime(7)), PTS); +} + +// -------------------- Regression: known small rows -------------------- +void test_b() { + const char* TEST_CATEGORY = "Regression: known small rows"; + + scoreExample(TEST_CATEGORY, "binPrime(3) == 4", string("4"), bnToString(binPrime(3)), PTS); + scoreExample(TEST_CATEGORY, "binPrime(5) == 21", string("21"), bnToString(binPrime(5)), PTS); + scoreExample(TEST_CATEGORY, "binPrime(6) == 41", string("41"), bnToString(binPrime(6)), PTS); + scoreExample(TEST_CATEGORY, "binPrime(8) == 148", string("148"), bnToString(binPrime(8)), PTS); + scoreExample(TEST_CATEGORY, "binPrime(9) == 282", string("282"), bnToString(binPrime(9)), PTS); +} + +int main() { + test_a(); + test_b(); + + cout << "Total points: " << total << endl; + cout << total << endl; // for the score recorder in the gitlab job + return 0; +} diff --git a/tests/testMoreIntegerPP.cpp b/tests/testMoreIntegerPP.cpp new file mode 100644 index 0000000..385a241 --- /dev/null +++ b/tests/testMoreIntegerPP.cpp @@ -0,0 +1,110 @@ +// Developed by Rayan 2/13/2026, adapted from Kevin's testMoreIntegerP.cpp +#include +#include +#include + +#include "IntegerPP.h" +#include "BigNum.h" + +using namespace std; + +const float PTS = 3.0; +float total = 0; + +/** + * If expected == actual, increments the total by points. Prints out information about what happened + * @param category The category of test + * @param test The specific test + * @param expected Expected outcome + * @param actual Actual outcome + * @param points Points for a correct response. + */ +template +void scoreExample(string category, string test, T expected, T actual, float points) { + string score; + if (expected == actual) { + score = "CORRECT! +" + to_string(points); + total += points; + } else { + score = "incorrect: +0"; + } + cout << category << " - " << test << ": " << score << endl; +} + +// helper: BigNum -> string +static string bnToString(const BigNum& x) { + std::ostringstream oss; + oss << x; + return oss.str(); +} + +// -------------------- Corner cases: multiple representations of 1 -------------------- +void test_a() { + const string CAT = "Corner: multiple representations of 1 (IntegerPP)"; + + IntegerPP one_default; // should represent 1 + IntegerPP one_zero_list({0}); // also 1 mathematically (different internal basis) + IntegerPP one_many_zeros({0,0,0}); // also 1 + IntegerPP one_from_bn(BigNum(1UL)); + + scoreExample(CAT, "default one -> BigNum == 1", string("1"), bnToString((BigNum)one_default), PTS); + scoreExample(CAT, "IntegerPP({0}) -> BigNum == 1", string("1"), bnToString((BigNum)one_zero_list), PTS); + scoreExample(CAT, "IntegerPP({0,0,0}) -> BigNum == 1", string("1"), bnToString((BigNum)one_many_zeros), PTS); + scoreExample(CAT, "IntegerPP(BigNum(1)) -> BigNum == 1", string("1"), bnToString((BigNum)one_from_bn), PTS); +} + +// -------------------- Corner cases: identity element via * and / with 1 -------------------- +void test_b() { + const string CAT = "Corner: identity via * and / with 1 (IntegerPP)"; + + IntegerPP one_default; // 1 + IntegerPP one_zero_list({0}); // 1 + IntegerPP x(30UL); // 30 = 2*3*5 + + // operator* and operator/ are inherited from IntegerP (return IntegerP), then lift to IntegerPP + IntegerPP p1 = IntegerPP(static_cast(x) * static_cast(one_default)); + IntegerPP q2 = IntegerPP(static_cast(x) / static_cast(one_zero_list)); + + scoreExample(CAT, "x*one_default -> BigNum == 30", string("30"), bnToString((BigNum)p1), PTS); + scoreExample(CAT, "x/{0} -> BigNum == 30", string("30"), bnToString((BigNum)q2), PTS); +} + +// -------------------- Corner cases: BigNum round-trip (factor + rebuild) -------------------- +void test_c() { + const string CAT = "Corner: BigNum round-trip (IntegerPP)"; + + BigNum a(2928UL); + IntegerPP ip_a(a); + scoreExample(CAT, "BigNum(2928) -> IntegerPP -> BigNum == 2928", string("2928"), bnToString((BigNum)ip_a), PTS); + + BigNum b(5184UL); // 2^6 * 3^4 = 5184 + IntegerPP ip_b(b); + scoreExample(CAT, "BigNum(5184) -> IntegerPP -> BigNum == 5184", string("5184"), bnToString((BigNum)ip_b), PTS); +} + +// -------------------- Corner cases: operator+ and operator= -------------------- +void test_d() { + const string CAT = "Corner: + and = (IntegerPP)"; + + // regression: the spec example + IntegerPP got = IntegerPP({1,1}) + IntegerPP({1,0,0,1}); // 6 + 14 = 20 + scoreExample(CAT, "{1,1}+{1,0,0,1} -> BigNum == 20", string("20"), bnToString((BigNum)got), PTS); + + // assignment should copy representation correctly + IntegerPP a(42UL); + IntegerPP b(1UL); + b = a; + scoreExample(CAT, "b=a; -> b BigNum == 42", string("42"), bnToString((BigNum)b), PTS); +} + +int main() { + test_a(); // 4 tests + test_b(); // 2 tests + test_c(); // 2 tests + test_d(); // 2 tests + // total = 10 tests * 3.0 = 30 points + + cout << "Total points: " << total << endl; + cout << total << endl; // for the score recorder in the gitlab job + return 0; +} -- GitLab From 6e4f808d41d99589fcf4b19c556663f06a4c6316 Mon Sep 17 00:00:00 2001 From: Rayan Syed Date: Sat, 14 Feb 2026 18:07:41 -0500 Subject: [PATCH 2/2] updated pipeline --- ci_cd/.gitlab-ci.yml | 1 + ci_cd/problem2a.yml | 19 +++++++++++++++++++ ci_cd/problem2b.yml | 18 ++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/ci_cd/.gitlab-ci.yml b/ci_cd/.gitlab-ci.yml index 0cd9a5e..cf35f0c 100644 --- a/ci_cd/.gitlab-ci.yml +++ b/ci_cd/.gitlab-ci.yml @@ -3,6 +3,7 @@ stages: - compile - test - extra + - internal include: - local: 'ci_cd/problem2a.yml' # IntegerPP diff --git a/ci_cd/problem2a.yml b/ci_cd/problem2a.yml index 53accdf..3f180cb 100644 --- a/ci_cd/problem2a.yml +++ b/ci_cd/problem2a.yml @@ -72,8 +72,27 @@ extra_credit: - echo "Your score is $score" - curl "https://agile.bu.edu/ec330_scripts/saveScores.pl?key=${MAGIC_KEY}&file=hw1extra&name=${GITLAB_USER_LOGIN}&score=${score}" rules: + - if: '$INTERNAL_TESTS == "1"' + when: never - if: '$CI_COMMIT_REF_NAME == "problem2a"' timeout: 2m # tags: [c++-17-light] tags: [c++-17] +more_integerpp: + stage: internal + needs: + - job: compile_problem_2a + artifacts: true + script: + - cd hw1/tests + - make more2a + - $(./more2a > more2a.txt) + - score="$(cat more2a.txt | tail -n 1 | tr -d '[:space:]')" + - echo "$(cat more2a.txt)" + - echo "Your score is $score" + - STUDENT="$(echo "$CI_PROJECT_PATH" | sed -E 's#.*/HomeworkOne##')" + - curl "https://agile.bu.edu/ec330_scripts/saveScores.pl?key=${MAGIC_KEY}&file=hw1_more2a&name=${STUDENT}&score=${score}" # log the score for easy grading + rules: + - if: '$CI_COMMIT_REF_NAME == "problem2a"' + tags: [ c++-17 ] diff --git a/ci_cd/problem2b.yml b/ci_cd/problem2b.yml index 6bec85e..5b1d290 100644 --- a/ci_cd/problem2b.yml +++ b/ci_cd/problem2b.yml @@ -45,3 +45,21 @@ exec_problem_2b: rules: - if: '$CI_COMMIT_REF_NAME == "problem2b"' tags: [c++-17] + +more_binprime: + stage: internal + needs: + - job: compile_problem_2b + artifacts: true + script: + - cd hw1/tests + - make more2b + - $(./more2b > more2b.txt) + - score="$(cat more2b.txt | tail -n 1 | tr -d '[:space:]')" + - echo "$(cat more2b.txt)" + - echo "Your score is $score" + - STUDENT="$(echo "$CI_PROJECT_PATH" | sed -E 's#.*/HomeworkOne##')" + - curl "https://agile.bu.edu/ec330_scripts/saveScores.pl?key=${MAGIC_KEY}&file=hw1_more2b&name=${STUDENT}&score=${score}" # log the score for easy grading + rules: + - if: '$CI_COMMIT_REF_NAME == "problem2b"' + tags: [ c++-17 ] -- GitLab