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

Merge branch 'lab4tests' into 'master'

lab4 basic tests

See merge request !10
parents d8b1bd1a cea088d2
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ stages:
  - lab1
  - lab2
  - lab3
  - lab4
  - tests

include:
@@ -12,3 +13,4 @@ include:
  - local: 'ci_cd/lab1.yml'    # Lab 1
  - local: 'ci_cd/lab2.yml'    # Lab 2
  - local: 'ci_cd/lab3.yml'    # Lab 3
  - local: 'ci_cd/lab4.yml'    # Lab 4
 No newline at end of file

ci_cd/lab4.yml

0 → 100644
+98 −0
Original line number Diff line number Diff line
### Lab 4
prebuild_lab_4:
  stage: lab4
  script:
    - echo "Changes Detected (if any):";
    - git diff --name-only $CI_COMMIT_SHA~ $CI_COMMIT_SHA || echo "No changes found";
    - FILES_ADDED=$(git diff --name-only --diff-filter=A HEAD~1 | wc -l)
    - |
    
      # Check if lab4.cpp exists
      if [ ! -f "lab4.cpp" ]; then
        echo "lab4.cpp does not exist";
        exit 1;
      fi

      # Check that only one file was checked in
      if [ "FILES_ADDED" -ne 1 ]; then
        echo "Error: Only one file should be committed.";
        exit 1;
      fi
      
      # Check if lab3.cpp has been merged into master
      if git ls-tree -r origin/master --name-only | grep -q 'lab3.cpp'; then
        echo "Lab 3 complete";
      else
        echo "Please have lab 3 merged first";
        exit 1;
      fi
    - git clone https://agile.bu.edu/gitlab/configs/ec327/lab-configs/current.git base_4
  artifacts:
    paths:
      - base_4
  rules:
    - if: '$CI_COMMIT_REF_NAME == "lab4"'
  tags: [c++-17]

prebuild_lab_4_SKIP:
  stage: lab4
  script:
    - echo "SKIPPING Lab 4 checks because the branch name is not 'lab4'"
  rules:
    - if: '$CI_COMMIT_REF_NAME != "lab4"'
  tags: [c++-17]

compile_lab_4:
  stage: lab4
  script:
    - echo "Compiling lab4.cpp"
    - g++ -c lab4.cpp
  artifacts:
    paths:
      - base_4
  dependencies:
    - prebuild_lab_4
  rules:
    - if: '$CI_COMMIT_REF_NAME == "lab4"'
  tags: [c++-17]

lint_lab_4:
  stage: lab4
  script:
    - echo "Static code check of lab4.cpp"
    - cppcheck --check-config --enable=all --inconclusive --error-exitcode=1 lab4.cpp tests/LabFour.cpp
  allow_failure: false
  artifacts:
    paths:
      - base_4
  dependencies:
    - prebuild_lab_4
  rules:
    - if: '$CI_COMMIT_REF_NAME == "lab4"'
  tags: [cppcheck]

test_lab_4:
  stage: lab4
  script:
    - echo "Testing Lab 4";
    - git clone https://agile.bu.edu/gitlab/configs/ec327/lab-configs/current.git base_4
    - cp lab4.cpp base_4/tests
    - cd base_4/tests
    - make lab4
  dependencies:
    - compile_lab_4
  rules:
    - if: '$CI_COMMIT_REF_NAME == "lab4"'
  tags: [c++-17]

# trigger internal tests only upon a merge request into master
internal_tests_lab_4:
 stage: tests
 script:
   - git clone https://trachten-gitlab:$INTERNAL_LAB_TESTS@agile.bu.edu/gitlab/ec327/ec327-staff/lab-tests.git
   - cp -f lab4.cpp lab-tests/internal_tests/
   - cd lab-tests/internal_tests
   - make lab4
 rules:
   - if: '$CI_COMMIT_REF_NAME == "lab4" && $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"'
 tags: [ c++-17 ]
+1 −1
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ using namespace std;
 * labFour_pZero_Person Jim("James");
 * Jim.setBirthday("2010-02-28"); // Jim's birthday is on February 28, 2010
 * labFour_pZero_Student Jane("Jane","2020-03-15");
 * Jane.setMajor(COMPUTER_ENGINEERING);
 * Jane.setMajor("COMPUTER_ENGINEERING");
 * labFour_pZero_Instructor Gabi("Gabriella");
 * Gabi.setBirthday("2000-01-03");
 * Gabi.setSalary(100000); // $100,000 per year

tests/LabFour.cpp

