diff options
Added files from project 1 (mirror)
8 files changed, 654 insertions, 0 deletions
diff --git a/Year 1/Object-oriented Programming/Project 1/tests/Tests_ALL.cpp b/Year 1/Object-oriented Programming/Project 1/tests/Tests_ALL.cpp new file mode 100644 index 0000000..2252865 --- /dev/null +++ b/Year 1/Object-oriented Programming/Project 1/tests/Tests_ALL.cpp @@ -0,0 +1,9 @@ +#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN +#include "../doctest/doctest/doctest.h" +#include "Tests_Command.h" +#include "Tests_Date.h" +#include "Tests_Event.h" +#include "Tests_Hall.h" +#include "Tests_Reservation.h" +#include "Tests_String.h" +#include "Tests_Ticket.h" diff --git a/Year 1/Object-oriented Programming/Project 1/tests/Tests_Command.h b/Year 1/Object-oriented Programming/Project 1/tests/Tests_Command.h new file mode 100644 index 0000000..02325cd --- /dev/null +++ b/Year 1/Object-oriented Programming/Project 1/tests/Tests_Command.h @@ -0,0 +1,51 @@ +#include <cstring> +#include "../doctest/doctest/doctest.h" +#include "../src/Generic/ConsoleInterface/Command.h" + +TEST_SUITE_BEGIN("ClassCommand"); + +unsigned value = 0; +void increment() { + value++; +} + +TEST_SUITE("Constructors") { + TEST_CASE("DefaultCtor_SavesNameInMenuAsBlankString_WhenCalled") { + Command c; + + CHECK_EQ(strcmp(c.get_nameInMenu(), ""), 0); + } + TEST_CASE("Ctor_SavesValues_WhenGivenCorrectValues") { + void (*exec)() = nullptr; + SUBCASE("ActualFunctionPointer") { exec = increment; } + SUBCASE("nullptrFunctionPointer") { exec = nullptr; } + Command c("Test", exec); + + CHECK_EQ(strcmp(c.get_nameInMenu(), "Test"), 0); + } +} + +TEST_SUITE("GettersAndSetters") { + TEST_CASE("nameInMenuGetter_ReturnsProperPointer_WhenCreatedWithProperString") { + Command c("Test", nullptr); + + CHECK_EQ(strcmp(c.get_nameInMenu(), "Test"), 0); + } + TEST_CASE("nameInMenuGetter_ReturnsBlankString_WhenCreatedWithDefaultCtor") { + Command c; + + CHECK_EQ(strcmp(c.get_nameInMenu(), ""), 0); + } +} + +TEST_SUITE("run()") { + TEST_CASE("run_ExecutesFunction_WhenCreatedWithProperFunction") { + value = 0; + Command c("Test", increment); + c.run(); + + CHECK_EQ(value, 1); + } +} + +TEST_SUITE_END(); diff --git a/Year 1/Object-oriented Programming/Project 1/tests/Tests_Date.h b/Year 1/Object-oriented Programming/Project 1/tests/Tests_Date.h new file mode 100644 index 0000000..17878d9 --- /dev/null +++ b/Year 1/Object-oriented Programming/Project 1/tests/Tests_Date.h @@ -0,0 +1,194 @@ +#include <cstring> +#include "../doctest/doctest/doctest.h" +#include "../src/Generic/Date/Date.h" + +TEST_SUITE_BEGIN("ClassDate"); + +const unsigned short d = 19, m = 4, y = 2022; // valid values + +TEST_SUITE("Constructors") { + TEST_CASE("DefaultCtor_SetsDateAsFirstOfMay2022_WhenCalled") { + Date dt; + + CHECK_EQ(dt.get_day(), 1); + CHECK_EQ(dt.get_month(), 5); + CHECK_EQ(dt.get_year(), 2022); + } + TEST_CASE("StrCtor_ParsesValues_WhenGivenCorrectString") { + char str[] = "9 12 2021"; + Date dt(str); + + CHECK_EQ(dt.get_day(), 9); + CHECK_EQ(dt.get_month(), 12); + CHECK_EQ(dt. get_year(), 2021); + } + TEST_CASE("StrCtor_StoresZeroes_WhenGivenBadString") { + char str[] = "45 500 ABCD"; + Date dt(str); + + CHECK_EQ(dt.get_day(), 0); + CHECK_EQ(dt.get_month(), 0); + CHECK_EQ(dt.get_year(), 0); + } + TEST_CASE("StrCtor_StoresZeroes_WhenGivenBlankString") { + char str[] = ""; + Date dt(str); + + CHECK_EQ(dt.get_day(), 0); + CHECK_EQ(dt.get_month(), 0); + CHECK_EQ(dt.get_year(), 0); + } + TEST_CASE("Ctor_SavesValues_WhenGivenValidValues") { + Date dt(d, m, y); + + CHECK_EQ(dt.get_day(), d); + CHECK_EQ(dt.get_month(), m); + CHECK_EQ(dt.get_year(), y); + } + TEST_CASE("Ctor_StoresZeroes_WhenGivenInvalidValues") { + unsigned short nd = 0, nm = 0, ny = 0; + SUBCASE("DayIsZero") { nd = 0; } + SUBCASE("DayIsTooBig") { nd = 5721; } + SUBCASE("MonthIsZero") { nm = 0; } + SUBCASE("MonthIsTooBig") { nm = 15661; } + SUBCASE("YearIsZero") { ny = 0; } + + Date dt(nd, nm, ny); + CHECK_EQ(dt.get_day(), 0); + CHECK_EQ(dt.get_month(), 0); + CHECK_EQ(dt.get_year(), 0); + } +} + +TEST_SUITE("GettersAndSetters") { + TEST_CASE("DayGetter_ReturnsCorrectValue_WhenCreatedWithValidValues") { + Date dt(d, m, y); + + CHECK_EQ(dt.get_day(), d); + } + TEST_CASE("DaySetter_ReturnsTrue_WhenGivenCorrectValue") { + Date dt(d, m, y); + unsigned nd = d; + SUBCASE("SingleDigits") { nd = 2; } + SUBCASE("DoubleDigits") { nd = 26; } + + CHECK_UNARY(dt.set_day(nd)); + } + TEST_CASE("DaySetter_SetsValue_WhenGivenCorrectValue") { + Date dt(d, m, y); + unsigned nd = d; + SUBCASE("SingleDigits") { nd = 9; } + SUBCASE("DoubleDigits") { nd = 13; } + dt.set_day(nd); + + CHECK_EQ(dt.get_day(), nd); + } + TEST_CASE("DaySetter_ReturnsFalse_WhenGivenIncorrectValue") { + Date dt(d, m, y); + unsigned nd = d; + SUBCASE("Zero") { nd = 0; } + SUBCASE("TooBig") { nd = 847; } + + CHECK_UNARY_FALSE(dt.set_day(nd)); + } + + TEST_CASE("MonthGetter_ReturnsCorrectValue_WhenCreatedWithValidValues") { + Date dt(d, m, y); + + CHECK_EQ(dt.get_month(), m); + } + TEST_CASE("MonthSetter_ReturnsTrue_WhenGivenCorrectValue") { + Date dt(d, m, y); + unsigned nm = m; + SUBCASE("SingleDigits") { nm = 2; } + SUBCASE("DoubleDigits") { nm = 11; } + + CHECK_UNARY(dt.set_month(nm)); + } + TEST_CASE("MonthSetter_SetsValue_WhenGivenCorrectValue") { + Date dt(d, m, y); + unsigned nm = m; + SUBCASE("SingleDigits") { nm = 9; } + SUBCASE("DoubleDigits") { nm = 10; } + dt.set_month(nm); + + CHECK_EQ(dt.get_month(), nm); + } + TEST_CASE("MonthSetter_ReturnsFalse_WhenGivenIncorrectValue") { + Date dt(d, m, y); + unsigned nm = m; + SUBCASE("Zero") { nm = 0; } + SUBCASE("TooBig") { nm = 13; } + + CHECK_UNARY_FALSE(dt.set_month(nm)); + } + + TEST_CASE("YearGetter_ReturnsCorrectValue_WhenCreatedWithValidValues") { + Date dt(d, m, y); + + CHECK_EQ(dt.get_year(), y); + } + TEST_CASE("YearSetter_ReturnsTrue_WhenGivenCorrectValue") { + Date dt(d, m, y); + unsigned ny = y; + SUBCASE("SingleDigits") { ny = 2; } + SUBCASE("DoubleDigits") { ny = 58; } + SUBCASE("TripleDigits") { ny = 681; } + SUBCASE("QuadrupleDigits") { ny = 1878; } + + CHECK_UNARY(dt.set_year(ny)); + } + TEST_CASE("YearSetter_SetsValue_WhenGivenCorrectValue") { + Date dt(d, m, y); + unsigned ny = y; + SUBCASE("SingleDigits") { ny = 2; } + SUBCASE("DoubleDigits") { ny = 58; } + SUBCASE("TripleDigits") { ny = 681; } + SUBCASE("QuadrupleDigits") { ny = 1878; } + dt.set_year(ny); + + CHECK_EQ(dt.get_year(), ny); + } + TEST_CASE("YearSetter_ReturnsFalse_WhenGivenIncorrectValue") { + Date dt(d, m, y); + unsigned ny = y; + SUBCASE("Zero") { ny = 0; } + + CHECK_UNARY_FALSE(dt.set_year(ny)); + } +} + +TEST_SUITE("createString()") { + TEST_CASE("createString_CreatesCorrectString_WhenCalled") { + Date dt(8, 10, 2019); + String output = dt.createString(); + + CHECK_EQ(strcmp(output.get_cstr(), "8.10.2019"), 0); + } +} + +TEST_SUITE("compare()") { + TEST_CASE("compare_ReturnsLessThanZero_WhenFirstDateIsBeforeSecond") { + Date dt1(d, m, y), dt2(d, m, y); + SUBCASE("DifferenceByDay") { dt1.set_day(d - 1); } + SUBCASE("DifferenceByMonth") { dt1.set_month(m - 1); } + SUBCASE("DifferenceByYear") { dt1.set_year(y - 1); } + + CHECK_LT(dt1.compare(dt2), 0); + } + TEST_CASE("compare_ReturnsMoreThanZero_WhenFirstDateIsAfterSecond") { + Date dt1(d, m, y), dt2(d, m, y); + SUBCASE("DifferenceByDay") { dt2.set_day(d - 1); } + SUBCASE("DifferenceByMonth") { dt2.set_month(m - 1); } + SUBCASE("DifferenceByYear") { dt2.set_year(y - 1); } + + CHECK_GT(dt1.compare(dt2), 0); + } + TEST_CASE("compare_ReturnsZero_WhenDatesAreEqual") { + Date dt1(d, m, y), dt2(d, m, y); + + CHECK_EQ(dt1.compare(dt2), 0); + } +} + +TEST_SUITE_END(); diff --git a/Year 1/Object-oriented Programming/Project 1/tests/Tests_Event.h b/Year 1/Object-oriented Programming/Project 1/tests/Tests_Event.h new file mode 100644 index 0000000..a27142a --- /dev/null +++ b/Year 1/Object-oriented Programming/Project 1/tests/Tests_Event.h @@ -0,0 +1,89 @@ +#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN +#include "../doctest/doctest/doctest.h" +#include "../src/Models/Event.h" +#include "../src/Generic/String/String.h" + +TEST_SUITE_BEGIN("ClassEvent"); + +TEST_SUITE("Constructors") { + TEST_CASE("DefaultCtor_CallsDefaultCtorsOnData_WhenCalled") { + Event e; + + CHECK_EQ(e.get_hall().compare(Hall()), 0); + CHECK_EQ(e.get_name().compare(String()), 0); + CHECK_EQ(e.get_date().compare(Date()), 0); + } + TEST_CASE("Ctor_SavesParameters_WhenCalledWithProperParameters") { + Hall h(1, 2, 3); + String n("Test"); + Date d(21, 3, 2012); + + Event e(h, n, d); + CHECK_EQ(e.get_hall().compare(h), 0); + CHECK_EQ(e.get_name().compare(n), 0); + CHECK_EQ(e.get_date().compare(d), 0); + } +} + +TEST_SUITE("GettersAndSetters") { + TEST_CASE("HallGetter_ReturnsProperHall_WhenCreatedWithProperHall") { + Hall h(1, 2, 3); + String n("Test"); + Date d(21, 3, 2012); + + Event e(h, n, d); + CHECK_EQ(e.get_hall().compare(h), 0); + } + + TEST_CASE("NameGetter_ReturnsProperName_WhenCreatedWithProperName") { + Hall h(1, 2, 3); + String n("Test"); + Date d(21, 3, 2012); + + Event e(h, n, d); + CHECK_EQ(e.get_name().compare(n), 0); + } + + TEST_CASE("DateGetter_ReturnsProperDate_WhenCreatedWithProperDate") { + Hall h(1, 2, 3); + String n("Test"); + Date d(21, 3, 2012); + + Event e(h, n, d); + CHECK_EQ(e.get_date().compare(d), 0); + } + + TEST_CASE("TicketsGetter_ReturnsEmptyList_WhenCreatedWithDefaultCtor") { + Event e; + + CHECK_EQ(e.get_tickets().get_count(), 0); + } + + TEST_CASE("ReservationsGetter_ReturnsEmptyList_WhenCreatedWithDefaultCtor") { + Event e; + + CHECK_EQ(e.get_reservations().get_count(), 0); + } +} + +TEST_SUITE("compare()") { + TEST_CASE("compare_ReturnsCompareBetweenHallsAndDates_WhenCalled") { + Hall h1(1, 2, 3), h2(3, 4, 5); + Date d1(1, 4, 2009), d2(19, 5, 2010); + + SUBCASE("HallIsLessThanOtherHall") {} + SUBCASE("HallIsBiggerThanOtherHall") { Hall temp = h2; h2 = h1; h1 = temp; } + SUBCASE("HallsAreEqual") { h1 = h2; } + SUBCASE("HallsAreEqualAndDateIsLessThanOther") {} + SUBCASE("HallsAreEqualAndDateIsMoreThanOther") { Date temp = d2; d2 = d1; d1 = temp; } + SUBCASE("HallsAreEqualAndDatesAreEqual") { h1 = h2; d1 = d2; } + Event e1(h1, "Test1", d1), e2(h2, "Test2", d2); + + if (h1.compare(h2) == 0) + CHECK_EQ(e1.compare(e2), d1.compare(d2)); + else + CHECK_EQ(e1.compare(e2), h1.compare(h2)); + } +} + +TEST_SUITE_END(); diff --git a/Year 1/Object-oriented Programming/Project 1/tests/Tests_Hall.h b/Year 1/Object-oriented Programming/Project 1/tests/Tests_Hall.h new file mode 100644 index 0000000..01e5979 --- /dev/null +++ b/Year 1/Object-oriented Programming/Project 1/tests/Tests_Hall.h @@ -0,0 +1,84 @@ +#include "../doctest/doctest/doctest.h" +#include "../src/Models/Hall.h" + +TEST_SUITE_BEGIN("ClassHall"); + +int number = 5; // valid values +unsigned rows = 10, seatsPerRow = 6; // valid values + +TEST_SUITE("Constructors") { + TEST_CASE("DefaultCtor_SetsValuesToZero_WhenCalled") { + Hall h; + + CHECK_EQ(h.get_number(), 0); + CHECK_EQ(h.get_rows(), 0); + CHECK_EQ(h.get_seatsPerRow(), 0); + } + TEST_CASE("NumberCtor_SetsNumberToParameterAndOthersToZeroes_WhenCalled") { + SUBCASE("NegativeNumber") { number = -843; } + SUBCASE("ZeroNumber") { number = 0; } + SUBCASE("PositiveNumber") { number = 571; } + + Hall h(number); + CHECK_EQ(h.get_number(), number); + } + TEST_CASE("Ctor_SetsValues_WhenGivenCorrectValues") { + SUBCASE("NegativeNumber") { number = -843; } + SUBCASE("ZeroNumber") { number = 0; } + SUBCASE("PositiveNumber") { number = 571; } + SUBCASE("ZeroRow") { rows = 0; } + SUBCASE("PositiveRow") { rows = 91; } + SUBCASE("ZeroSeatsPerRow") { seatsPerRow = 0; } + SUBCASE("PositiveSeatsPerRow") { seatsPerRow = 37; } + + Hall h(number, rows, seatsPerRow); + CHECK_EQ(h.get_number(), number); + CHECK_EQ(h.get_rows(), rows); + CHECK_EQ(h.get_seatsPerRow(), seatsPerRow); + } +} + +TEST_SUITE("GettersAndSetters") { + TEST_CASE("NumberGetter_ReturnsProperValue_WhenGivenCorrectValue") { + SUBCASE("CreatedWithZeroNumber") { number = 0; } + SUBCASE("CreatedWithPositiveNumber") { number = 473; } + SUBCASE("CretaedWithNegativeNumber") { number = -384; } + + Hall h(number, rows, seatsPerRow); + CHECK_EQ(h.get_number(), number); + } + TEST_CASE("RowsGetter_ReturnsProperValue_WhenGivenCorrectValue") { + SUBCASE("CreatedWithZeroRows") { rows = 0; } + SUBCASE("CreatedWithPositiveRows") { rows = 473; } + + Hall h(number, rows, seatsPerRow); + CHECK_EQ(h.get_rows(), rows); + } + TEST_CASE("SeatsPerRowGetter_ReturnsProperValue_WhenGivenCorrectValue") { + SUBCASE("CreatedWithZeroSeatsPerRow") { seatsPerRow = 0; } + SUBCASE("CreatedWithPositiveSeatsPerRow") { seatsPerRow = 473; } + + Hall h(number, rows, seatsPerRow); + CHECK_EQ(h.get_seatsPerRow(), seatsPerRow); + } +} + +TEST_SUITE("compare()") { + TEST_CASE("compare_ReturnsLessThanZero_WhenFirstHallNumberIsLessThanSecondHallNumber") { + Hall h1(number, rows, seatsPerRow), h2(number + 1, rows, seatsPerRow); + + CHECK_LT(h1.compare(h2), 0); + } + TEST_CASE("compare_ReturnsMoreThanZero_WhenFirstHallNumberIsMoreThanSecondHallNumber") { + Hall h1(number + 1, rows, seatsPerRow), h2(number, rows, seatsPerRow); + + CHECK_GT(h1.compare(h2), 0); + } + TEST_CASE("compare_ReturnsZero_WhenFirstHallNumberIsEqualToSecondHallNumber") { + Hall h1(number, rows, seatsPerRow), h2(number, rows, seatsPerRow); + + CHECK_EQ(h1.compare(h2), 0); + } +} + +TEST_SUITE_END(); diff --git a/Year 1/Object-oriented Programming/Project 1/tests/Tests_Reservation.h b/Year 1/Object-oriented Programming/Project 1/tests/Tests_Reservation.h new file mode 100644 index 0000000..31efaf9 --- /dev/null +++ b/Year 1/Object-oriented Programming/Project 1/tests/Tests_Reservation.h @@ -0,0 +1,64 @@ +#include <cstring> +#include "../doctest/doctest/doctest.h" +#include "../src/Models/Reservation.h" + +TEST_SUITE_BEGIN("ClassReservation"); + +TEST_SUITE("Constructors") { + TEST_CASE("DefaultCtor_CallsDefaultCtorOfTicketAndSetsNoteAndPasswordBlank_WhenCalled") { + Reservation r; + + CHECK_EQ(r.get_ticket().compare(Ticket()), 0); + CHECK_EQ(strcmp(r.get_password(), ""), 0); + CHECK_EQ(strcmp(r.get_note(), ""), 0); + } + TEST_CASE("TicketCtor_SavesTicketAndSetsNoteAndPasswordBlank_WhenCalled") { + Ticket t(4, 2); + Reservation r(t); + + CHECK_EQ(r.get_ticket().compare(t), 0); + CHECK_EQ(strcmp(r.get_password(), ""), 0); + CHECK_EQ(strcmp(r.get_note(), ""), 0); + } + TEST_CASE("Ctor_SavesProperValues_WhenGivenProperValues") { + Ticket t(6, 1); + Reservation r(t, "One", "Two"); + + CHECK_EQ(r.get_ticket().compare(t), 0); + CHECK_EQ(strcmp(r.get_password(), "One"), 0); + CHECK_EQ(strcmp(r.get_note(), "Two"), 0); + } +} + +TEST_SUITE("GettersAndSetters") { + TEST_CASE("TicketGetter_ReturnsProperValue_WhenCreatedWithTicket") { + Ticket t(5, 7); + Reservation r(t); + + CHECK_EQ(r.get_ticket().compare(t), 0); + } + TEST_CASE("PasswordGetter_ReturnsProperValue_WhenCreatedWithProperValue") { + Reservation r(Ticket(), "12345678", ""); + + CHECK_EQ(strcmp(r.get_password(), "12345678"), 0); + } + TEST_CASE("NoteGetter_ReturnsProperValue_WhenCreatedWithProperValue") { + Reservation r(Ticket(), "", "One Two Three"); + + CHECK_EQ(strcmp(r.get_note(), "One Two Three"), 0); + } +} + +TEST_SUITE("compare()") { + TEST_CASE("Compare_ReturnsTicketCompare_WhenCalled") { + Ticket t1(1, 1), t2(2, 2); + SUBCASE("FirstIsBiggerThanSecond") { t1 = Ticket(3, 3); } + SUBCASE("FirstIsSmallerThanSecond") {} + SUBCASE("FirstIsEqualToSecond") { t1 = t2; } + Reservation r1(t1), r2(t2); + + CHECK_EQ(r1.compare(r2), t1.compare(t2)); + } +} + +TEST_SUITE_END(); diff --git a/Year 1/Object-oriented Programming/Project 1/tests/Tests_String.h b/Year 1/Object-oriented Programming/Project 1/tests/Tests_String.h new file mode 100644 index 0000000..542b6d8 --- /dev/null +++ b/Year 1/Object-oriented Programming/Project 1/tests/Tests_String.h @@ -0,0 +1,99 @@ +#include <cstring> +#include "../doctest/doctest/doctest.h" +#include "../src/Generic/String/String.h" + +TEST_SUITE_BEGIN("ClassString"); + +TEST_SUITE("Constructors") { + TEST_CASE("Ctor_CreatesInternalArrayOfLength_WhenGivenCorrectLength") { + String s(5); + + CHECK_EQ(strlen(s.get_cstr()), 5); + } + TEST_CASE("Ctor_CopiesValues_WhenGivenCorrectCString") { + String s("Testing string."); + + CHECK_EQ(strcmp(s.get_cstr(), "Testing string."), 0); + } +} + +TEST_SUITE("GettersAndSetters") { + TEST_CASE("CStrGetter_ReturnsCorrectPointer_WhenCreatedWithCString") { + String s("Testing string."); + + CHECK_EQ(strcmp(s.get_cstr(), "Testing string."), 0); + } + + TEST_CASE("LengthGetter_ReturnsCorrectLength_WhenCreatedWithLength") { + String s(5); + + CHECK_EQ(s.get_length(), 5); + } + TEST_CASE("LengthGetter_ReturnsCorrectLength_WhenCreatedWithCString") { + String s("Testing string."); + + CHECK_EQ(s.get_length(), strlen(s.get_cstr())); + } +} + +TEST_SUITE("Operators") { + TEST_CASE("BracketsOperator_ReturnsCorrectCharacter_WhenGivenCorrectIndex") { + String s("Tesing string."); + + unsigned index = 0; + char expectedCharacter = '\0'; + SUBCASE("IndexIsZero") { index = 0; expectedCharacter = 'T'; } + SUBCASE("IndexIsSomewhereInTheMiddle") { index = 5; expectedCharacter = 'g'; } + SUBCASE("IndexIsLast") { index = 13; expectedCharacter = '.'; } + SUBCASE("IndexIsTerminatingZero") { index = 14; expectedCharacter = '\0'; } + + CHECK_EQ(s[index], expectedCharacter); + } + TEST_CASE("BracketsOperator_SetsCharacter_WhenGivenCorrectIndexAndValue") { + String s("Tesing string."); + + unsigned index = 0; + char replaceWith = 'W'; + SUBCASE("IndexIsZero") { index = 0; } + SUBCASE("IndexIsSomewhereInTheMiddle") { index = 5; } + SUBCASE("IndexIsLast") { index = 13; } + s[index] = replaceWith; + + CHECK_EQ(s[index], replaceWith); + } + + TEST_CASE("PlusEqualOperator_AppendsProperlyCString_WhenGivenCorrectStringAndCreatedWithCstr") { + String s("Testing"); + s += " string."; + + CHECK_EQ(strcmp(s.get_cstr(), "Testing string."), 0); + } + TEST_CASE("PlusEqualOperator_AppendsProperlyNumber_WhenGivenCorrectNumberAndCreatedWithCstr") { + String s("Testing"); + s += 15684; + + CHECK_EQ(strcmp(s.get_cstr(), "Testing15684"), 0); + } +} + +TEST_SUITE("compare()") { + TEST_CASE("compare_ReturnsSameResultAsstrcmp_WhenFirstIsLessThanSecond") { + String s1("Test"), s2("test"); + + CHECK_LT(s1.compare(s2), 0); + CHECK_LT(strcmp("Test", "test"), 0); + } + TEST_CASE("compare_ReturnsSameResultAsstrcmp_WhenFirstIsGreaterThanSecond") { + String s1("test"), s2("Test"); + + CHECK_GT(s1.compare(s2), 0); + CHECK_GT(strcmp("test", "Test"), 0); + } + TEST_CASE("compare_ReturnsSameResultAsstrcmp_WhenFirstIsEqualToSecond") { + String s1("test"), s2("test"); + + CHECK_EQ(s1.compare(s2), strcmp("test", "test")); + } +} + +TEST_SUITE_END(); diff --git a/Year 1/Object-oriented Programming/Project 1/tests/Tests_Ticket.h b/Year 1/Object-oriented Programming/Project 1/tests/Tests_Ticket.h new file mode 100644 index 0000000..fc1855c --- /dev/null +++ b/Year 1/Object-oriented Programming/Project 1/tests/Tests_Ticket.h @@ -0,0 +1,64 @@ +#include "../doctest/doctest/doctest.h" +#include "../src/Models/Ticket.h" + +TEST_SUITE_BEGIN("ClassTicket"); + +TEST_SUITE("Constructors") { + TEST_CASE("DefaultCtor_SetsZeroes_WhenCalled") { + Ticket t; + + CHECK_EQ(t.get_row(), 0); + CHECK_EQ(t.get_seat(), 0); + } + TEST_CASE("Ctor_SetsValues_WhenGivenProperValues") { + unsigned r = 0, s = 0; + SUBCASE("RowIsZero") { r = 0; } + SUBCASE("RowIsPositive") { r = 3; } + SUBCASE("SeatIsZero") { s = 0; } + SUBCASE("SeatIsPositive") { s = 7; } + Ticket t(r, s); + + CHECK_EQ(t.get_row(), r); + CHECK_EQ(t.get_seat(), s); + } +} + +TEST_SUITE("GettersAndSetters") { + TEST_CASE("RowGetter_ReturnsProperValue_WhenCreatedWithProperValue") { + Ticket t(6, 0); + + CHECK_EQ(t.get_row(), 6); + } + TEST_CASE("SeatGetter_ReturnsProperValue_WhenCreatedWithProperValue") { + Ticket t(0, 8); + + CHECK_EQ(t.get_seat(), 8); + } +} + +TEST_SUITE("compare()") { + TEST_CASE("compare_ReturnsLessThanZero_WhenFirstIsLessThanSecond") { + unsigned r1 = 0, r2 = 0, s1 = 0, s2 = 0; + SUBCASE("FirstRowIsLessThanSecond") { r1 = 5; r2 = 9; } + SUBCASE("RowsAreEqualAndFirstSeatIsLessThanSecond") { r1 = r2 = 62; s1 = 3; s2 = 93; } + Ticket t1(r1, s1), t2(r2, s2); + + CHECK_LT(t1.compare(t2), 0); + } + TEST_CASE("compare_ReturnsGreaterThanZero_WhenFirstIsGreaterThanSecond") { + unsigned r1 = 0, r2 = 0, s1 = 0, s2 = 0; + SUBCASE("FirstRowIsGreaterThanSecond") { r1 = 9; r2 = 5; } + SUBCASE("RowsAreEqualAndFirstSeatIsGreaterThanSecond") { r1 = r2 = 62; s1 = 93; s2 = 3; } + Ticket t1(r1, s1), t2(r2, s2); + + CHECK_GT(t1.compare(t2), 0); + } + TEST_CASE("compare_ReturnsZero_WhenFirstIsEqualToSecond") { + unsigned r1 = 458, r2 = 458, s1 = 73, s2 = 73; + Ticket t1(r1, s1), t2(r2, s2); + + CHECK_EQ(t1.compare(t2), 0); + } +} + +TEST_SUITE_END(); |
