Website Summary Files Commits Branches @commit @diff @stats
path: root / tests / Test_DateTime.cpp
blob: 1fc827eac127a10656ce3d6f52bd43a2619bdac0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <stdexcept>
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "../doctest/doctest/doctest.h"
#include "../src/DateTime/DateTime.h"

TEST_SUITE_BEGIN("ClassDateTime");

const unsigned short h = 5, m = 12, d = 19, M = 4, y = 2022; // valid values

TEST_SUITE("Constructors") {
	TEST_CASE("Ctor_SavesValues_WhenGivenValidValues") {
		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_WhenGivenInvalidValues") {
		unsigned short h = h, m = m, d = d, M = M, y = y;
		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);
	}
}

TEST_SUITE("GettersAndSetters") {
	TEST_CASE("HourGetter_ReturnsCorrectValue_WhenCreatedWithValidValues") {
		DateTime dt(h, m, d, M, y);

		CHECK_EQ(dt.get_hour(), h);
	}
	TEST_CASE("HourSetter_ReturnTrue_WhenGivenCorrectValue") {
		DateTime dt(h, m, d, M, y);

		CHECK_EQ
	}
}

TEST_SUITE_END();