-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathanonymous_transition.cpp
102 lines (88 loc) · 2.17 KB
/
anonymous_transition.cpp
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 "hsm/hsm.h"
#include <boost/hana.hpp>
#include <gtest/gtest.h>
#include <future>
#include <memory>
namespace {
// States
struct S1 {
};
struct S2 {
};
struct S3 {
};
struct S4 {
};
struct S5 {
};
struct S6 {
};
struct S7 {
};
struct S8 {
};
struct S9 {
};
struct PS1 {
};
struct PS2 {
};
// Events
struct e1 {
};
struct e2 {
};
struct e3 {
};
struct e4 {
};
struct e5 {
};
// Guards
const auto guard = [](auto /*event*/, auto /*source*/, auto /*target*/) { return true; };
// Actions
const auto action = [](auto /*event*/, auto /*source*/, auto /*target*/) {};
using namespace ::testing;
struct MainState {
static constexpr auto make_transition_table()
{
// clang-format off
return hsm::transition_table(
* hsm::state<S1> + hsm::event<e1> = hsm::state<S2>
, hsm::state<S1> + hsm::event<e2> = hsm::state<S4>
, hsm::state<S1> + hsm::event<e3> = hsm::state<S6>
, hsm::state<S1> + hsm::event<e4> = hsm::state<S8>
, hsm::state<S2> = hsm::state<S3>
, hsm::state<S4> / action = hsm::state<S5>
, hsm::state<S6> [guard] = hsm::state<S7>
, hsm::state<S8> [guard] / action = hsm::state<S9>
,*hsm::state<PS1> + hsm::event<e5> = hsm::state<PS2>
);
// clang-format on
}
};
}
class AnonymousTransitionTests : public Test {
protected:
hsm::sm<MainState> sm;
};
TEST_F(AnonymousTransitionTests, should_transit_with_anonymous_transition)
{
sm.process_event(e1 {});
ASSERT_TRUE(sm.is(hsm::state<S3>));
}
TEST_F(AnonymousTransitionTests, should_transit_with_anonymous_transition_and_action)
{
sm.process_event(e2 {});
ASSERT_TRUE(sm.is(hsm::state<S5>));
}
TEST_F(AnonymousTransitionTests, should_transit_with_anonymous_transition_and_guard)
{
sm.process_event(e3 {});
ASSERT_TRUE(sm.is(hsm::state<S7>));
}
TEST_F(AnonymousTransitionTests, should_transit_with_anonymous_transition_and_guard_and_action)
{
sm.process_event(e4 {});
ASSERT_TRUE(sm.is(hsm::state<S9>));
}