0 → 100644
+243 −0
Original line number Diff line number Diff line
/**
** Created by James Knee on 11/17/2024
** With help from ChatGPT
*/


#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <sstream>

#include "Support/Common.h"

#include "lab4.cpp"

using namespace std;

bool test_labFour_pZero(){
    labFour_pZero_Person person1("James");
    person1.setBirthday("2010-02-28");
    labFour_pZero_Student person2("Jane","2020-03-15");
    person2.setMajor("COMPUTER_ENGINEERING");
    labFour_pZero_Instructor person3("Gabi");
    person3.setBirthday("2000-01-03");
    person3.setSalary(100000);

    labFour_pZero_Person person4;
    labFour_pZero_Student person5;
    labFour_pZero_Instructor person6;

    stringstream input0("Pleiade 2004-02-26");
    stringstream input1("Jake 2000-11-22 Computer_Science");
    stringstream input2("Olivia 2000-01-30 123456");

    input0 >> person4;
    input1 >> person5;
    input2 >> person6;

    Common::redirIO();
    cout << person4;
    string output0 = Common::restoreIO();

    Common::redirIO();
    cout << person5;
    string output1 = Common::restoreIO();

    Common::redirIO();
    cout << person6;
    string output2 = Common::restoreIO();

    if(person1.getName() != "James"){
        cout << "Test 0a failed" << endl;
        return false;
    }

    if(person1.getBirthday() != "2010-02-28"){
        cout << "Test 0b failed" << endl;
        return false;
    }

    if(person2.getName() != "Jane"){
        cout << "Test 0c failed" << endl;
        return false;
    }

    if(person2.getBirthday() != "2020-03-15"){
        cout << "Test 0d failed" << endl;
        return false;
    }

    if(person2.getMajor() != "COMPUTER_ENGINEERING"){
        cout << "Test 0e failed" << endl;
        return false;
    }

    if(person3.getName() != "Gabi"){
        cout << "Test 0f failed" << endl;
        return false;
    }

    if(person3.getBirthday() != "2000-01-03"){
        cout << "Test 0g failed" << endl;
        return false;
    }

    if(person3.getSalary() != 100000){
        cout << "Test 0h failed" << endl;
        return false;
    }

    //Quick test of the << operators for each class
    //Since we don't have a specific way to format the output, we have to check it is included

    if(output0.find("Pleiade")==string::npos || output0.find("2004-02-26")==string::npos){
        cout << "Test 0i failed" << endl;
        return false;
    }

    if(output1.find("Jake")==string::npos || output1.find("2000-11-22")==string::npos || output1.find("Computer_Science")==string::npos){
        cout << "Test 0j failed" << endl;
        return false;
    }

    if(output2.find("Olivia")==string::npos || output2.find("2000-01-30")==string::npos || output2.find("123456")==string::npos){
        cout << "Test 0k failed" << endl;
        return false;
    }

    
    // All tests passed
    return true;
}

bool test_labFour_pOne(){
    labFour_pOne_Quadrilateral q1(
         {1, 1},
         {1, 2},
         {2, 2},
         {2, 1}); // area 1, perimeter 4
    labFour_pOne_Rectangle re1({0, 0}, 1, 2); // area 2, perimeter 6
    labFour_pOne_Square s1({1, 3}, 3); //area 9, perimeter 12
    labFour_pOne_Rhombus rh1({1, 1}, 1, 45); // area sqrt(2)/2, perimeter 4
    labFour_pOne_Circle c1({0, 0}, 1); // area pi, perimeter 2*pi

    vector<labFour_pOne_GeometricThing *> things = {&re1, &s1, &rh1, &c1};

    if(q1.getArea() != 1){
        cout << "Test 1a failed" << endl;
        return false;
    }

    if(q1.getPerimeter() != 4){
        cout << "Test 1b failed" << endl;
        return false;
    }

    if(re1.getArea() != 2){
        cout << "Test 1c failed" << endl;
        return false;
    }

    if(re1.getPerimeter() != 6){
        cout << "Test 1d failed" << endl;
        return false;
    }

    if(s1.getArea() != 9){
        cout << "Test 1e failed" << endl;
        return false;
    }

    if(s1.getPerimeter() != 12){
        cout << "Test 1f failed" << endl;
        return false;
    }

    if(rh1.getArea() != sqrt(2) / 2){
        cout << "Test 1g failed" << endl;
        return false;
    }

    if(rh1.getPerimeter() != 4){
        cout << "Test 1h failed" << endl;
        return false;
    }

    if(c1.getArea() != M_PI){
        cout << "Test 1i failed" << endl;
        return false;
    }

    if(c1.getPerimeter() != 2 * M_PI){
        cout << "Test 1j failed" << endl;
        return false;
    }

    if(labFour_pOne_GeometricThing::sumAreas(things) != 1 + 2 + 9 + sqrt(2) / 2 + M_PI){
        cout << "Test 1k failed" << endl;
        return false;
    }


    if(labFour_pOne_GeometricThing::sumPerimeters(things) != 4 + 6 + 12 + 4 + 2 * M_PI){
        cout << "Test 1l failed" << endl;
        return false;
    }

    // All tests passed
    return true;
}

