From 9c0be0283c265cff286cadb5f7ddc7caf826c251 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 12 May 2022 20:32:10 +0300 Subject: Added reworked how tests are built --- docs/html/index.html | 8 +- docs/index.md | 10 +++ docs/latex/classList.pdf | 12 +-- docs/latex/classOrderedList.pdf | 12 +-- docs/latex/index.tex | 11 ++- docs/latex/refman.aux | 20 +++-- docs/latex/refman.log | 32 +++---- docs/latex/refman.pdf | Bin 287272 -> 288245 bytes docs/latex/refman.toc | 9 +- tests/Tests_ALL.cpp | 9 ++ tests/Tests_Command.cpp | 52 ----------- tests/Tests_Command.h | 51 +++++++++++ tests/Tests_Date.cpp | 195 ---------------------------------------- tests/Tests_Date.h | 194 +++++++++++++++++++++++++++++++++++++++ tests/Tests_Event.cpp | 89 ------------------ tests/Tests_Event.h | 89 ++++++++++++++++++ tests/Tests_Hall.cpp | 85 ------------------ tests/Tests_Hall.h | 84 +++++++++++++++++ tests/Tests_Reservation.cpp | 65 -------------- tests/Tests_Reservation.h | 64 +++++++++++++ tests/Tests_String.cpp | 100 --------------------- tests/Tests_String.h | 99 ++++++++++++++++++++ tests/Tests_Ticket.cpp | 65 -------------- tests/Tests_Ticket.h | 64 +++++++++++++ 24 files changed, 730 insertions(+), 689 deletions(-) create mode 100644 tests/Tests_ALL.cpp delete mode 100644 tests/Tests_Command.cpp create mode 100644 tests/Tests_Command.h delete mode 100644 tests/Tests_Date.cpp create mode 100644 tests/Tests_Date.h delete mode 100644 tests/Tests_Event.cpp create mode 100644 tests/Tests_Event.h delete mode 100644 tests/Tests_Hall.cpp create mode 100644 tests/Tests_Hall.h delete mode 100644 tests/Tests_Reservation.cpp create mode 100644 tests/Tests_Reservation.h delete mode 100644 tests/Tests_String.cpp create mode 100644 tests/Tests_String.h delete mode 100644 tests/Tests_Ticket.cpp create mode 100644 tests/Tests_Ticket.h diff --git a/docs/html/index.html b/docs/html/index.html index 249286d..ae068ae 100644 --- a/docs/html/index.html +++ b/docs/html/index.html @@ -95,6 +95,12 @@ Linux/BSD/MacOS Windows (PowerShell)
g++ (Get-ChildItem -Recurse *.cpp) -o TicketSystem.exe && ./TicketSystem.exe

+Running the tests

+

Instructions are all for gcc. All commands should be executed while in the tests folder.

+

+Linux/BSD/MacOS

+
g++ Tests_ALL.cpp ../src/*/*.cpp ../src/*/*/*.cpp -o Tests_ALL.out && ./Tests_ALL.out
+

Acknowledgements

Wikipedia
@@ -104,7 +110,7 @@ Acknowledgements
Way to clear the console in Toolbox.hpp
https://stackoverflow.com/a/52895729/12036073
-

+

Figures

Figure 1: Overview of the "FMI Ticket System" design

diff --git a/docs/index.md b/docs/index.md index b2b183c..c9e1134 100644 --- a/docs/index.md +++ b/docs/index.md @@ -39,6 +39,16 @@ g++ *.cpp */*.cpp */*/*.cpp -o TicketSystem.out && ./TicketSystem.out g++ (Get-ChildItem -Recurse *.cpp) -o TicketSystem.exe && ./TicketSystem.exe ``` +## Running the tests + +Instructions are all for `gcc`. All commands should be executed while in the `tests` folder. + +### Linux/BSD/MacOS + +```bash +g++ Tests_ALL.cpp ../src/*/*.cpp ../src/*/*/*.cpp -o Tests_ALL.out && ./Tests_ALL.out +``` + ## Acknowledgements
diff --git a/docs/latex/classList.pdf b/docs/latex/classList.pdf index d0ee570..072935e 100644 --- a/docs/latex/classList.pdf +++ b/docs/latex/classList.pdf @@ -74,10 +74,10 @@ endobj -2022-05-12T20:19:17+03:00 -2022-05-12T20:19:17+03:00 +2022-05-12T20:31:17+03:00 +2022-05-12T20:31:17+03:00 Doxygen - + ClassName @@ -88,8 +88,8 @@ endstream endobj 2 0 obj <>endobj @@ -109,7 +109,7 @@ xref 0000002748 00000 n trailer << /Size 12 /Root 1 0 R /Info 2 0 R -/ID [<0EF19F22F689AC8E3058E6CE4329811B><0EF19F22F689AC8E3058E6CE4329811B>] +/ID [<2C91EE083BFA5F7C036C26C82C94FBC4><2C91EE083BFA5F7C036C26C82C94FBC4>] >> startxref 4229 diff --git a/docs/latex/classOrderedList.pdf b/docs/latex/classOrderedList.pdf index cf2fb6d..b49d530 100644 --- a/docs/latex/classOrderedList.pdf +++ b/docs/latex/classOrderedList.pdf @@ -75,10 +75,10 @@ endobj -2022-05-12T20:19:17+03:00 -2022-05-12T20:19:17+03:00 +2022-05-12T20:31:17+03:00 +2022-05-12T20:31:17+03:00 Doxygen - + ClassName @@ -89,8 +89,8 @@ endstream endobj 2 0 obj <>endobj @@ -110,7 +110,7 @@ xref 0000002752 00000 n trailer << /Size 12 /Root 1 0 R /Info 2 0 R -/ID [<390CF1C4862214E16A53E7299A120F60><390CF1C4862214E16A53E7299A120F60>] +/ID [<497BA3445BC612F34C75267FB1F523CD><497BA3445BC612F34C75267FB1F523CD>] >> startxref 4233 diff --git a/docs/latex/index.tex b/docs/latex/index.tex index a85f5b5..7552a6f 100644 --- a/docs/latex/index.tex +++ b/docs/latex/index.tex @@ -35,14 +35,21 @@ Instructions are all for {\ttfamily gcc}. All commands should be executed while \DoxyCodeLine{g++ (Get-\/ChildItem -\/Recurse *.cpp) -\/o TicketSystem.exe \&\& ./TicketSystem.exe} \end{DoxyCode} -\hypertarget{index_autotoc_md5}{}\doxysection{Acknowledgements}\label{index_autotoc_md5} +\hypertarget{index_autotoc_md5}{}\doxysection{Running the tests}\label{index_autotoc_md5} +Instructions are all for {\ttfamily gcc}. All commands should be executed while in the {\ttfamily tests} folder.\hypertarget{index_autotoc_md6}{}\doxysubsection{Linux/\+BSD/\+Mac\+OS}\label{index_autotoc_md6} + +\begin{DoxyCode}{0} +\DoxyCodeLine{g++ Tests\_ALL.cpp ../src/*/*.cpp ../src/*/*/*.cpp -\/o Tests\_ALL.out \&\& ./Tests\_ALL.out} + +\end{DoxyCode} +\hypertarget{index_autotoc_md7}{}\doxysection{Acknowledgements}\label{index_autotoc_md7} \begin{DoxyDescription} \item[Wikipedia ]Leap year calculation for \mbox{\hyperlink{classDate}{Date}} ~\newline \href{https://en.wikipedia.org/wiki/Leap_year\#Gregorian_calendar}{\texttt{ https\+://en.\+wikipedia.\+org/wiki/\+Leap\+\_\+year\#\+Gregorian\+\_\+calendar}} \item[Stack\+Overflow ]Way to clear the console in \mbox{\hyperlink{Toolbox_8hpp}{Toolbox.\+hpp}} ~\newline \href{https://stackoverflow.com/a/52895729/12036073}{\texttt{ https\+://stackoverflow.\+com/a/52895729/12036073}} -\end{DoxyDescription}\hypertarget{index_autotoc_md6}{}\doxysection{Figures}\label{index_autotoc_md6} +\end{DoxyDescription}\hypertarget{index_autotoc_md8}{}\doxysection{Figures}\label{index_autotoc_md8} \label{index_fig1}% \Hypertarget{index_fig1}% {\bfseries{Figure 1\+:}} Overview of the \char`\"{}\+FMI Ticket System\char`\"{} design diff --git a/docs/latex/refman.aux b/docs/latex/refman.aux index 860d0a1..f22f225 100644 --- a/docs/latex/refman.aux +++ b/docs/latex/refman.aux @@ -27,11 +27,21 @@ \newlabel{index_autotoc_md0}{{1.1}{1}{About}{section.1.1}{}} \@writefile{toc}{\contentsline {section}{\numberline {1.2}Structure overview}{1}{section.1.2}\protected@file@percent } \newlabel{index_autotoc_md1}{{1.2}{1}{Structure overview}{section.1.2}{}} -\@writefile{toc}{\contentsline {section}{\numberline {1.3}Acknowledgements}{2}{section.1.3}\protected@file@percent } -\newlabel{index_autotoc_md2}{{1.3}{2}{Acknowledgements}{section.1.3}{}} -\@writefile{toc}{\contentsline {section}{\numberline {1.4}Figures}{2}{section.1.4}\protected@file@percent } -\newlabel{index_autotoc_md3}{{1.4}{2}{Figures}{section.1.4}{}} -\newlabel{index_fig1}{{1.4}{2}{Figures}{section.1.4}{}} +\@writefile{toc}{\contentsline {section}{\numberline {1.3}Building the project}{2}{section.1.3}\protected@file@percent } +\newlabel{index_autotoc_md2}{{1.3}{2}{Building the project}{section.1.3}{}} +\@writefile{toc}{\contentsline {subsection}{\numberline {1.3.1}Linux/\discretionary {\mbox {\scriptsize $\hookleftarrow $}}{}{}BSD/\discretionary {\mbox {\scriptsize $\hookleftarrow $}}{}{}Mac\discretionary {\mbox {\scriptsize $\hookleftarrow $}}{}{}OS}{2}{subsection.1.3.1}\protected@file@percent } +\newlabel{index_autotoc_md3}{{1.3.1}{2}{Linux/\+BSD/\+Mac\+OS}{subsection.1.3.1}{}} +\@writefile{toc}{\contentsline {subsection}{\numberline {1.3.2}Windows (\discretionary {\mbox {\scriptsize $\hookleftarrow $}}{}{}Power\discretionary {\mbox {\scriptsize $\hookleftarrow $}}{}{}Shell)}{2}{subsection.1.3.2}\protected@file@percent } +\newlabel{index_autotoc_md4}{{1.3.2}{2}{Windows (\+Power\+Shell)}{subsection.1.3.2}{}} +\@writefile{toc}{\contentsline {section}{\numberline {1.4}Running the tests}{2}{section.1.4}\protected@file@percent } +\newlabel{index_autotoc_md5}{{1.4}{2}{Running the tests}{section.1.4}{}} +\@writefile{toc}{\contentsline {subsection}{\numberline {1.4.1}Linux/\discretionary {\mbox {\scriptsize $\hookleftarrow $}}{}{}BSD/\discretionary {\mbox {\scriptsize $\hookleftarrow $}}{}{}Mac\discretionary {\mbox {\scriptsize $\hookleftarrow $}}{}{}OS}{2}{subsection.1.4.1}\protected@file@percent } +\newlabel{index_autotoc_md6}{{1.4.1}{2}{Linux/\+BSD/\+Mac\+OS}{subsection.1.4.1}{}} +\@writefile{toc}{\contentsline {section}{\numberline {1.5}Acknowledgements}{2}{section.1.5}\protected@file@percent } +\newlabel{index_autotoc_md7}{{1.5}{2}{Acknowledgements}{section.1.5}{}} +\@writefile{toc}{\contentsline {section}{\numberline {1.6}Figures}{2}{section.1.6}\protected@file@percent } +\newlabel{index_autotoc_md8}{{1.6}{2}{Figures}{section.1.6}{}} +\newlabel{index_fig1}{{1.6}{2}{Figures}{section.1.6}{}} \@writefile{lof}{\contentsline {figure}{\numberline {1.1}{\ignorespaces Not available in La\discretionary {\mbox {\scriptsize $\hookleftarrow $}}{}{}Te\discretionary {\mbox {\scriptsize $\hookleftarrow $}}{}{}X!}}{2}{figure.caption.1}\protected@file@percent } \@writefile{toc}{\contentsline {chapter}{\numberline {2}Hierarchical Index}{3}{chapter.2}\protected@file@percent } \@writefile{lof}{\addvspace {10\p@ }} diff --git a/docs/latex/refman.log b/docs/latex/refman.log index 0c9cb4b..a61a76e 100644 --- a/docs/latex/refman.log +++ b/docs/latex/refman.log @@ -1,4 +1,4 @@ -This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020 Funtoo Linux) (preloaded format=pdflatex 2022.4.8) 12 MAY 2022 20:14 +This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020 Funtoo Linux) (preloaded format=pdflatex 2022.4.8) 12 MAY 2022 20:31 entering extended mode restricted \write18 enabled. %&-line parsing enabled. @@ -1019,7 +1019,9 @@ LaTeX Warning: Font shape declaration has incorrect series value `mc'. LaTeX Font Info: Font shape `TS1/phv/m/n' will be (Font) scaled to size 8.99994pt on input line 19. LaTeX Font Info: Font shape `T1/phv/b/n' will be -(Font) scaled to size 6.29996pt on input line 30. +(Font) scaled to size 10.79993pt on input line 26. +LaTeX Font Info: Font shape `T1/phv/b/n' will be +(Font) scaled to size 6.29996pt on input line 26. [1 @@ -1031,7 +1033,7 @@ See the LaTeX manual or LaTeX Companion for explanation. Type H for immediate help. ... -l.39 ...rue]{FMI-OOP-P1_TicketSystem Overview.svg} +l.59 ...rue]{FMI-OOP-P1_TicketSystem Overview.svg} ? ) [2] @@ -1218,8 +1220,6 @@ nput line 18. ] Chapter 5. (./classCommand.tex -LaTeX Font Info: Font shape `T1/phv/b/n' will be -(Font) scaled to size 10.79993pt on input line 12. LaTeX Font Info: Font shape `T1/phv/m/n' will be (Font) scaled to size 8.09995pt on input line 17. LaTeX Font Info: Font shape `T1/phv/m/it' in size <9> not available @@ -1477,7 +1477,7 @@ Underfull \hbox (badness 10000) detected at line 60 [] ) (./classList.tex <./classList.pdf> - + File: classList.pdf Graphic file (type pdf) Package pdftex.def Info: classList.pdf used on input line 15. @@ -1590,7 +1590,7 @@ Package longtable Warning: Column widths have changed (longtable) in table 5.17 on input line 148. ) (./classOrderedList.tex <./classOrderedList.pdf> - + File: classOrderedList.pdf Graphic file (type pdf) Package pdftex.def Info: classOrderedList.pdf used on input line 15. @@ -2080,7 +2080,7 @@ Package rerunfilecheck Warning: File `refman.out' has changed. Package rerunfilecheck Info: Checksums for `refman.out': (rerunfilecheck) Before: -(rerunfilecheck) After: 3440AC0C41982DE2B7FFE393A388B650;41850. +(rerunfilecheck) After: B8054B7EE97E48507319E9C6C798020D;42752. LaTeX Warning: There were undefined references. @@ -2089,10 +2089,10 @@ LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right. ) Here is how much of TeX's memory you used: - 17924 strings out of 482368 - 269195 string characters out of 5952188 - 530503 words of memory out of 5000000 - 32188 multiletter control sequences out of 15000+600000 + 17939 strings out of 482368 + 269445 string characters out of 5952188 + 529503 words of memory out of 5000000 + 32193 multiletter control sequences out of 15000+600000 598871 words of font info for 113 fonts, out of 8000000 for 9000 452 hyphenation exceptions out of 8191 55i,16n,96p,891b,634s stack positions out of 5000i,500n,10000p,200000b,80000s @@ -2107,10 +2107,10 @@ fb> -Output written on refman.pdf (78 pages, 287272 bytes). +Output written on refman.pdf (78 pages, 288245 bytes). PDF statistics: - 2004 PDF objects out of 2073 (max. 8388607) - 1876 compressed objects within 19 object streams - 596 named destinations out of 1000 (max. 500000) + 2015 PDF objects out of 2073 (max. 8388607) + 1887 compressed objects within 19 object streams + 606 named destinations out of 1000 (max. 500000) 11 words of extra memory for PDF output out of 10000 (max. 10000000) diff --git a/docs/latex/refman.pdf b/docs/latex/refman.pdf index 6a4170b..86078ce 100644 Binary files a/docs/latex/refman.pdf and b/docs/latex/refman.pdf differ diff --git a/docs/latex/refman.toc b/docs/latex/refman.toc index 48ee10f..bdfe232 100644 --- a/docs/latex/refman.toc +++ b/docs/latex/refman.toc @@ -2,8 +2,13 @@ \contentsline {chapter}{\numberline {1}FMI Tickets System}{1}{chapter.1}% \contentsline {section}{\numberline {1.1}About}{1}{section.1.1}% \contentsline {section}{\numberline {1.2}Structure overview}{1}{section.1.2}% -\contentsline {section}{\numberline {1.3}Acknowledgements}{2}{section.1.3}% -\contentsline {section}{\numberline {1.4}Figures}{2}{section.1.4}% +\contentsline {section}{\numberline {1.3}Building the project}{2}{section.1.3}% +\contentsline {subsection}{\numberline {1.3.1}Linux/\discretionary {\mbox {\scriptsize $\hookleftarrow $}}{}{}BSD/\discretionary {\mbox {\scriptsize $\hookleftarrow $}}{}{}Mac\discretionary {\mbox {\scriptsize $\hookleftarrow $}}{}{}OS}{2}{subsection.1.3.1}% +\contentsline {subsection}{\numberline {1.3.2}Windows (\discretionary {\mbox {\scriptsize $\hookleftarrow $}}{}{}Power\discretionary {\mbox {\scriptsize $\hookleftarrow $}}{}{}Shell)}{2}{subsection.1.3.2}% +\contentsline {section}{\numberline {1.4}Running the tests}{2}{section.1.4}% +\contentsline {subsection}{\numberline {1.4.1}Linux/\discretionary {\mbox {\scriptsize $\hookleftarrow $}}{}{}BSD/\discretionary {\mbox {\scriptsize $\hookleftarrow $}}{}{}Mac\discretionary {\mbox {\scriptsize $\hookleftarrow $}}{}{}OS}{2}{subsection.1.4.1}% +\contentsline {section}{\numberline {1.5}Acknowledgements}{2}{section.1.5}% +\contentsline {section}{\numberline {1.6}Figures}{2}{section.1.6}% \contentsline {chapter}{\numberline {2}Hierarchical Index}{3}{chapter.2}% \contentsline {section}{\numberline {2.1}Class Hierarchy}{3}{section.2.1}% \contentsline {chapter}{\numberline {3}Class Index}{5}{chapter.3}% diff --git a/tests/Tests_ALL.cpp b/tests/Tests_ALL.cpp new file mode 100644 index 0000000..2252865 --- /dev/null +++ b/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/tests/Tests_Command.cpp b/tests/Tests_Command.cpp deleted file mode 100644 index 6cac193..0000000 --- a/tests/Tests_Command.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include -#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN -#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/tests/Tests_Command.h b/tests/Tests_Command.h new file mode 100644 index 0000000..02325cd --- /dev/null +++ b/tests/Tests_Command.h @@ -0,0 +1,51 @@ +#include +#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/tests/Tests_Date.cpp b/tests/Tests_Date.cpp deleted file mode 100644 index 77e381d..0000000 --- a/tests/Tests_Date.cpp +++ /dev/null @@ -1,195 +0,0 @@ -#include -#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN -#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/tests/Tests_Date.h b/tests/Tests_Date.h new file mode 100644 index 0000000..17878d9 --- /dev/null +++ b/tests/Tests_Date.h @@ -0,0 +1,194 @@ +#include +#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/tests/Tests_Event.cpp b/tests/Tests_Event.cpp deleted file mode 100644 index a27142a..0000000 --- a/tests/Tests_Event.cpp +++ /dev/null @@ -1,89 +0,0 @@ -#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/tests/Tests_Event.h b/tests/Tests_Event.h new file mode 100644 index 0000000..a27142a --- /dev/null +++ b/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/tests/Tests_Hall.cpp b/tests/Tests_Hall.cpp deleted file mode 100644 index 5c3be7e..0000000 --- a/tests/Tests_Hall.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN -#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/tests/Tests_Hall.h b/tests/Tests_Hall.h new file mode 100644 index 0000000..01e5979 --- /dev/null +++ b/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/tests/Tests_Reservation.cpp b/tests/Tests_Reservation.cpp deleted file mode 100644 index ecb1efe..0000000 --- a/tests/Tests_Reservation.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#include -#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN -#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/tests/Tests_Reservation.h b/tests/Tests_Reservation.h new file mode 100644 index 0000000..31efaf9 --- /dev/null +++ b/tests/Tests_Reservation.h @@ -0,0 +1,64 @@ +#include +#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/tests/Tests_String.cpp b/tests/Tests_String.cpp deleted file mode 100644 index 9f6d754..0000000 --- a/tests/Tests_String.cpp +++ /dev/null @@ -1,100 +0,0 @@ -#include -#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN -#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/tests/Tests_String.h b/tests/Tests_String.h new file mode 100644 index 0000000..542b6d8 --- /dev/null +++ b/tests/Tests_String.h @@ -0,0 +1,99 @@ +#include +#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/tests/Tests_Ticket.cpp b/tests/Tests_Ticket.cpp deleted file mode 100644 index 4d0be5c..0000000 --- a/tests/Tests_Ticket.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN -#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(); diff --git a/tests/Tests_Ticket.h b/tests/Tests_Ticket.h new file mode 100644 index 0000000..fc1855c --- /dev/null +++ b/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(); -- cgit v1.3.1-26-gb76a