Commit 96d6a3d5 authored by James Knee's avatar James Knee
Browse files

lab5 basic tests

parent 35c22609
Loading
Loading
Loading
Loading

tests/LabFive.cpp

0 → 100644
+84 −0
Original line number Diff line number Diff line
#include <iostream>
#include <stdexcept>
#include <string>

#include "lab5.cpp"

using namespace std;

bool testLogicError(Graph &g, int value) {
    try {
        // Call the student's function with input that should trigger the exception.
        g+=value;
    } catch (const logic_error& e) {
        return true; //if it returns logic error
    } catch (...) {
        return false;
    }

    return false;
}

bool test_labFive(){

    Graph G;

    if(testLogicError(G, 3)){
        cout << "Test 5a failed" << endl;
        return false;
    }

    if(testLogicError(G, 5)){
        cout << "Test 5b failed" << endl;
        return false;
    }

    if(!testLogicError(G, 3)){ //should throw a logic error
        cout << "Test 5c failed" << endl;
        return false;
    }

    if(G.hasEdge(3,5)){
        cout << "Test 5d failed" << endl;
        return false;
    } 

    G.addEdge(5,3);

    if(!G.hasEdge(3,5)){
        cout << "Test 5e failed" << endl;
        return false;
    }

    if(G[0] != 3){
        cout << "Test 5f failed" << endl;
        return false;
    }           
    
    if(G.numVertices() != 2){
        cout << "Test 5g failed" << endl;
        return false;
    }

    if(G.numEdges() != 1){
        cout << "Test 5h failed" << endl;
        return false;
    }

    // All tests passed
    return true;
}

int main(){
    
        bool t0 = test_labFive();
    
        cout << "Lab Five: " << (t0 ? "passed" : "failed") << endl;
    
        if (t0) { // all tests passed
            exit(0);  // passed
        } else {
            exit(1);  // failed
        }
}