Skip to content

Commit

Permalink
ElapsedTime -> Duration
Browse files Browse the repository at this point in the history
  • Loading branch information
MacDada committed Apr 24, 2023
1 parent ad8406f commit 775ed25
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 68 deletions.
6 changes: 3 additions & 3 deletions lib/DnAppArduino/src/DnApp/Arduino/Hardware/Board.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <Arduino.h>

#include "DnApp/Common/ElapsedTime.h"
#include "DnApp/Common/Duration.h"

namespace DnApp::Arduino::Hardware {
class Board final {
Expand All @@ -15,8 +15,8 @@ namespace DnApp::Arduino::Hardware {
}

[[nodiscard]]
auto getUptime() const -> DnApp::Common::ElapsedTime {
return DnApp::Common::ElapsedTime{millis()};
auto getUptime() const -> DnApp::Common::Duration {
return DnApp::Common::Duration{millis()};
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <cstdint> // uint32_t, uint16_t, uint8_t

namespace DnApp::Common {
class ElapsedTime final {
class Duration final {
public:
// Accepting `uint32_t` as this is a 32–bit value.
//
Expand All @@ -20,7 +20,7 @@ namespace DnApp::Common {
// -> probably strange behaviour from type size overflows
// -> Maybe I should just force restart when overflow actually occurs?
explicit
ElapsedTime(const uint32_t milliseconds):
Duration(const uint32_t milliseconds):
milliseconds{milliseconds} {
}

Expand Down
63 changes: 63 additions & 0 deletions test/native/DnAppCommon/test_Duration/DurationTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include <unity.h>

#include "DnApp/Common/Duration.h"

namespace {
using DnApp::Common::Duration;

auto testMinimal() -> void {
const auto duration = Duration{0};

TEST_ASSERT_EQUAL_INT(0, duration.getDays());
TEST_ASSERT_EQUAL_INT(0, duration.getHours());
TEST_ASSERT_EQUAL_INT(0, duration.getMinutes());
TEST_ASSERT_EQUAL_INT(0, duration.getSeconds());
TEST_ASSERT_EQUAL_INT(0, duration.getMilliseconds());

TEST_ASSERT_EQUAL_INT(0, duration.getHoursRemainder());
TEST_ASSERT_EQUAL_INT(0, duration.getMinutesRemainder());
TEST_ASSERT_EQUAL_INT(0, duration.getSecondsRemainder());
TEST_ASSERT_EQUAL_INT(0, duration.getMillisecondsRemainder());
}

auto testTypical() -> void {
const auto sevenDaysAndABitMore = 634567224;
const auto duration = Duration{sevenDaysAndABitMore};

TEST_ASSERT_EQUAL_INT(7, duration.getDays());
TEST_ASSERT_EQUAL_INT(176, duration.getHours());
TEST_ASSERT_EQUAL_INT(10576, duration.getMinutes());
TEST_ASSERT_EQUAL_INT(634567, duration.getSeconds());
TEST_ASSERT_EQUAL_INT(634567224, duration.getMilliseconds());

TEST_ASSERT_EQUAL_INT(8, duration.getHoursRemainder());
TEST_ASSERT_EQUAL_INT(16, duration.getMinutesRemainder());
TEST_ASSERT_EQUAL_INT(7, duration.getSecondsRemainder());
TEST_ASSERT_EQUAL_INT(224, duration.getMillisecondsRemainder());
}

auto testMaximal() -> void {
const auto duration = Duration{4294967295};

TEST_ASSERT_EQUAL_INT(49, duration.getDays());
TEST_ASSERT_EQUAL_INT(1193, duration.getHours());
TEST_ASSERT_EQUAL_INT(71582, duration.getMinutes());
TEST_ASSERT_EQUAL_INT(4294967, duration.getSeconds());
TEST_ASSERT_EQUAL_INT(4294967295, duration.getMilliseconds());

TEST_ASSERT_EQUAL_INT(17, duration.getHoursRemainder());
TEST_ASSERT_EQUAL_INT(2, duration.getMinutesRemainder());
TEST_ASSERT_EQUAL_INT(47, duration.getSecondsRemainder());
TEST_ASSERT_EQUAL_INT(295, duration.getMillisecondsRemainder());
}
}

auto main() -> int {
UNITY_BEGIN();

RUN_TEST(testMinimal);
RUN_TEST(testTypical);
RUN_TEST(testMaximal);

return UNITY_END();
}
63 changes: 0 additions & 63 deletions test/native/DnAppCommon/test_ElapsedTime/ElapsedTimeTest.cpp

This file was deleted.

0 comments on commit 775ed25

Please sign in to comment.