Website Summary Files Commits Branches @commit @diff @stats
path: root / tests / Test_DateTime.cpp
diff options
context:
space:
mode:
1 files changed, 19 insertions, 6 deletions
-rw-r--r--tests/Test_DateTime.cpp25
diff --git a/tests/Test_DateTime.cpp b/tests/Test_DateTime.cpp
index 189e988..65763f2 100644
--- a/tests/Test_DateTime.cpp
+++ b/tests/Test_DateTime.cpp
@@ -1,3 +1,4 @@
+#include <stdexcept>
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "../doctest/doctest/doctest.h"
#include "../src/DateTime/DateTime.h"
@@ -6,12 +7,24 @@ TEST_SUITE_BEGIN("ClassDateTime");
TEST_SUITE("Constructors") {
TEST_CASE("Ctor_SavesValues_WhenGivenCorrectOnes") {
- DateTime dt(2, 49, 4, 12, 2022);
- CHECK_EQ(dt.get_hour(), 2);
- CHECK_EQ(dt.get_minute(), 49);
- CHECK_EQ(dt.get_day(), 4);
- CHECK_EQ(dt.get_month(), 12);
- CHECK_EQ(dt.get_year(), 2022);
+ unsigned short h = 5, m = 12, d = 19, M = 4, y = 2022;
+ DateTime dt(h, m, d, M, y);
+ CHECK_EQ(dt.get_hour(), h);
+ CHECK_EQ(dt.get_minute(), m);
+ CHECK_EQ(dt.get_day(), d);
+ CHECK_EQ(dt.get_month(), M);
+ CHECK_EQ(dt.get_year(), y);
+ }
+ TEST_CASE("Ctor_ThrowsInvalidArgumentException_WhenGivenIncorrectValues") {
+ unsigned short h = 5, m = 12, d = 19, M = 4, y = 2022;
+ SUBCASE("HourIsTooBig") { h = 194; }
+ SUBCASE("MinutesAreTooBig") { m = 7032; }
+ SUBCASE("DayIsZero") { d = 0; }
+ SUBCASE("DayIsTooBig") { d = 5721; }
+ SUBCASE("MonthIsZero") { M = 0; }
+ SUBCASE("MonthIsTooBig") { M = 15661; }
+
+ CHECK_THROWS_AS(DateTime dt(h, m, d, M, y), std::invalid_argument);
}
}