Commit 744ad102 authored by Ari Trachtenberg's avatar Ari Trachtenberg
Browse files

Merge branch 'more_tests' into 'master'

More tests

See merge request configs/ec330/homeworks/homeworkone!3
parents b84c0237 6e4f808d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ stages:
  - compile
  - test
  - extra
  - internal

include:
  - local: 'ci_cd/problem2a.yml'   # IntegerPP
+19 −0
Original line number Diff line number Diff line
@@ -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 ]
+18 −0
Original line number Diff line number Diff line
@@ -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 ]
+14 −4
Original line number Diff line number Diff line
@@ -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
+69 −0
Original line number Diff line number Diff line
// Developed by Rayan 2/13/2026, adapted from Kevin's testMoreIntegerP.cpp
#include <iostream>
#include <string>
#include <sstream>

#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 <typename T>
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;
}
Loading