bool test_labFour_pTwo(){

    if(labFour_pTwo_exchange(8) != 7){
        cout << "Test 2a failed" << endl;
        return false;
    }

    // All tests passed
    return true;
}


bool test_labFour_pThree(){

    if(labFour_pThree_genFib({1,1}, 3) != 8){
        cout << "Test 3a failed" << endl;
        return false;
    }

    if(labFour_pThree_genFib({1,0,1}, 4) != 9){
        cout << "Test 3b failed" << endl;
        return false;
    }

    if(labFour_pThree_genFib({0.25 ,0.25 ,0.5, 0.5}, 3) != 2.5625){
        cout << "Test 3c failed" << endl;
        return false;
    }

    // All tests passed
    return true;
}

int main() {

    bool t0 = test_labFour_pZero();
    bool t1 = test_labFour_pOne();
    bool t2 = test_labFour_pTwo();
    bool t3 = test_labFour_pThree();

    cout << "pZero: " << (t0 ? "passed" : "failed") << endl;
    cout << "pOne: " << (t1 ? "passed" : "failed") << endl;
    cout << "pTwo: " << (t2 ? "passed" : "failed") << endl;
    cout << "pThree: " << (t3 ? "passed" : "failed") << endl;

    if (t0 && t1 && t2 && t3) { // all tests passed
        exit(0);  // passed
    } else {
        exit(-1); // failed
    }
}
 No newline at end of file
+10 −3
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ LAB0_SRCS = LabZero.cpp lab0.cpp $(COMMON_SRCS)
LAB1_SRCS = LabOne.cpp lab1.cpp $(COMMON_SRCS)
LAB2_SRCS = LabTwo.cpp lab2.cpp
LAB3_SRCS = LabThree.cpp
LAB4_SRCS = LabFour.cpp

# Object files
COMM_OBJS = Support/Common.o
@@ -17,17 +18,19 @@ LAB0_OBJS = LabZero.o lab0.o $(COMM_OBJS)
LAB1_OBJS = LabOne.o lab1.o $(COMM_OBJS)
LAB2_OBJS = LabTwo.o lab2.o
LAB3_OBJS = LabThree.o
OBJS = $(COMM_OBJS) $(LAB0_OBJS) $(LAB1_OBJS) $(LAB2_OBJS) $(LAB3_OBJS)
LAB4_OBJS = LabFour.o
OBJS = $(COMM_OBJS) $(LAB0_OBJS) $(LAB1_OBJS) $(LAB2_OBJS) $(LAB3_OBJS) $(LAB4_OBJS)

# Executable names
LAB0_EXEC = lab0
LAB1_EXEC = lab1
LAB2_EXEC = lab2
LAB3_EXEC = lab3
EXEC = $(LAB0_EXEC) $(LAB1_EXEC) $(LAB2_EXEC) $(LAB3_EXEC)
LAB4_EXEC = lab4
EXEC = $(LAB0_EXEC) $(LAB1_EXEC) $(LAB2_EXEC) $(LAB3_EXEC) $(LAB4_EXEC)

# Default target to build the executable
all: $(LAB0_EXEC) $(LAB1_EXEC) $(LAB2_EXEC) $(LAB3_EXEC)
all: $(LAB0_EXEC) $(LAB1_EXEC) $(LAB2_EXEC) $(LAB3_EXEC) $(LAB4_EXEC)

# Rule to build the executable from object files
$(LAB0_EXEC): $(LAB0_OBJS) Makefile
@@ -47,6 +50,10 @@ $(LAB3_EXEC): $(LAB3_OBJS) Makefile lab3.cpp
	$(CXX) $(CXXFLAGS) -o $(LAB3_EXEC) $(LAB3_OBJS)
	./$(LAB3_EXEC)

$(LAB4_EXEC): $(LAB4_OBJS) Makefile lab4.cpp
	$(CXX) $(CXXFLAGS) -o $(LAB4_EXEC) $(LAB4_OBJS)
	./$(LAB4_EXEC)

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

File changed.

Contains only whitespace changes.

Loading