Skip to content
Snippets Groups Projects
Forked from Configs / EC327 / Labs / Current
166 commits behind the upstream repository.
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
LabZero.cpp 2.72 KiB
//
// Created by Ari Trachtenberg on 9/24.
//
//
// #include <iostream>
#include <string>

#include "../problems/LabZero_ChapterTwo.h"
#include "../problems/LabZero_ChapterThree.h"
#include "Support/Common.h"

using namespace std;

bool test_labZero_pZero() {
    Common::redirIO("1 2 90"); // redirect input
    labZero_pZero();
    float out = stof(Common::restoreIO());
    if (out * out > 1.99 && out * out < 2.01) {
        return true;
    } else {
        return false;
    }
}

bool test_labZero_pOne() {
    string out;

    // example 1
    Common::redirIO("0900\n1730\n");
    labZero_pOne();
    out = Common::restoreIO();
    if (out != "8 hours 30 minutes") {
        return false;
    }

    // example 2
    Common::redirIO("1730\n0900\n");
    labZero_pOne();
    out = Common::restoreIO();
    if (out != "15 hours 30 minutes") {
        return false;
    }

    // passed all tests
    return true;
}

bool test_labZero_pTwo() {
    Common::redirIO("123456");
    labZero_pTwo();
    int out = stoi(Common::restoreIO());
    if (out != 21)
        return false;

    return true;
}

bool test_labZero_pThree() {
    Common::redirIO("1 2 3 4");
    labZero_pThree();
    string out = Common::restoreIO();
    if (out != "in order")
        return false;

    return true;
}

bool test_labZero_pFour() {
    string out;
    // example 1
    Common::redirIO("0 0\n0 1\n1 0\n1 1\n");
    labZero_pFour();
    out = Common::restoreIO();
    if (out != "square")
        return false;

    // example 2
    Common::redirIO("0 0\n0 1\n2 0\n1 1\n");
    labZero_pFour();
    out = Common::restoreIO();
    if (out != "trapezoid")
        return false;

    return true;
}

bool test_labZero_pFive() {
    string out;

    // example 1
    Common::redirIO("14\n");
    labZero_pFive();
    out = Common::restoreIO();
    if (out != "XIV")
        return false;

    // example 2
    Common::redirIO("1978\n");
    labZero_pFive();
    out = Common::restoreIO();
    if (out != "MCMLXXVIII")
        return false;

    return true;
}


int main() {
    bool t0 = test_labZero_pZero();
    bool t1 = test_labZero_pOne();
    bool t2 = test_labZero_pTwo();
    bool t3 = test_labZero_pThree();
    bool t4 = test_labZero_pFour();
    bool t5 = test_labZero_pFive();

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

    if (t0 && t1 && t2 && t3 && t4 && t5) { // all tests passed
        exit(0);  // passed
    } else {
        exit(-1); // failed
    }
}