Commit 7a5b964d authored by Ari Trachtenberg's avatar Ari Trachtenberg
Browse files

Starting lab 1 testing

parent d284280e
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -29,9 +29,9 @@ int labOne_pFour(int nn);
 *       then add the first character to the end.
 *
 * @example
 * labOne_pFour("wolf") returns "flow".
 * labOne_pFive("wolf") returns "flow".
 */
int labOne_pFive(string str);
string labOne_pFive(string str);

/**
 * @param str Some string.
+1 −1
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ void labOne_pZero();
 *    c.  The sum of all positive powers of two less than or equal to 2 (i.e., 2)
 *
 * @example 2
 * MaxL 9
 * Max: 9
 * 47
 *
 * This is because 20+14+13 = 47:
+110 −4
Original line number Diff line number Diff line
//
// Created by Ari Trachtenberg on 9/10/24.
//
/**
** Created by Ari Trachtenberg on 9/10/24.
** With help from ChatGPT
*/


#include <iostream>
#include <string>

#include "../problems/LabOne_ChapterFour.h"
#include "../problems/LabOne_ChapterFive.h"
#include "Support/Common.h"

using namespace std;

bool test_labOne_pZero() {
    // simple, but incomplete tests

    // example 1
    Common::redirIO("3 4"); // redirect input
    labOne_pZero();
    string out = Common::restoreIO();
    // count occurrences of ****
    size_t pos=0; int count=0;
    while ((pos = out.find("****", pos)) != string::npos) {
        count++;  // found a match
        pos += 4;  // Move the position forward to avoid overlapping matches
    }
    if (count!=3)
        return false;

    // example 2
    Common::redirIO("1 10"); // redirect input
    labOne_pZero();
    out = Common::restoreIO();
    if (out.find("**********") == string::npos)
        return false;

    return true;
}

bool test_labOne_pOne() {
    // example 1
    Common::redirIO("2");
    labOne_pOne();
    int out = stoi(Common::restoreIO());
    if (out!=5)
        return false;

    // example 2
    Common::redirIO("9");
    labOne_pOne();
    out = stoi(Common::restoreIO());
    if (out!=47)
        return false;

    return true;
}

bool test_labOne_pTwo() {
    Common::redirIO("20");
    labOne_pTwo();
    string out = Common::restoreIO();

    // sum the length of each line
    istringstream stream(out);
    string line;
    int sum = 0;
    while (getline(stream, line)) {
        sum += line.length();
    }

    if (sum==10)
        return true;
    else
        return false;
}

bool test_labOne_pThree() {
    Common::redirIO("20");
    labOne_pThree();
    string out = Common::restoreIO();

    // sum the numbers on each line
    istringstream stream(out);
    string line;
    int sum = 0;
    while (getline(stream, line)) {
        sum += stoi(line);
    }

    if (sum==132)
        return true;
    else
        return false;
}

bool test_labOne_pFour() {
    if (labOne_pFour(1729) == 14)
        return true;
    else
        return false;
}

bool test_labOne_pFive() {
    if (labOne_pFive("wolf") == "flow")
        return true;
    else
        return false;
}
//#include "LabOne.h"
+5 −4
Original line number Diff line number Diff line

#include <iostream>
//
// Created by Ari Trachtenberg on 9/24.
//
//
// #include <iostream>
#include <string>

#include "../problems/LabZero_ChapterTwo.h"
@@ -8,8 +11,6 @@

using namespace std;


// TESTS
bool test_labZero_pZero() {
    Common::redirIO("1 2 90"); // redirect input
    labZero_pZero();