CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_Common/tests/test_tsindex.cpp
Views: 1799
1
#include <AP_gtest.h>
2
3
#include <AP_Common/TSIndex.h>
4
DECLARE_TYPESAFE_INDEX(testTSIndex, uint8_t);
5
6
TEST(TSIndex, operators)
7
{
8
testTSIndex test_value = testTSIndex();
9
EXPECT_EQ(0, test_value.get_int());
10
uint8_t test_eq = 1;
11
test_value = 1;
12
EXPECT_EQ(test_eq, test_value.get_int());
13
EXPECT_EQ(test_eq++, (test_value++).get_int());
14
EXPECT_EQ(++test_eq, (++test_value).get_int());
15
test_eq = 1;
16
EXPECT_EQ(test_eq, (test_value % 2).get_int());
17
test_eq = 10;
18
EXPECT_TRUE(test_value < test_eq);
19
test_eq = 3;
20
EXPECT_TRUE(test_value <= test_eq);
21
test_eq = 2;
22
EXPECT_TRUE(test_value >= test_eq);
23
test_eq = 1;
24
EXPECT_TRUE(test_value > test_eq);
25
test_eq = 2;
26
EXPECT_TRUE(test_value != test_eq);
27
test_eq = 3;
28
EXPECT_TRUE(test_value == test_eq);
29
test_eq = 4;
30
EXPECT_EQ(test_eq, (test_value + 1).get_int());
31
test_eq = 3;
32
EXPECT_EQ(test_eq, uint8_t(test_value));
33
}
34
35
TEST(TSIndex, RestrictIDArray)
36
{
37
38
testTSIndex i_0(0);
39
testTSIndex i_1(1);
40
RestrictIDTypeArray<int32_t , 2, testTSIndex> state{};
41
42
EXPECT_EQ(state[i_0], 0);
43
EXPECT_EQ(state[i_1], 0);
44
state[i_1] = 42;
45
EXPECT_EQ(state[i_1], 42);
46
const int32_t state_1 = state[i_1];
47
EXPECT_EQ(state_1, state[i_1]);
48
EXPECT_NE(state_1, state[i_0]);
49
const RestrictIDTypeArray<int32_t , 2, testTSIndex> state_const{42, 43};
50
EXPECT_TRUE(state_const[i_0] == 42);
51
EXPECT_TRUE(state_const[i_1] == 43);
52
}
53
AP_GTEST_MAIN()
54
55