-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathtest_MappedDict.cpp
More file actions
102 lines (92 loc) · 2.31 KB
/
test_MappedDict.cpp
File metadata and controls
102 lines (92 loc) · 2.31 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <unity.h>
#include "MappedDict.hpp"
void setUp(void)
{
}
void tearDown(void)
{
}
void test_function_mapped_dict_simple_lookups(void)
{
MappedDict<char, int>::DictEntry_t lookupTable[] = {
{'0', 0},
{'1', 1},
{'2', 2},
};
auto idxLookup = MappedDict<char, int>(lookupTable, 3);
int intIdx;
(void) idxLookup.tryGet('0', &intIdx);
TEST_ASSERT_EQUAL(0, intIdx);
(void) idxLookup.tryGet('1', &intIdx);
TEST_ASSERT_EQUAL(1, intIdx);
(void) idxLookup.tryGet('2', &intIdx);
TEST_ASSERT_EQUAL(2, intIdx);
}
void test_function_mapped_dict_bounds(void)
{
MappedDict<char, int>::DictEntry_t lookupTable[] = {
{'0', 0},
{'1', 1},
};
auto idxLookup = MappedDict<char, int>(lookupTable, 2);
int intIdx;
bool found = idxLookup.tryGet('0', &intIdx);
TEST_ASSERT_EQUAL(0, intIdx);
TEST_ASSERT_TRUE(found);
found = idxLookup.tryGet('2', &intIdx);
TEST_ASSERT_NOT_EQUAL(2, intIdx);
TEST_ASSERT_FALSE(found);
}
void test_function_mapped_dict_zero_size(void)
{
MappedDict<char, int>::DictEntry_t lookupTable[] = {{'\0', 0}};
auto idxLookup = MappedDict<char, int>(lookupTable, 0);
int intIdx;
bool found = idxLookup.tryGet('0', &intIdx);
TEST_ASSERT_FALSE(found);
}
void test_function_mapped_dict_pointer_types(void)
{
MappedDict<const char *, int>::DictEntry_t lookupTable[] = {
{"One", 1},
{"Two", 2},
};
auto idxLookup = MappedDict<const char *, int>(lookupTable, 2);
int intIdx;
bool found = idxLookup.tryGet("One", &intIdx);
TEST_ASSERT_TRUE(found);
TEST_ASSERT_EQUAL(1, intIdx);
found = idxLookup.tryGet("Two", &intIdx);
TEST_ASSERT_TRUE(found);
TEST_ASSERT_EQUAL(2, intIdx);
}
void process()
{
UNITY_BEGIN();
RUN_TEST(test_function_mapped_dict_simple_lookups);
RUN_TEST(test_function_mapped_dict_bounds);
RUN_TEST(test_function_mapped_dict_zero_size);
RUN_TEST(test_function_mapped_dict_pointer_types);
UNITY_END();
}
#if defined(ARDUINO)
#include <Arduino.h>
void setup()
{
delay(2000); // Just if board doesn't support software reset via Serial.DTR/RTS
process();
}
void loop()
{
digitalWrite(13, HIGH);
delay(100);
digitalWrite(13, LOW);
delay(500);
}
#else
int main()
{
process();
return 0;
}
#endif