Belle II Software
release-08-02-06
Main Page
Modules
Namespaces
Namespace List
Namespace Members
All
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Functions
_
a
b
c
d
e
f
g
h
i
l
m
n
o
p
r
s
t
u
v
w
x
z
Variables
a
b
c
d
e
f
g
h
i
l
m
n
o
p
q
r
s
t
v
w
x
z
Typedefs
a
b
c
d
e
g
i
k
l
m
n
p
r
s
t
u
v
w
Enumerations
a
b
c
e
f
g
n
p
s
v
z
Enumerator
c
d
f
p
t
u
v
w
Classes
Class List
Class Hierarchy
Class Members
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Typedefs
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
Enumerations
a
b
c
d
e
f
g
h
i
l
m
o
p
r
s
t
u
v
Enumerator
a
b
c
d
e
f
g
h
k
l
m
n
o
p
r
s
t
u
v
w
z
Related Functions
b
c
d
g
i
o
r
s
t
Files
File List
File Members
All
Functions
Typedefs
Macros
test_caf_machine.py
1
8
import
unittest
9
from
unittest
import
TestCase
10
11
from
caf.state_machines
import
ConditionError, Machine, MachineError
12
13
14
class
Test_Machine
(TestCase):
15
"""
16
Set of tests for checking Machine Base class
17
"""
18
19
def
setUp
(self):
20
"""
21
"""
22
23
self.
m
m = Machine()
24
self.
m
m.add_state(
"standing"
)
25
self.
m
m.add_state(
"walking"
)
26
self.
m
m.add_transition(
"walk"
,
"standing"
,
"walking"
)
27
self.
m
m.add_transition(
"stop"
,
"walking"
,
"standing"
)
28
self.
m
m.initial_state =
"standing"
29
30
def
test_initial
(self):
31
"""
32
Checks that a new machine sets an initial state correctly
33
"""
34
states = [
"walking"
,
"standing"
]
35
initial =
"walking"
36
m = Machine(states, initial)
37
self.assertEqual(m.state.name, initial)
38
39
def
test_set
(self):
40
"""
41
Checks that machine sets at a state
42
"""
43
self.
m
m.state =
"walking"
44
self.assertEqual(self.
m
m.state.name,
"walking"
)
45
46
def
test_bad_set
(self):
47
"""
48
Checks that machine won't set a state not in the list
49
"""
50
with
self.assertRaises(MachineError):
51
self.
m
m.state =
"fake"
52
53
def
test_walk
(self):
54
"""
55
Checks that machine can transition to a state
56
"""
57
self.
m
m.state =
"standing"
58
self.
m
m.walk()
59
self.assertEqual(self.
m
m.state.name,
"walking"
)
60
61
def
test_walk_stop
(self):
62
"""
63
Checks that machine can traverse several states
64
"""
65
self.
m
m.state =
"standing"
66
self.
m
m.walk()
67
self.
m
m.stop()
68
self.assertEqual(self.
m
m.state.name,
"standing"
)
69
70
def
test_true_condition
(self):
71
"""
72
Check that when a condition for a transition evaulates true it will transition
73
to the correct state
74
"""
75
self.
m
m.add_state(
"airborne"
)
76
77
def
can_jump():
78
return
True
79
80
self.
m
m.add_transition(
"jump"
,
"standing"
,
"airborne"
, conditions=can_jump)
81
self.
m
m.state =
"standing"
82
self.
m
m.jump()
83
self.assertEqual(self.
m
m.state.name,
"airborne"
)
84
85
def
test_false_condition
(self):
86
"""
87
Check that when a condition for a transition evaulates false it will raise
88
the correct error.
89
"""
90
self.
m
m.add_state(
"airborne"
)
91
92
def
can_jump():
93
return
False
94
95
self.
m
m.add_transition(
"jump"
,
"standing"
,
"airborne"
, conditions=can_jump)
96
self.
m
m.state =
"standing"
97
with
self.assertRaises(ConditionError):
98
self.
m
m.jump()
99
100
def
test_true_conditions
(self):
101
"""
102
Check that when multiple conditions for a transition all evaulate true it will transition
103
to the correct state
104
"""
105
self.
m
m.add_state(
"airborne"
)
106
107
def
can_jump():
108
return
True
109
110
def
eaten_lunch():
111
return
True
112
self.
m
m.add_transition(
"jump"
,
"standing"
,
"airborne"
, conditions=[can_jump, eaten_lunch])
113
self.
m
m.state =
"standing"
114
self.
m
m.jump()
115
self.assertEqual(self.
m
m.state.name,
"airborne"
)
116
117
def
test_halftrue_conditions
(self):
118
"""
119
Check that when a single condition out of many for a transition evaulates true it will
120
fail to move to the correct state
121
"""
122
self.
m
m.add_state(
"airborne"
)
123
124
def
can_jump():
125
return
True
126
127
def
eaten_lunch():
128
return
False
129
self.
m
m.add_transition(
"jump"
,
"standing"
,
"airborne"
, conditions=[can_jump, eaten_lunch])
130
self.
m
m.state =
"standing"
131
with
self.assertRaises(ConditionError):
132
self.
m
m.jump()
133
134
135
def
main
():
136
unittest.main()
137
138
139
if
__name__ ==
'__main__'
:
140
main
()
test_caf_machine.Test_Machine
Definition:
test_caf_machine.py:14
test_caf_machine.Test_Machine.test_true_condition
def test_true_condition(self)
Definition:
test_caf_machine.py:70
test_caf_machine.Test_Machine.setUp
def setUp(self)
Definition:
test_caf_machine.py:19
test_caf_machine.Test_Machine.test_false_condition
def test_false_condition(self)
Definition:
test_caf_machine.py:85
test_caf_machine.Test_Machine.m
m
Machine for testing.
Definition:
test_caf_machine.py:23
test_caf_machine.Test_Machine.test_initial
def test_initial(self)
Definition:
test_caf_machine.py:30
test_caf_machine.Test_Machine.test_bad_set
def test_bad_set(self)
Definition:
test_caf_machine.py:46
test_caf_machine.Test_Machine.test_true_conditions
def test_true_conditions(self)
Definition:
test_caf_machine.py:100
test_caf_machine.Test_Machine.test_walk
def test_walk(self)
Definition:
test_caf_machine.py:53
test_caf_machine.Test_Machine.test_walk_stop
def test_walk_stop(self)
Definition:
test_caf_machine.py:61
test_caf_machine.Test_Machine.test_halftrue_conditions
def test_halftrue_conditions(self)
Definition:
test_caf_machine.py:117
test_caf_machine.Test_Machine.test_set
def test_set(self)
Definition:
test_caf_machine.py:39
main
Definition:
main.py:1
main
int main(int argc, char **argv)
Run all tests.
Definition:
test_main.cc:91
calibration
tests
test_caf_machine.py
Generated on Tue Jan 28 2025 01:53:10 for Belle II Software by
1.9.1