Loading problems/LabOne_ChapterFive.h +3 −3 Original line number Diff line number Diff line Loading @@ -58,15 +58,15 @@ bool labOne_pSix(string str); * @see https://en.wikipedia.org/wiki/Factorial_number_system * * @example 1 * labOne_pSix(3) = 11 because: * labOne_pSeven(3) returns 11 because: * 3 = 1*2! + 1*1! * * @example 2 * labOne_pSix(10) = 120 because: * labOne_pSeven(10) returns 120 because: * 10 = 1*3! + 2*2! + 0*1! * * @example 3 * labOne_pSix(463) returns 34101 because: * labOne_pSeven(463) returns 34101 because: * 463 = 3*5! + 4*4! + 1*3! + 0*2! + 1*1! */ long labOne_pSeven(long num); No newline at end of file tests/LabOne.cpp +55 −0 Original line number Diff line number Diff line Loading @@ -109,3 +109,58 @@ bool test_labOne_pFive() { return false; } bool test_labOne_pSix() { // example 1 if (!labOne_pSix("deed")) return false; // example 2 if (labOne_pSix("deeds")) return false; // example 3 if (!labOne_pSix("aibophpobia")) return false; return true; } bool test_labOne_pSeven() { // example 1 if (labOne_pSeven(3)!=11) return false; // example 2 if (labOne_pSeven(10)!=120) return false; // example 3 if (labOne_pSeven(463)!=34101) return false; } int main() { bool t0 = test_labOne_pZero(); bool t1 = test_labOne_pOne(); bool t2 = test_labOne_pTwo(); bool t3 = test_labOne_pThree(); bool t4 = test_labOne_pFour(); bool t5 = test_labOne_pFive(); bool t6 = test_labOne_pSix(); bool t7 = test_labOne_pSeven(); 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; cout << "pSix: " << (t6 ? "passed" : "failed") << endl; cout << "pSeven: " << (t7 ? "passed" : "failed") << endl; if (t0 && t1 && t2 && t3 && t4 && t5 && t6 && t7) { // all tests passed exit(0); // passed } else { exit(-1); // failed } } No newline at end of file tests/Makefile +19 −16 Original line number Diff line number Diff line Loading @@ -5,35 +5,38 @@ CXX = g++ CXXFLAGS = -Wall -std=c++17 # Source files SRCS = LabOne.cpp LabZero.cpp lab0.cpp Support/Common.cpp COMMON_SRCS = Support/Common.cpp LAB0_SRCS = LabZero.cpp lab0.cpp $(COMMON_SRCS) LAB1_SRCS = LabOne.cpp lab1.cpp $(COMMON_SRCS) # Object files OBJS = LabOne.o LabZero.o lab0.o Support/Common.o COMM_OBJS = Support/Common.o LAB0_OBJS = LabZero.o lab0.o $(COMM_OBJS) LAB1_OBJS = LabOne.o lab1.o $(COMM_OBJS) # Executable name EXEC = test # Executable names LAB0_EXEC = lab0 LAB1_EXEC = lab1 # Default target to build the executable all: $(EXEC) all: $(LAB0_EXEC) $(LAB1_EXEC) # Rule to build the executable from object files $(EXEC): $(OBJS) $(CXX) $(CXXFLAGS) -o $(EXEC) $(OBJS) $(LAB0_EXEC): $(LAB0_OBJS) Makefile $(CXX) $(CXXFLAGS) -o $(LAB0_EXEC) $(LAB0_OBJS) ./$(LAB0_EXEC) # Rules to build object files from source files, with dependency on the Common.h header LabOne.o: LabOne.cpp Support/Common.h $(CXX) $(CXXFLAGS) -c LabOne.cpp $(LAB1_EXEC): $(LAB1_OBJS) Makefile $(CXX) $(CXXFLAGS) -o $(LAB1_EXEC) $(LAB1_OBJS) ./$(LAB1_EXEC) LabZero.o: LabZero.cpp Support/Common.h $(CXX) $(CXXFLAGS) -c LabZero.cpp # Rules to build object files from source files, with dependency on the Common.h header %.o: %.cpp Support/Common.h Makefile $(CXX) $(CXXFLAGS) -c $< -o $@ $(SUPPORT_DIR)/Common.o: Support/Common.cpp Support/Common.h $(CXX) $(CXXFLAGS) -c $(SUPPORT_DIR)/Common.cpp # only recompile lab0.o if it changes lab0.o: $(CXX) $(CXXFLAGS) -c lab0.cpp # Clean target to remove compiled files clean: rm -f $(OBJS) $(EXEC) Loading
problems/LabOne_ChapterFive.h +3 −3 Original line number Diff line number Diff line Loading @@ -58,15 +58,15 @@ bool labOne_pSix(string str); * @see https://en.wikipedia.org/wiki/Factorial_number_system * * @example 1 * labOne_pSix(3) = 11 because: * labOne_pSeven(3) returns 11 because: * 3 = 1*2! + 1*1! * * @example 2 * labOne_pSix(10) = 120 because: * labOne_pSeven(10) returns 120 because: * 10 = 1*3! + 2*2! + 0*1! * * @example 3 * labOne_pSix(463) returns 34101 because: * labOne_pSeven(463) returns 34101 because: * 463 = 3*5! + 4*4! + 1*3! + 0*2! + 1*1! */ long labOne_pSeven(long num); No newline at end of file
tests/LabOne.cpp +55 −0 Original line number Diff line number Diff line Loading @@ -109,3 +109,58 @@ bool test_labOne_pFive() { return false; } bool test_labOne_pSix() { // example 1 if (!labOne_pSix("deed")) return false; // example 2 if (labOne_pSix("deeds")) return false; // example 3 if (!labOne_pSix("aibophpobia")) return false; return true; } bool test_labOne_pSeven() { // example 1 if (labOne_pSeven(3)!=11) return false; // example 2 if (labOne_pSeven(10)!=120) return false; // example 3 if (labOne_pSeven(463)!=34101) return false; } int main() { bool t0 = test_labOne_pZero(); bool t1 = test_labOne_pOne(); bool t2 = test_labOne_pTwo(); bool t3 = test_labOne_pThree(); bool t4 = test_labOne_pFour(); bool t5 = test_labOne_pFive(); bool t6 = test_labOne_pSix(); bool t7 = test_labOne_pSeven(); 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; cout << "pSix: " << (t6 ? "passed" : "failed") << endl; cout << "pSeven: " << (t7 ? "passed" : "failed") << endl; if (t0 && t1 && t2 && t3 && t4 && t5 && t6 && t7) { // all tests passed exit(0); // passed } else { exit(-1); // failed } } No newline at end of file
tests/Makefile +19 −16 Original line number Diff line number Diff line Loading @@ -5,35 +5,38 @@ CXX = g++ CXXFLAGS = -Wall -std=c++17 # Source files SRCS = LabOne.cpp LabZero.cpp lab0.cpp Support/Common.cpp COMMON_SRCS = Support/Common.cpp LAB0_SRCS = LabZero.cpp lab0.cpp $(COMMON_SRCS) LAB1_SRCS = LabOne.cpp lab1.cpp $(COMMON_SRCS) # Object files OBJS = LabOne.o LabZero.o lab0.o Support/Common.o COMM_OBJS = Support/Common.o LAB0_OBJS = LabZero.o lab0.o $(COMM_OBJS) LAB1_OBJS = LabOne.o lab1.o $(COMM_OBJS) # Executable name EXEC = test # Executable names LAB0_EXEC = lab0 LAB1_EXEC = lab1 # Default target to build the executable all: $(EXEC) all: $(LAB0_EXEC) $(LAB1_EXEC) # Rule to build the executable from object files $(EXEC): $(OBJS) $(CXX) $(CXXFLAGS) -o $(EXEC) $(OBJS) $(LAB0_EXEC): $(LAB0_OBJS) Makefile $(CXX) $(CXXFLAGS) -o $(LAB0_EXEC) $(LAB0_OBJS) ./$(LAB0_EXEC) # Rules to build object files from source files, with dependency on the Common.h header LabOne.o: LabOne.cpp Support/Common.h $(CXX) $(CXXFLAGS) -c LabOne.cpp $(LAB1_EXEC): $(LAB1_OBJS) Makefile $(CXX) $(CXXFLAGS) -o $(LAB1_EXEC) $(LAB1_OBJS) ./$(LAB1_EXEC) LabZero.o: LabZero.cpp Support/Common.h $(CXX) $(CXXFLAGS) -c LabZero.cpp # Rules to build object files from source files, with dependency on the Common.h header %.o: %.cpp Support/Common.h Makefile $(CXX) $(CXXFLAGS) -c $< -o $@ $(SUPPORT_DIR)/Common.o: Support/Common.cpp Support/Common.h $(CXX) $(CXXFLAGS) -c $(SUPPORT_DIR)/Common.cpp # only recompile lab0.o if it changes lab0.o: $(CXX) $(CXXFLAGS) -c lab0.cpp # Clean target to remove compiled files clean: rm -f $(OBJS) $(EXEC)