-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cpp
55 lines (42 loc) · 971 Bytes
/
test.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
#include <vector>
#include <cassert>
#include "HSM.hpp"
using namespace std;
using namespace HSM;
class State: public HSMState {
public:
virtual void on_enter(HSMInfo *info) {
assert(!entered);
entered = true;
}
virtual void on_exit(HSMInfo *info) {
assert(entered);
entered = false;
}
private:
bool entered = false;
};
int main() {
HSMachine hsm;
vector<State*> states;
// Build random state tree
for(int x = 0; x < 10000; x++) {
State *state = new State();
unsigned int rnd = rand();
rnd %= states.size()+1;
if(rnd == states.size())
hsm.add_child_state(state);
else {
states[rnd]->add_child_state(state);
if(rnd % 10 == 0 && !states[rnd]->get_default_state())
states[rnd]->set_default_state(state);
}
states.emplace_back(state);
}
// Perform random transitions
for(int x = 0; x < 1000000; x++) {
unsigned int rnd = rand();
rnd %= states.size();
assert(hsm.transition_to(states[rnd]));
}
}