Skip to content
Snippets Groups Projects
Commit bff34baf authored by Theodoros Katzalis's avatar Theodoros Katzalis
Browse files

Added tests for the new functions

parent 9082107a
No related branches found
No related tags found
No related merge requests found
...@@ -92,7 +92,7 @@ public: ...@@ -92,7 +92,7 @@ public:
* @return true if \p Now is greater than \p DateExamined. The equality depends on the \p * @return true if \p Now is greater than \p DateExamined. The equality depends on the \p
* equalCondition * equalCondition
*/ */
bool IsAfter(struct TimeAndDate &Now, struct TimeAndDate &Date, bool equalCondition); static bool IsAfter(struct TimeAndDate &Now, struct TimeAndDate &Date, bool equalCondition);
/** /**
* @param Now the date provided from the Real Time Clock(UTC format) * @param Now the date provided from the Real Time Clock(UTC format)
...@@ -103,7 +103,7 @@ public: ...@@ -103,7 +103,7 @@ public:
* @return true if \p Now is smaller than \p DateExamined. The equality depends on the \p * @return true if \p Now is smaller than \p DateExamined. The equality depends on the \p
* equalCondition * equalCondition
*/ */
bool IsBefore(struct TimeAndDate &Now, struct TimeAndDate &Date, bool equalCondition); static bool IsBefore(struct TimeAndDate &Now, struct TimeAndDate &Date, bool equalCondition);
/** /**
* Generate the CDS time format(3.3 in CCSDS 301.0-B-4 standard). * Generate the CDS time format(3.3 in CCSDS 301.0-B-4 standard).
......
...@@ -82,44 +82,44 @@ struct TimeAndDate TimeHelper::utcTime(uint32_t seconds) { ...@@ -82,44 +82,44 @@ struct TimeAndDate TimeHelper::utcTime(uint32_t seconds) {
bool TimeHelper::IsAfter(struct TimeAndDate &Now, struct TimeAndDate &Date, bool bool TimeHelper::IsAfter(struct TimeAndDate &Now, struct TimeAndDate &Date, bool
equalCondition) { equalCondition) {
// compare years // compare years
if (Now.year > Date.year) { if (Now.year < Date.year) {
return true; return true;
} else if (Now.year < Date.year) { } else if (Now.year > Date.year) {
return false; return false;
} }
// compare months // compare months
if (Now.month > Date.month) { if (Now.month < Date.month) {
return true; return true;
} else if (Now.month < Date.month) { } else if (Now.month > Date.month) {
return false; return false;
} }
// compare days // compare days
if (Now.day > Date.day) { if (Now.day < Date.day) {
return true; return true;
} else if (Now.day < Date.day) { } else if (Now.day > Date.day) {
return false; return false;
} }
// compare hours // compare hours
if (Now.hour > Date.hour) { if (Now.hour < Date.hour) {
return true; return true;
} else if (Now.hour < Date.hour) { } else if (Now.hour > Date.hour) {
return false; return false;
} }
// compare minutes // compare minutes
if (Now.minute > Date.minute) { if (Now.minute < Date.minute) {
return true; return true;
} else if (Now.minute < Date.minute) { } else if (Now.minute > Date.minute) {
return false; return false;
} }
// compare seconds // compare seconds
if (Now.second > Date.second) { if (Now.second < Date.second) {
return true; return true;
} else if (Now.second < Date.second) { } else if (Now.second > Date.second) {
return false; return false;
} else if (Now.second == Date.second) } else if (Now.second == Date.second)
return equalCondition; return equalCondition;
...@@ -128,44 +128,44 @@ equalCondition) { ...@@ -128,44 +128,44 @@ equalCondition) {
bool TimeHelper::IsBefore(struct TimeAndDate &Now, struct TimeAndDate &Date, bool bool TimeHelper::IsBefore(struct TimeAndDate &Now, struct TimeAndDate &Date, bool
equalCondition) { equalCondition) {
// compare years // compare years
if (Now.year < Date.year) { if (Now.year > Date.year) {
return true; return true;
} else if (Now.year > Date.year) { } else if (Now.year < Date.year) {
return false; return false;
} }
// compare months // compare months
if (Now.month < Date.month) { if (Now.month > Date.month) {
return true; return true;
} else if (Now.month > Date.month) { } else if (Now.month < Date.month) {
return false; return false;
} }
// compare days // compare days
if (Now.day < Date.day) { if (Now.day > Date.day) {
return true; return true;
} else if (Now.day > Date.day) { } else if (Now.day < Date.day) {
return false; return false;
} }
// compare hours // compare hours
if (Now.hour < Date.hour) { if (Now.hour > Date.hour) {
return true; return true;
} else if (Now.hour > Date.hour) { } else if (Now.hour < Date.hour) {
return false; return false;
} }
// compare minutes // compare minutes
if (Now.minute < Date.minute) { if (Now.minute > Date.minute) {
return true; return true;
} else if (Now.minute > Date.minute) { } else if (Now.minute < Date.minute) {
return false; return false;
} }
// compare seconds // compare seconds
if (Now.second < Date.second) { if (Now.second > Date.second) {
return true; return true;
} else if (Now.second > Date.second) { } else if (Now.second < Date.second) {
return false; return false;
} else if (Now.second == Date.second) } else if (Now.second == Date.second)
return equalCondition; return equalCondition;
......
...@@ -37,7 +37,7 @@ TEST_CASE("Time format implementation", "[CUC]") { ...@@ -37,7 +37,7 @@ TEST_CASE("Time format implementation", "[CUC]") {
CHECK(TimeHelper::generateCDStimeFormat(TimeInfo) == timeFormat); CHECK(TimeHelper::generateCDStimeFormat(TimeInfo) == timeFormat);
} }
SECTION("Convert elapsed seconds since Unix epoch to UTC date"){ SECTION("Convert elapsed seconds since Unix epoch to UTC date") {
uint32_t seconds = 1586513700; // elapsed seconds between 10/04/2020 10:15:00 and Unix epoch uint32_t seconds = 1586513700; // elapsed seconds between 10/04/2020 10:15:00 and Unix epoch
TimeHelper time; TimeHelper time;
...@@ -121,4 +121,157 @@ TEST_CASE("Time format implementation", "[CUC]") { ...@@ -121,4 +121,157 @@ TEST_CASE("Time format implementation", "[CUC]") {
} }
SECTION("Date comparison") {
SECTION("Different year") {
struct TimeAndDate Now = {0};
// 10/04/2021 10:15:00
Now.year = 2021;
Now.month = 4;
Now.day = 10;
Now.hour = 10;
Now.minute = 15;
Now.second = 0;
struct TimeAndDate Date = {0};
// 10/04/2020 10:15:00
Date.year = 2020;
Date.month = 4;
Date.day = 10;
Date.hour = 10;
Date.minute = 15;
Date.second = 0;
CHECK(TimeHelper::IsAfter(Now, Date, true) == false);
CHECK(TimeHelper::IsAfter(Date, Now, true) == true);
CHECK(TimeHelper::IsBefore(Now, Date, true) == true);
CHECK(TimeHelper::IsBefore(Date, Now, true) == false);
}
SECTION("Different month") {
struct TimeAndDate Now = {0};
// 10/05/2020 10:15:00
Now.year = 2020;
Now.month = 5;
Now.day = 10;
Now.hour = 10;
Now.minute = 15;
Now.second = 0;
struct TimeAndDate Date = {0};
// 10/04/2020 10:15:00
Date.year = 2020;
Date.month = 4;
Date.day = 10;
Date.hour = 10;
Date.minute = 15;
Date.second = 0;
CHECK(TimeHelper::IsAfter(Now, Date, true) == false);
CHECK(TimeHelper::IsAfter(Date, Now, true) == true);
CHECK(TimeHelper::IsBefore(Now, Date, true) == true);
CHECK(TimeHelper::IsBefore(Date, Now, true) == false);
}
SECTION("Different day") {
struct TimeAndDate Now = {0};
// 11/04/2020 10:15:00
Now.year = 2020;
Now.month = 5;
Now.day = 11;
Now.hour = 10;
Now.minute = 15;
Now.second = 0;
struct TimeAndDate Date = {0};
// 10/04/2020 10:15:00
Date.year = 2020;
Date.month = 4;
Date.day = 10;
Date.hour = 10;
Date.minute = 15;
Date.second = 0;
CHECK(TimeHelper::IsAfter(Now, Date, true) == false);
CHECK(TimeHelper::IsAfter(Date, Now, true) == true);
CHECK(TimeHelper::IsBefore(Now, Date, true) == true);
CHECK(TimeHelper::IsBefore(Date, Now, true) == false);
}
SECTION("Different hour") {
struct TimeAndDate Now = {0};
// 10/04/2020 11:15:00
Now.year = 2020;
Now.month = 4;
Now.day = 10;
Now.hour = 11;
Now.minute = 15;
Now.second = 0;
struct TimeAndDate Date = {0};
// 10/04/2020 10:15:00
Date.year = 2020;
Date.month = 4;
Date.day = 10;
Date.hour = 10;
Date.minute = 15;
Date.second = 0;
CHECK(TimeHelper::IsAfter(Now, Date, true) == false);
CHECK(TimeHelper::IsAfter(Date, Now, true) == true);
CHECK(TimeHelper::IsBefore(Now, Date, true) == true);
CHECK(TimeHelper::IsBefore(Date, Now, true) == false);
}
SECTION("Different minute") {
struct TimeAndDate Now = {0};
// 11/04/2020 10:16:00
Now.year = 2020;
Now.month = 4;
Now.day = 10;
Now.hour = 10;
Now.minute = 16;
Now.second = 0;
struct TimeAndDate Date = {0};
// 10/04/2020 10:15:00
Date.year = 2020;
Date.month = 4;
Date.day = 10;
Date.hour = 10;
Date.minute = 15;
Date.second = 0;
CHECK(TimeHelper::IsAfter(Now, Date, true) == false);
CHECK(TimeHelper::IsAfter(Date, Now, true) == true);
CHECK(TimeHelper::IsBefore(Now, Date, true) == true);
CHECK(TimeHelper::IsBefore(Date, Now, true) == false);
}
SECTION("Different second") {
struct TimeAndDate Now = {0};
// 11/04/2020 10:15:01
Now.year = 2020;
Now.month = 4;
Now.day = 10;
Now.hour = 10;
Now.minute = 15;
Now.second = 1;
struct TimeAndDate Date = {0};
// 10/04/2020 10:15:00
Date.year = 2020;
Date.month = 4;
Date.day = 10;
Date.hour = 10;
Date.minute = 15;
Date.second = 0;
CHECK(TimeHelper::IsAfter(Now, Date, true) == false);
CHECK(TimeHelper::IsAfter(Date, Now, true) == true);
CHECK(TimeHelper::IsBefore(Now, Date, true) == true);
CHECK(TimeHelper::IsBefore(Date, Now, true) == false);
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment