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

Wroking on the test functions.

parent 894e20da
Loading
Loading
Loading
Loading
+39 −34
Original line number Diff line number Diff line
@@ -3,6 +3,8 @@
//

// Chapter 9
#include <string>
using namespace std;

/**
 * This class represents a student with the following properties:
@@ -20,9 +22,8 @@
 * student.addQuizScore(70);
 * Then student.getAverageScore() should return 80, the average of 100, 70, and 70.
 */
class labThree_pTwo {
    // fill this in here.
};
// please provide the implementation in your cpp file
class labThree_pTwo;


/**
@@ -32,9 +33,9 @@ class labThree_pTwo {
 * - It has member functions matching the signatures below.
 *
 * @example
 * labThree_pThree person1("Jim");
 * labThree_pThree person2("Jane");
 * labThree_pThree person3("Bob");
 * labThree_pThree person1 = labThree_pThree("Jim");
 * labThree_pThree person2 = labThree_pThree("Jane");
 * labThree_pThree person3 = labThree_pThree("Bob");
 *
 * person1.befriend(person2);
 * person1.befriend(person3);
@@ -47,11 +48,15 @@ class labThree_pTwo {
 * person1.getFriends() - returns "Jane, Bob"
 * person2.getFriends() - returns "Jim"
 *
 * person1.getFriendOfFreinds() - returns "Jim"
 * person2.getFriendOfFriends() - returns "Jane, Bob"
 * person1.getFriendsOfFriends() - returns "Jim"
 * person2.getFriendsOfFriends() - returns "Jane, Bob"
 *
 */

// PLEASE PROVIDE ONLY THE IMPLEMENTATION in your solution
class labThree_pThree {
public:
    labThree_pThree(char *name);

    /**
     * Adds thePerson as a friend of this person.

tests/LabThree.cpp

0 → 100644
+120 −0
Original line number Diff line number Diff line
/**
** Created by Ari Trachtenberg on 10/31/2024
** With help from ChatGPT
*/


#include <iostream>
#include <string>
#include <cstring>

#include "../problems/labThree_ChapterEight.h"
#include "../problems/labThree_ChapterNine.h"

using namespace std;

bool test_labThree_pZero() {
    int *result = labThree_pZero("Support/example.txt");

    //test a
    if(result[0]!=1 || result[3]!=2 || result[14]!=4){
        cout << "Test 0a failed" << endl;
        return false;
    }

    // All tests passed
    return true;
}

bool test_labThree_pOne() {
    // test a
    if (labThree_pOne("Support/example.csv") !=4) {
        cout << "Test 1a failed" << endl;
        return false;
    }

    // test b
    if (labThree_pOne("Support/example2.csv") !=4) {
        cout << "Test 1b failed" << endl;
        return false;
    }

    // All tests passed
    return true;
}

bool test_labThree_pTwo() {
    // no easy way to test this, since it is a class declaration

    // All tests passed
    return true;
}

bool test_labThree_pThree() {
    labThree_pThree person1("Jim");
    labThree_pThree person2("Jane");
    labThree_pThree person3("Bob");

    person1.befriend(person2);
    person1.befriend(person3);
    person2.befriend(person1);

    if (person1.getFriendCount()!=2) {
        cout << "Test 3a failed" << endl;
        return false;
    }
    if (person2.getFriendCount()!=1) {
        cout << "Test 3b failed" << endl;
        return false;
    }
    if (person3.getFriendCount()!=0) {
        cout << "Test 3c failed" << endl;
        return false;
    }

    string result = person1.getFriends();
    if (result.find("Jane")==string::npos || result.find("Bob")==string::npos) {
        cout << "Test 3d failed" << endl;
        return false;
    }

    string result2 = person1.getFriends();
    if (result2.find("Jim")==string::npos || result2.length()!=3) {
        cout << "Test 3e failed" << endl;
        return false;
    }

    string result3 = person1.getFriendsOfFriends();
    if (result3.find("Jim")==string::npos || result3.length()!=3) {
        cout << "Test 3f failed" << endl;
        return false;
    }

    string result4 = person1.getFriendsOfFriends();
    if (result4.find("Jane")==string::npos || result4.find("Bob")==string::npos) {
        cout << "Test 3g failed" << endl;
        return false;
    }

    // All tests passed
    return true;
}


int main() {
    bool t0 = test_labThree_pZero();
    bool t1 = test_labThree_pOne();
    bool t2 = test_labThree_pTwo();
    bool t3 = test_labThree_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
+1 −0
Original line number Diff line number Diff line
1729, San Francisco, "Hello, World", "He asked: ""Quo vadis?"""
 No newline at end of file
+1 −0
Original line number Diff line number Diff line
The quick brown fox jumped over the lazy dog.
 No newline at end of file
+3 −0
Original line number Diff line number Diff line
a,b,c
"a", "b", "c", "d"
1, 2
 No newline at end of file