Commit 490b5404 authored by Ari Trachtenberg's avatar Ari Trachtenberg
Browse files

Adding basic testing

parent d9e80460
Loading
Loading
Loading
Loading
+11 −6
Original line number Diff line number Diff line
stages:
  - noop
  - prebuild
  - problem0a
  - problem0b
  - problem0c
  - problem1
  - problem2

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

default:
  timeout: 5m

ci_cd/problems.yml

0 → 100644
+122 −0
Original line number Diff line number Diff line
prebuild:
  stage: prebuild
  script:
    - git clone https://agile.bu.edu/gitlab/configs/ec327/hw-configs/hw5.git base_5
  artifacts:
    paths:
      - base_5/
  rules:
    - when: always
  tags: [c++-17]

test_problem0a:
  stage: problem0a
  dependencies:
    - prebuild
  script:
    - # Check if source files exist
    - if [ ! -f "oneA.cpp" ]; then
    - echo "oneA.cpp does not exist";
    - exit 1;
    - fi
    - # compile and run tests
    - cp oneA.cpp base_5/tests/0a
    - cd base_5/tests/0a
    - make problem0a
    - ./problem0a
  rules:
    - if: '$CI_COMMIT_REF_NAME == "0a"'
  tags: [c++-17]

test_problem0b:
  stage: problem0b
  dependencies:
    - prebuild
  script:
    - # Check if source files exist
    - if [ ! -f "SimpleLink.cpp" ]; then
    - echo "SimpleLink.cpp does not exist";
    - exit 1;
    - fi
    - # compile and run tests
    - cp SimpleLink.cpp base_5/tests/0b
    - cd base_5/tests/0b
    - make problem0b
    - ./problem0b
  rules:
    - if: '$CI_COMMIT_REF_NAME == "0b"'
  tags: [c++-17]

test_problem0c:
  stage: problem0c
  dependencies:
    - prebuild
  script:
    - # Check if source files exist
    - if [ ! -f "SimpleLink.cpp" ]; then
    - echo "SimpleLink.cpp does not exist";
    - exit 1;
    - fi
    - # compile and run tests
    - cp SimpleLink.cpp base_5/tests/0c
    - cd base_5/tests/0c
    - make problem0c
    - ./problem0c
  rules:
    - if: '$CI_COMMIT_REF_NAME == "0c"'
  artifacts:
    paths:
      - base_5/
      - SimpleLink.cpp
  tags: [ c++-17 ]

  test_problem1:
    stage: problem1
    dependencies:
      - problem0c
    script:
      - # Check if source files exist
      - if [ ! -f "SimpleLinkStr.h" ]; then
      - echo "SimpleLinkStr.h does not exist";
      - exit 1;
      - fi
      - if [ ! -f "SimpleLinkStr.cpp" ]; then
      - echo "SimpleLinkStr.cpp does not exist";
      - exit 1;
      - fi
      - # compile and run tests
      - cp SimpleLink.cpp base_5/tests/0c
      - cp SimpleLinkStr.h base_5/tests/0c
      - cp SimpleLinkStr.cpp base_5/tests/0c
      - cd base_5/tests/1
      - make problem1
      - ./problem1
    rules:
      - if: '$CI_COMMIT_REF_NAME == "1"'
    tags: [ c++-17 ]


test_problem2:
  stage: problem2
  dependencies:
    - problem0c
  script:
    - # Check if source files exist
    - if [ ! -f "DoubleLink.h" ]; then
    - echo "DoubleLink.h does not exist";
    - exit 1;
    - fi
    - if [ ! -f "DoubleLink.cpp" ]; then
    - echo "DoubleLink.cpp does not exist";
    - exit 1;
    - fi
    - # compile and run tests
    - cp SimpleLink.cpp base_5/tests/2
    - cp DoubleLink.cpp base_5/tests/2
    - cp DoubleLink.h base_5/tests/2
    - cd base_5/tests/2
    - make problem2
    - ./problem2
  rules:
    - if: '$CI_COMMIT_REF_NAME == "2"'
  tags: [ c++-17 ]
 No newline at end of file

tests/0a/Makefile

0 → 100644
+14 −0
Original line number Diff line number Diff line
# Compiler and flags
CXX = g++
CXXFLAGS = -Wall -std=c++17

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

problem0a: oneA.o testProblem0a.o
	$(CXX) $(CXXFLAGS) oneA.o testProblem0a.o -o problem0a

# Clean target to remove compiled files
clean:
	rm -f oneA.o testProblem0a.0 problem0a
 No newline at end of file

tests/0a/SimpleLink.h

0 → 100644
+47 −0
Original line number Diff line number Diff line
//
// Created by Ari on 10/26/24.
//

#ifndef HW5_SIMPLELINK_H
#define HW5_SIMPLELINK_H
/**
 * Implements a simple linked list, whose intPayload is an integer
 * and which is terminated by a nullptr.
 */
class SimpleLink {
 public:
  // CONSTRUCTORS

  /**
   * Creates a single link of a linked list, whose next pointer is nullptr.
   * @param theIntPayload The intPayload intended for this link.
   */
  SimpleLink(int theIntPayload = 0) : intPayload(theIntPayload), next(nullptr) {}

  /**
   * Creates a linked list whose ii-th link contains the intPayload in data[ii].
   * The list is terminated with a nullptr.
   * @param data An array of data to process into a linked list.
   * @param size The size of the data array.
   */
  SimpleLink(const int *const data, unsigned int size) : intPayload(data[0]) {
    if (size != 1)
      next = new SimpleLink(data + 1, size - 1); // recursively add the remaining list
    else  // this is the last link
      next = nullptr;
  }


  // ACCESSORS / GETTERS
  const int getIntPayload() const { return intPayload; }
  SimpleLink *getNext() const { return next; }

  // SETTERS
  void setIntPayload(int newPayload) { intPayload = newPayload; }
  void setNext(SimpleLink *item) { next = item; }

 protected:
  int intPayload;       // the intPayload stored in this link
  SimpleLink *next;  // the next link in the list
};
#endif //HW5_SIMPLELINK_H
+33 −0
Original line number Diff line number Diff line
//
// Created by Ari on 10/26/24.
//
#include <iostream>
#include <string>
using namespace std;

// forward declaration
int testSimpleLink();

bool test_0a() {
  int result=testSimpleLink();
  if (result<0 || result>9)
    return false;

  // all tests passed
  return true;
}

int main() {
  bool t0a = test_0a();

  cout << "Test (a) of problem 0: " << (t0a ? "passed" : "failed") << endl;

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