Skip to content

Commit 6a208ad

Browse files
committed
Add tests
1 parent 488eba0 commit 6a208ad

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

tests/HostTests/include/modules.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
XX(Libc) \
2323
XX(PreCache) \
2424
XX(BitSet) \
25+
XX(Range) \
2526
XX(String) \
2627
XX(ArduinoString) \
2728
XX(Wiring) \

tests/HostTests/modules/Range.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <HostTests.h>
2+
#include <Data/Range.h>
3+
4+
class RangeTest : public TestGroup
5+
{
6+
public:
7+
RangeTest() : TestGroup(_F("Range"))
8+
{
9+
}
10+
11+
void execute() override
12+
{
13+
TEST_CASE("constexpr")
14+
{
15+
constexpr TRange<int> range(0, 100);
16+
constexpr auto int64 = 120000000000LL;
17+
constexpr auto val = range.clip(int64);
18+
static_assert(val == 100, "Bad clip");
19+
20+
constexpr int64_t tmp = 0x8000000000LL;
21+
static_assert(!range.contains(tmp));
22+
}
23+
24+
TEST_CASE("truncation")
25+
{
26+
constexpr TRange<int8_t> range(0, 100);
27+
int val = 0x1020;
28+
val = range.clip(val);
29+
REQUIRE_EQ(val, 100);
30+
}
31+
32+
TEST_CASE("Membership")
33+
{
34+
constexpr TRange<int8_t> range(0, 100);
35+
int val = 0x8000;
36+
REQUIRE(!range.contains(val));
37+
}
38+
}
39+
};
40+
41+
void REGISTER_TEST(Range)
42+
{
43+
registerGroup<RangeTest>();
44+
}

0 commit comments

Comments
 (0)