Commit adcab4e2 authored by Ari Trachtenberg's avatar Ari Trachtenberg
Browse files

added preliminary tests

parent bbc2997d
Loading
Loading
Loading
Loading
+11 −5
Original line number Diff line number Diff line
stages:
  - noop
  - problem1
  - problem1a
  - problem1b
  - problem1c
  - problem1d
  - problem1e

do_nothing:
  stage: noop
  script:
    - echo "This job does nothing."
include:
  - local: 'ci_cd/problem1.yml'   # hw4, problem 1

default:
  timeout: 5m
 No newline at end of file

ci_cd/problem1.yml

0 → 100644
+80 −0
Original line number Diff line number Diff line
prebuild_problem1:
  stage: problem1

  script:
    - |
      # Check if source files exist
      if [ ! -f "GaussianInteger.cpp" ]; then
        echo "GaussianInteger.cpp does not exist";
        exit 1;
      fi
      if [ ! -f "GaussianInteger.h" ]; then
        echo "GaussianInteger.h does not exist";
        exit 1;
      fi
    - git clone https://agile.bu.edu/gitlab/configs/ec327/hw-configs/hw3.git base_4
  artifacts:
    paths:
      - base_4/
  tags: [shell]


test_problem_1a:
  stage: problem1a
  dependencies: prebuild_problem1
  script:
    - cp GaussianInteger.cpp GaussianInteger.h base_4/tests
    - cd base_4/tests
    - make problem1a
    - ./problem1a
  rules:
    - if: '$CI_COMMIT_REF_NAME == "1a"'
  tags: [c++-17]

test_problem_1b:
  stage: problem1b
  dependencies: prebuild_problem1
  script:
    - cp GaussianInteger.cpp GaussianInteger.h base_4/tests
    - cd base_4/tests
    - make problem1b
    - ./problem1b
  rules:
    - if: '$CI_COMMIT_REF_NAME == "1b"'
  tags: [c++-17]

test_problem_1c:
  stage: problem1c
  dependencies: prebuild_problem1
  script:
    - cp GaussianInteger.cpp GaussianInteger.h base_4/tests
    - cd base_4/tests
    - make problem1c
    - ./problem1c
  rules:
    - if: '$CI_COMMIT_REF_NAME == "1c"'
  tags: [c++-17]

test_problem_1d:
  stage: problem1d
  dependencies: prebuild_problem1
  script:
    - cp GaussianInteger.cpp GaussianInteger.h base_4/tests
    - cd base_4/tests
    - make problem1d
    - ./problem1d
  rules:
    - if: '$CI_COMMIT_REF_NAME == "1d"'
  tags: [c++-17]

test_problem_1e:
  stage: problem1e
  dependencies: prebuild_problem1
  script:
    - cp GaussianInteger.cpp GaussianInteger.h base_4/tests
    - cd base_4/tests
    - make problem1e
    - ./problem1e
  rules:
    - if: '$CI_COMMIT_REF_NAME == "1e"'
  tags: [c++-17]

tests/Makefile

0 → 100644
+40 −0
Original line number Diff line number Diff line
# Makefile, generated with support of ChatGPT

# Compiler and flags
CXX = g++
CXXFLAGS = -Wall -std=c++17

# Object files
PROBLEM1a_OBJS = testProblem1a.o GaussianInteger.o
PROBLEM1b_OBJS = testProblem1b.o GaussianInteger.o
PROBLEM1c_OBJS = testProblem1c.o GaussianInteger.o
PROBLEM1d_OBJS = testProblem1d.o GaussianInteger.o
PROBLEM1e_OBJS = testProblem1e.o GaussianInteger.o

# Executable names
PROBLEM1a_EXEC = problem1a
PROBLEM1b_EXEC = problem1b
PROBLEM1c_EXEC = problem1c
PROBLEM1d_EXEC = problem1d
PROBLEM1e_EXEC = problem1e

# Rule to build the executable from object files
$(PROBLEM1a_EXEC): $(PROBLEM1a_OBJS) Makefile
	$(CXX) $(CXXFLAGS) -o $(PROBLEM1a_EXEC) $(PROBLEM1a_OBJS)
$(PROBLEM1b_EXEC): $(PROBLEM1b_OBJS) Makefile
	$(CXX) $(CXXFLAGS) -o $(PROBLEM1b_EXEC) $(PROBLEM1b_OBJS)
$(PROBLEM1c_EXEC): $(PROBLEM1c_OBJS) Makefile
	$(CXX) $(CXXFLAGS) -o $(PROBLEM1c_EXEC) $(PROBLEM1c_OBJS)
$(PROBLEM1d_EXEC): $(PROBLEM1d_OBJS) Makefile
	$(CXX) $(CXXFLAGS) -o $(PROBLEM1d_EXEC) $(PROBLEM1d_OBJS)
$(PROBLEM1e_EXEC): $(PROBLEM1e_OBJS) Makefile
	$(CXX) $(CXXFLAGS) -o $(PROBLEM1e_EXEC) $(PROBLEM1e_OBJS)


# Rules to build object files from source files, with dependency on the Common.h header
%.o: %.cpp %.h Makefile
	$(CXX) $(CXXFLAGS) -c $< -o $@

# Clean target to remove compiled files
clean:
	rm -f $(OBJS) $(EXEC)
+34 −0
Original line number Diff line number Diff line
//
// Created by Ari on 10/19/24.
//


#include <iostream>
#include <string>
#include "GaussianInteger.h"
GaussianInteger sumPrimeFactors(GaussianInteger integer);
using namespace std;

bool test_1a() {
  GaussianInteger first;
  GaussianInteger second(1,3);
  GaussianInteger third(first);

  // if we got this far without crashing, we might be ok
  return true;
}

int main() {
  bool t1a = test_1a();

  cout << "Test (a) of problem 1: " << (t1a ? "passed" : "failed") << endl;

  if (t1a) {
    // all tests passed
    exit(0);
  }
  else {
    // at least one test was failed
    exit (-1);
  }
}
+55 −0
Original line number Diff line number Diff line
//
// Created by Ari on 10/19/24.
//


#include <iostream>
#include <string>
#include "GaussianInteger.h"
GaussianInteger sumPrimeFactors(GaussianInteger integer);
using namespace std;

bool test_1b() {
  GaussianInteger four(4,0);
  GaussianInteger two(2,0);
  if (!four.divides(two))
    return false;

  GaussianInteger onePlusI(1,1);
  if (!two.divides(onePlusI))
    return false;

  GaussianInteger twoPlusI(2,1);
  if (two.divides(twoPlusI))
    return false;

  if (onePlusI.norm() != 2)
    return false;

  GaussianInteger twoPlusThreeI(2,3);
  string printed = twoPlusThreeI.print();
  if (printed.find("2")==string::npos) // look for "2"
    return false;
  if (printed.find("3i")==string::npos) // look for "3i"
    return false;

  // if we got this far, we're ok
  return true;
}


int main() {
  bool t1b = test_1b();

  cout << "Test (b) of problem 1: " << (t1b ? "passed" : "failed") << endl;


  if (t1b) {
    // all tests passed
    exit(0);
  }
  else {
    // at least one test was failed
    exit (-1);
  }
}
Loading