Belle II Software development
Test_Machine Class Reference
Inheritance diagram for Test_Machine:

Public Member Functions

def setUp (self)
 
def test_initial (self)
 
def test_set (self)
 
def test_bad_set (self)
 
def test_walk (self)
 
def test_walk_stop (self)
 
def test_true_condition (self)
 
def test_false_condition (self)
 
def test_true_conditions (self)
 
def test_halftrue_conditions (self)
 

Public Attributes

 m
 Machine for testing.
 

Detailed Description

Set of tests for checking Machine Base class

Definition at line 14 of file test_caf_machine.py.

Member Function Documentation

◆ setUp()

def setUp (   self)
 

Definition at line 19 of file test_caf_machine.py.

19 def setUp(self):
20 """
21 """
22
23 self.m = Machine()
24 self.m.add_state("standing")
25 self.m.add_state("walking")
26 self.m.add_transition("walk", "standing", "walking")
27 self.m.add_transition("stop", "walking", "standing")
28 self.m.initial_state = "standing"
29

◆ test_bad_set()

def test_bad_set (   self)
Checks that machine won't set a state not in the list

Definition at line 46 of file test_caf_machine.py.

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.state = "fake"
52

◆ test_false_condition()

def test_false_condition (   self)
Check that when a condition for a transition evaulates false it will raise
the correct error.

Definition at line 85 of file test_caf_machine.py.

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.add_state("airborne")
91
92 def can_jump():
93 return False
94
95 self.m.add_transition("jump", "standing", "airborne", conditions=can_jump)
96 self.m.state = "standing"
97 with self.assertRaises(ConditionError):
98 self.m.jump()
99

◆ test_halftrue_conditions()

def test_halftrue_conditions (   self)
Check that when a single condition out of many for a transition evaulates true it will
fail to move to the correct state

Definition at line 117 of file test_caf_machine.py.

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.add_state("airborne")
123
124 def can_jump():
125 return True
126
127 def eaten_lunch():
128 return False
129 self.m.add_transition("jump", "standing", "airborne", conditions=[can_jump, eaten_lunch])
130 self.m.state = "standing"
131 with self.assertRaises(ConditionError):
132 self.m.jump()
133
134

◆ test_initial()

def test_initial (   self)
Checks that a new machine sets an initial state correctly

Definition at line 30 of file test_caf_machine.py.

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

◆ test_set()

def test_set (   self)
Checks that machine sets at a state

Definition at line 39 of file test_caf_machine.py.

39 def test_set(self):
40 """
41 Checks that machine sets at a state
42 """
43 self.m.state = "walking"
44 self.assertEqual(self.m.state.name, "walking")
45

◆ test_true_condition()

def test_true_condition (   self)
Check that when a condition for a transition evaulates true it will transition
to the correct state

Definition at line 70 of file test_caf_machine.py.

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.add_state("airborne")
76
77 def can_jump():
78 return True
79
80 self.m.add_transition("jump", "standing", "airborne", conditions=can_jump)
81 self.m.state = "standing"
82 self.m.jump()
83 self.assertEqual(self.m.state.name, "airborne")
84

◆ test_true_conditions()

def test_true_conditions (   self)
Check that when multiple conditions for a transition all evaulate true it will transition
to the correct state

Definition at line 100 of file test_caf_machine.py.

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.add_state("airborne")
106
107 def can_jump():
108 return True
109
110 def eaten_lunch():
111 return True
112 self.m.add_transition("jump", "standing", "airborne", conditions=[can_jump, eaten_lunch])
113 self.m.state = "standing"
114 self.m.jump()
115 self.assertEqual(self.m.state.name, "airborne")
116

◆ test_walk()

def test_walk (   self)
Checks that machine can transition to a state

Definition at line 53 of file test_caf_machine.py.

53 def test_walk(self):
54 """
55 Checks that machine can transition to a state
56 """
57 self.m.state = "standing"
58 self.m.walk()
59 self.assertEqual(self.m.state.name, "walking")
60

◆ test_walk_stop()

def test_walk_stop (   self)
Checks that machine can traverse several states

Definition at line 61 of file test_caf_machine.py.

61 def test_walk_stop(self):
62 """
63 Checks that machine can traverse several states
64 """
65 self.m.state = "standing"
66 self.m.walk()
67 self.m.stop()
68 self.assertEqual(self.m.state.name, "standing")
69

Member Data Documentation

◆ m

m

Machine for testing.

Definition at line 23 of file test_caf_machine.py.


The documentation for this class was generated from the following file: