Loading problems/LabOne_ChapterFive.h +2 −2 Original line number Diff line number Diff line Loading @@ -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. Loading problems/LabOne_ChapterFour.h +1 −1 Original line number Diff line number Diff line Loading @@ -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: Loading tests/LabOne.cpp +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" tests/LabZero.cpp +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" Loading @@ -8,8 +11,6 @@ using namespace std; // TESTS bool test_labZero_pZero() { Common::redirIO("1 2 90"); // redirect input labZero_pZero(); Loading Loading
problems/LabOne_ChapterFive.h +2 −2 Original line number Diff line number Diff line Loading @@ -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. Loading
problems/LabOne_ChapterFour.h +1 −1 Original line number Diff line number Diff line Loading @@ -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: Loading
tests/LabOne.cpp +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"
tests/LabZero.cpp +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" Loading @@ -8,8 +11,6 @@ using namespace std; // TESTS bool test_labZero_pZero() { Common::redirIO("1 2 90"); // redirect input labZero_pZero(); Loading