Car Ignition
I want to make a Car that comes ON or stays OFF when I push the start button.
preview
These are the tests I have at the end of the chapter
1import src.car
2import unittest
3
4
5class TestCar(unittest.TestCase):
6
7 def test_park_w_brake_pressed_key_close_start_pressed(self):
8 self.assertTrue(
9 src.car.ignition(
10 start_is_pressed=True,
11 key_is_close=True,
12 brake_is_pressed=True,
13 in_park=True,
14 )
15 )
16 self.assertFalse(
17 src.car.ignition(
18 start_is_pressed=True,
19 key_is_close=True,
20 brake_is_pressed=True,
21 in_park=False,
22 )
23 )
25 def test_park_w_brake_not_pressed_key_close_start_pressed(self):
26 self.assertFalse(
27 src.car.ignition(
28 start_is_pressed=True,
29 key_is_close=True,
30 brake_is_pressed=False,
31 in_park=True,
32 )
33 )
34 self.assertFalse(
35 src.car.ignition(
36 start_is_pressed=True,
37 key_is_close=True,
38 brake_is_pressed=False,
39 in_park=False,
40 )
41 )
43 def test_park_w_brake_pressed_key_not_close_start_pressed(self):
44 self.assertFalse(
45 src.car.ignition(
46 start_is_pressed=True,
47 key_is_close=False,
48 brake_is_pressed=True,
49 in_park=True,
50 )
51 )
52 self.assertFalse(
53 src.car.ignition(
54 start_is_pressed=True,
55 key_is_close=False,
56 brake_is_pressed=True,
57 in_park=False,
58 )
59 )
61 def test_park_w_brake_not_pressed_key_not_close_start_pressed(self):
62 self.assertFalse(
63 src.car.ignition(
64 start_is_pressed=True,
65 key_is_close=False,
66 brake_is_pressed=False,
67 in_park=True,
68 )
69 )
70 self.assertFalse(
71 src.car.ignition(
72 start_is_pressed=True,
73 key_is_close=False,
74 brake_is_pressed=False,
75 in_park=False,
76 )
77 )
79 def test_park_w_brake_pressed_key_close_start_not_pressed(self):
80 self.assertFalse(
81 src.car.ignition(
82 start_is_pressed=False,
83 key_is_close=True,
84 brake_is_pressed=True,
85 in_park=True,
86 )
87 )
88 self.assertFalse(
89 src.car.ignition(
90 start_is_pressed=False,
91 key_is_close=True,
92 brake_is_pressed=True,
93 in_park=False,
94 )
95 )
97 def test_park_w_brake_not_pressed_key_close_start_not_pressed(self):
98 self.assertFalse(
99 src.car.ignition(
100 start_is_pressed=False,
101 key_is_close=True,
102 brake_is_pressed=False,
103 in_park=True,
104 )
105 )
106 self.assertFalse(
107 src.car.ignition(
108 start_is_pressed=False,
109 key_is_close=True,
110 brake_is_pressed=False,
111 in_park=False,
112 )
113 )
115 def test_park_w_brake_pressed_key_not_close_start_not_pressed(self):
116 self.assertFalse(
117 src.car.ignition(
118 start_is_pressed=False,
119 key_is_close=False,
120 brake_is_pressed=True,
121 in_park=True,
122 )
123 )
124 self.assertFalse(
125 src.car.ignition(
126 start_is_pressed=False,
127 key_is_close=False,
128 brake_is_pressed=True,
129 in_park=False,
130 )
131 )
133 def test_park_w_brake_not_pressed_key_not_close_start_not_pressed(self):
134 self.assertFalse(
135 src.car.ignition(
136 start_is_pressed=False,
137 key_is_close=False,
138 brake_is_pressed=False,
139 in_park=True,
140 )
141 )
142 self.assertFalse(
143 src.car.ignition(
144 start_is_pressed=False,
145 key_is_close=False,
146 brake_is_pressed=False,
147 in_park=False,
148 )
149 )
150
151
152# Exceptions seen
153# AssertionError
154# NameError
155# AttributeError
156# TypeError
157# SyntaxError
start the project
I open a terminal
I open
makePythonTdd.shI change the name of the project to
carinmakePythonTdd.shI run
makePythonTdd.shin the terminal to make thecarproject./makePythonTdd.sh
I open
makePythonTdd.ps1I change the name of the project to
carinmakePythonTdd.ps1I run
makePythonTdd.ps1in the terminal to make thecarproject.\makePythonTdd.ps1
the terminal is my friend, and shows AssertionError
======================== FAILURES ========================= _________________ TestCar.test_failure ____________________ self = <tests.test_car.TestCar testMethod=test_failure> def test_failure(self): > self.assertFalse(True) E AssertionError: True is not false tests/test_car.py:7: AssertionError ================ short test summary info ================== FAILED tests/test_car.py::TestCar::test_failure - AssertionError: True is not false ==================== 1 failed in X.YZs ====================I open
test_car.pyfrom thetestsfolderI change True to False in
tests/test_car.pythe test passes.
I open a new terminal then change directory to
carI add a git commit message
I want the car to come ON only when the start button is pressed. I get this truth table
start button |
output |
|---|---|
pressed |
True |
NOT pressed |
False |
where True is the Car comes ON and False is it stays OFF.
test_start_pressed
RED: make it fail
I go back to the terminal where the tests are running
I change test_failure to test_start_pressed, then add an assertion for if the start button is pressed
start button
output
pressed
True
the terminal is my friend, and shows NameError
NameError: name 'src' is not definedbecause I do not have a definition for
srcintests/test_car.py.
GREEN: make it pass
I add NameError to the list of Exceptions seen
I add an import statement at the top of the file
1import src.car 2import unittest 3 4 5class TestCar(unittest.TestCase):the terminal is my friend, and shows AttributeError
AttributeError: module 'src.car' has no attribute 'ignition'because the
carmodule does not have anything namedignitionin it.I add AttributeError to the list of Exceptions seen
I delete all the text in the file then add a function named
ignitiontosrc/car/__init__.py1def ignition(): 2 return Nonethe terminal is my friend, and shows TypeError
TypeError: ignition() got an unexpected keyword argument 'start_is_pressed'because the test called the
ignitionfunction with a name (start_is_pressed) that is not in the parentheses of its definition.I add TypeError to the list of Exceptions seen, in
tests/test_car.pyI add
start_is_pressedto the function signature1def ignition(start_is_pressed): 2 return Nonethe terminal is my friend, and shows AssertionError
AssertionError: None is not truebecause the
ignitionfunction returns None and the assertion expects True.I change the return statement to give the test what it wants
1def ignition(start_is_pressed): 2 return Truethe test passes.
The ignition function always returns True.
ignition(start_is_pressed=True ) -> True
test_start_not_pressed
RED: make it fail
I go back to the terminal where the tests are running
I add a test with an assertion for if the start button is NOT pressed
start button
output
NOT pressed
False
the terminal is my friend, and shows AssertionError
AssertionError: True is not falsebecause the function always returns True and the assertion expects False.
GREEN: make it pass
I change the return statement
1def ignition(start_is_pressed): 2 return start_is_pressedthe test passes.
ignition(start_is_pressed=False) -> False ignition(start_is_pressed=True ) -> True
The ignition function always returns the value of start_is_pressed. Is this the Identity Function?
I want the car to come ON only when the start button is pressed AND the key is close to the ignition. The inputs to the ignition will then be
was the start button pressed?
is the key close to the ignition?
Which gives me this truth table
key |
start button |
output |
|---|---|---|
close |
pressed |
True |
NOT close |
pressed |
False |
close |
NOT pressed |
False |
NOT close |
NOT pressed |
False |
test_key_close_start_pressed
RED: make it fail
I go back to the terminal where the tests are running
I add
key_is_closewith a value to the call to theignitionfunction from test_start_pressed for if the start button is pressed AND the key is close to the ignitionkey
start button
output
close
pressed
True
the terminal is my friend, and shows TypeError
TypeError: ignition() got an unexpected keyword argument 'key_is_close'because the test called the
ignitionfunction with a name (key_is_close) that is not in the parentheses of its definition.
GREEN: make it pass
I add
key_is_closeto the function definition insrc/car/__init__.py1def ignition(start_is_pressed, key_is_close): 2 return start_is_pressedthe terminal is my friend, and shows TypeError
TypeError: ignition() missing 1 required positional argument: 'key_is_close'because the assertion in test_start_not_pressed calls the
ignitionfunction with one argument (start_is_pressed) and I just changed the function to make it take two required arguments (key_is_closeandstart_is_pressed). I have to makekey_is_closea choice.I add a default value for
key_is_closeto make it a choice1def ignition(start_is_pressed, key_is_close=False): 2 return start_is_pressedthe test passes.
ignition(key_is_close=True , start_is_pressed=True ) -> True
REFACTOR: make it better
I change the name of test_start_pressed to test_key_close_start_pressed
test_key_not_close_start_pressed
RED: make it fail
I go back to the terminal where the tests are running
I add a test with an assertion for if the start button is pressed AND the key is NOT close to the ignition, in
tests/test_car.pykey
start button
output
NOT close
pressed
False
the terminal is my friend, and shows AssertionError
AssertionError: True is not falsebecause the
ignitionfunction returns True and the assertion expects False.I do not need to add a value for the
key_is_closeparameter sincesrc.car.ignition( start_is_pressed=True )is the same as
src.car.ignition( start_is_pressed=True, key_is_close=False, )because a function uses the default value for a parameter when it is called without the parameter.
GREEN: make it pass
I add an if statement to src/car/__init__.py
1def ignition(start_is_pressed, key_is_close=False):
2 if key_is_close == False:
3 return False
4 return start_is_pressed
the test passes.
REFACTOR: make it better
I want the
ignitionfunction to check if the start button is pressed before it checks if the key is close to the ignition since there is no need to check for the key if the button is NOT pressed. I change the if statement1def ignition(start_is_pressed, key_is_close=False): 2 # if key_is_close == False: 3 # return False 4 # return start_is_pressed 5 if start_is_pressed: 6 return key_is_closethe test is still green.
I remove the commented lines from the
ignitionfunction1def ignition(start_is_pressed, key_is_close=False): 2 if start_is_pressed: 3 return key_is_close
When the ignition function is called it checks if the start button is pressed. If the start button is pressed it returns the value of key_is_close (True if it is close, False if it is NOT close.
ignition(key_is_close=False, start_is_pressed=True ) -> False
ignition(key_is_close=True , start_is_pressed=True ) -> True
test_key_close_start_not_pressed
I go back to the terminal where the tests are running
I add a value for the
key_is_closeparameter to the assertion in test_start_not_pressed for if the start button is NOT pressed AND the key is close to the ignition, intests/test_car.pykey
start button
output
close
NOT pressed
False
the test is still green.
I change the name from test_start_not_pressed to test_key_close_start_not_pressed
When the ignition function is called it checks if the start button is pressed. If the start button is pressed it returns the value of key_is_close (True if it is close, False if it is NOT close.
ignition(key_is_close=True , start_is_pressed=False) -> False
ignition(key_is_close=False, start_is_pressed=True ) -> False
ignition(key_is_close=True , start_is_pressed=True ) -> True
test_key_not_close_start_not_pressed
RED: make it fail
I go back to the terminal where the tests are running
I add a test with an assertion for if the start button is NOT pressed AND the key is NOT close to the ignition, in
tests/test_car.pykey
start button
output
NOT close
NOT pressed
False
the terminal is my friend, and shows AssertionError
AssertionError: None is not truebecause all functions return None by default.
I do not give a value for the
key_is_closeparameter sincesrc.car.ignition( start_is_pressed=False, )is the same as
src.car.ignition( start_is_pressed=False, key_is_close=False, )because a function uses the default value for a parameter when it is called without the parameter.
GREEN: make it pass
I add a return statement to the
ignitionfunction to make it clearer, insrc/car/__init__.py1def ignition(start_is_pressed, key_is_close=False): 2 if start_is_pressed: 3 return key_is_close 4 return Nonethe terminal still shows AssertionError
I change None to False in the return statement
1def ignition(start_is_pressed, key_is_close=False): 2 if start_is_pressed: 3 return key_is_close 4 return Falsethe terminal is my friend, and shows AssertionError
AssertionError: False is not trueI change assertTrue to assertFalse to match
realityin test_key_not_close_start_not_pressed intests/test_car.pythe test passes.
ignition(key_is_close=False, start_is_pressed=False) -> False ignition(key_is_close=True , start_is_pressed=False) -> False ignition(key_is_close=False, start_is_pressed=True ) -> False ignition(key_is_close=True , start_is_pressed=True ) -> TrueI add a git commit message in the other terminal
git commit -am \ 'add test_key_not_close_start_not_pressed'
When the ignition function is called. It checks if the start button is pressed.
If the start button is NOT pressed it returns False
src.car.ignition( key_is_close=False, start_is_pressed=False ) -> False └── src/car/__init__.py └── def ignition(start_is_pressed, key_is_close=False): ├── if start_is_pressed: │ return key_is_close └── return Falsesrc.car.ignition( key_is_close=True, start_is_pressed=False ) -> False └── src/car/__init__.py └── def ignition(start_is_pressed, key_is_close=False): ├── if start_is_pressed: │ return key_is_close └── return FalseIf the start button is pressed it returns the value of
key_is_closeif the key is NOT close to the ignition it returns False
src.car.ignition( key_is_close=False, start_is_pressed=True ) -> False └── src/car/__init__.py └── def ignition(start_is_pressed, key_is_close=False): └── if start_is_pressed: └── return key_is_close return False return Falseif the key is close to the ignition it returns True
src.car.ignition( key_is_close=True, start_is_pressed=True ) -> True └── src/car/__init__.py └── def ignition(start_is_pressed, key_is_close=False): └── if start_is_pressed: └── return key_is_close return True return False
remove reality variable
I can call the ignition function directly in all the assertions.
I call
src.car.ignitiondirectly in the assertion of test_key_not_close_start_not_pressedthe test is still green.
I remove the commented lines from test_key_not_close_start_not_pressed
I call
src.car.ignitiondirectly in the assertion of test_key_close_start_not_pressedstill green.
I remove the commented lines from test_key_close_start_not_pressed
I call
src.car.ignitiondirectly in the assertion of test_key_not_close_start_pressedgreen.
I remove the commented lines from test_key_not_close_start_pressed
I call
src.car.ignitiondirectly in the assertion of test_key_close_start_pressedthe test is still green.
I remove the commented lines from test_key_close_start_pressed
I add a git commit message in the other terminal
git commit -am 'remove reality variable'
So far, the truth table for the ignition is
key |
start button |
output |
|---|---|---|
close |
pressed |
True |
NOT close |
pressed |
False |
close |
NOT pressed |
False |
NOT close |
NOT pressed |
False |
I want the car to come ON only when the start button is pressed AND the key is close to the ignition AND the brake pedal is pressed. The inputs to the ignition will then be
was the start button pressed?
is the key close to the ignition?
is the brake being pressed?
test_brake_pressed_key_close_start_pressed
RED: make it fail
I go back to the terminal where the tests are running
I add a value for
brake_is_pressedto the assertion in test_key_close_start_pressed, for if the start button is pressed AND the key is close to the ignition AND the brake is being pressedkey
brake
start button
output
close
pressed
pressed
True
the terminal is my friend, and shows TypeError
TypeError: ignition() got an unexpected keyword argument 'brake_is_pressed'. Did you mean 'start_is_pressed'?because the test called the
ignitionfunction with a name (brake_is_pressed) that is not in the parentheses of its definition.
GREEN: make it pass
I add
brake_is_pressedto the function signature insrc/car/__init__.py1def ignition( 2 start_is_pressed, key_is_close=False, 3 brake_is_pressed, 4 ): 5 if start_is_pressed: 6 return key_is_close 7 return Falsethe terminal is my friend, and shows SyntaxError
SyntaxError: parameter without a default follows parameter with a defaultbecause parameters without default values must come before parameters with default values.
I add SyntaxError to the list of Exceptions seen, in
tests/test_car.pyI add a default value for the
brake_is_pressedparameter, insrc/car/__init__.py1def ignition( 2 start_is_pressed, key_is_close=False, 3 brake_is_pressed=False, 4 ): 5 if not key_is_close: 6 return False 7 return start_is_pressedthe test passes.
ignition( start_is_pressed=True, key_is_close=True, brake_is_pressed=True ) -> True
REFACTOR: make it better
I change the name from test_key_close_start_pressed to test_brake_pressed_key_close_start_pressed
test_brake_not_pressed_key_close_start_pressed
RED: make it fail
I go back to the terminal where the tests are running
I add a new test with an assertion for if the start button is pressed AND the key is close to the ignition AND the brake is NOT pressed
key
brake
start button
output
close
NOT pressed
pressed
False
the terminal is my friend, and shows AssertionError
AssertionError: True is not falsebecause the
ignitionfunction returned True and the assertion expects False. I do not need to give a value for thebrake_is_pressedparameter since it is the same as the default value, I do it to make things clearer.
GREEN: make it pass
I add an if statement to the
ignitionfunction insrc/car/__init__.py1def ignition( 2 start_is_pressed, key_is_close=False, 3 brake_is_pressed=False, 4 ): 5 if brake_is_pressed == False: 6 return False 7 if start_is_pressed: 8 return key_is_close 9 return Falsethe test passes.
I write a simpler version of the new if statement
still green, because
if something == Falseis the same asif not something == Trueis the same asif not something.I want the
ignitionfunction to only check if the brake is pressed if the start button is pressed AND the key is close to the ignition. I change the if statementsI remove the commented lines from the
ignitionfunction1def ignition( 2 start_is_pressed, key_is_close=False, 3 brake_is_pressed=False, 4 ): 5 if start_is_pressed: 6 if key_is_close: 7 return brake_is_pressed 8 return False
When the ignition function is called. It checks if the start button is pressed.
If the start button is NOT pressed it returns False
If the start button is pressed it checks if the key is close to the ignition
if the key is NOT close to the ignition it leaves the if statements then returns False
if the key is close to the ignition it returns the value of
brake_is_pressedif the brake is NOT pressed it returns False
if the brake is pressed it returns True
ignition(
start_is_pressed=True, key_is_close=True,
brake_is_pressed=False
) -> False
ignition(
start_is_pressed=True, key_is_close=True,
brake_is_pressed=True
) -> True
test_brake_pressed_key_not_close_start_pressed
I add values for the
key_is_closeandbrake_is_pressedparameters to the assertion in test_key_not_close_start_pressed for if the start button is pressed AND the key is NOT close to the ignition AND the brake is being pressedkey
brake
start button
output
NOT close
pressed
pressed
False
the test is still green.
ignition( start_is_pressed=True, key_is_close=False, brake_is_pressed=True ) -> False ignition( start_is_pressed=True, key_is_close=True, brake_is_pressed=False ) -> False ignition( start_is_pressed=True, key_is_close=True, brake_is_pressed=True ) -> TrueI change the name of the test from test_key_not_close_start_pressed to test_brake_pressed_key_not_close_start_pressed
I add a git commit message in the other terminal
git commit -am \ 'add test_brake_pressed_key_not_close_start_pressed'
test_brake_not_pressed_key_not_close_start_pressed
RED: make it fail
I go back to the terminal where the tests are running
I add a test with an assertion for if the start button is pressed AND the key is NOT close to the ignition AND the brake is NOT pressed
key
brake
start button
output
NOT close
NOT pressed
pressed
False
the terminal is my friend, and shows AssertionError
AssertionError: False is not true
GREEN: make it pass
I change assertTrue to assertFalse to match the result of the call to the
ignitionfunctionthe test passes.
When the ignition function is called. It checks if the start button is pressed.
If the start button is NOT pressed it returns False
If the start button is pressed it checks if the key is close to the ignition
if the key is NOT close to the ignition it leaves the if statements then returns False
src.car.ignition( start_is_pressed=True, key_is_close=False, brake_is_pressed=False ) -> False └── src/car/__init__.py └── def ignition( start_is_pressed, key_is_close=False, brake_is_pressed=False, ): └── if start_is_pressed: ┌───┴── if key_is_close: │ return brake_is_pressed └── return Falsesrc.car.ignition( start_is_pressed=True, key_is_close=False, brake_is_pressed=True ) -> False └── src/car/__init__.py └── def ignition( start_is_pressed, key_is_close=False, brake_is_pressed=False, ): └── if start_is_pressed: ┌───┴── if key_is_close: │ return brake_is_pressed └── return Falseif the key is close to the ignition it returns the value of
brake_is_pressedif the brake is NOT pressed it returns False
src.car.ignition( start_is_pressed=True, key_is_close=True, brake_is_pressed=False ) -> False └── src/car/__init__.py └── def ignition( start_is_pressed, key_is_close=False, brake_is_pressed=False, ): └── if start_is_pressed: └── if key_is_close: └── return brake_is_pressed return False return Falseif the brake is pressed it returns True
src.car.ignition( start_is_pressed=True, key_is_close=True, brake_is_pressed=True ) -> True └── src/car/__init__.py └── def ignition( start_is_pressed, key_is_close=False, brake_is_pressed=False, ): └── if start_is_pressed: └── if key_is_close: └── return brake_is_pressed return True return False
test_brake_pressed_key_close_start_not_pressed
I go back to the terminal where the tests are running
I add a value for the
brake_is_pressedparameter to the assertion in test_key_close_start_not_pressed for the case where the start button is NOT pressed AND the key is close to the ignition AND the brake is being pressedkey
brake
start button
output
close
pressed
NOT pressed
False
the test is still green.
ignition( start_is_pressed=False, key_is_close=True, brake_is_pressed=True ) -> FalseI change the name from test_key_close_start_not_pressed to test_brake_pressed_key_close_start_not_pressed
test_brake_not_pressed_key_close_start_not_pressed
RED: make it fail
I go back to the terminal where the tests are running
I add a test with an assertion, for if the start button is NOT pressed AND the key is close to the ignition AND the brake is NOT pressed
key
brake
start button
output
close
NOT pressed
NOT pressed
False
the terminal is my friend, and shows AssertionError
AssertionError: False is not true
GREEN: make it pass
I change assertTrue to assertFalse to match reality
the test passes.
ignition( start_is_pressed=False, key_is_close=True, brake_is_pressed=False ) -> False ignition( start_is_pressed=False, key_is_close=True, brake_is_pressed=True ) -> False
test_brake_pressed_key_not_close_start_not_pressed
I go back to the terminal where the tests are running
I add values for the
key_is_closeandbrake_is_pressedparameters to test_key_not_close_start_not_pressed for if the start button is NOT pressed AND the key is NOT close to the ignition AND the brake is being pressedkey
brake
start button
output
NOT close
pressed
NOT pressed
False
the test is still green.
ignition( start_is_pressed=False, key_is_close=False, brake_is_pressed=True ) -> False ignition( start_is_pressed=False, key_is_close=True, brake_is_pressed=False ) -> False ignition( start_is_pressed=False, key_is_close=True, brake_is_pressed=True ) -> FalseI change the name from test_key_not_close_start_not_pressed to test_brake_pressed_key_not_close_start_not_pressed
test_brake_not_pressed_key_not_close_start_not_pressed
I go back to the terminal where the tests are running
I add a test with an assertion for if the start button is NOT pressed AND the key is NOT close to the ignition AND the brake is NOT pressed
key
brake
start button
output
NOT close
NOT pressed
NOT pressed
False
the terminal is my friend, and shows AssertionError
AssertionError: False is not true
GREEN: make it pass
I change assertTrue to assertFalse to match the result of the call to
src.car.ignitionin test_brake_not_pressed_key_not_close_start_not_pressedthe test passes.
I add a git commit message in the other terminal
git commit -am \ 'add test_brake_not_pressed_key_not_close_start_not_pressed'
When the ignition function is called. It checks if the start button is pressed.
If the start button is NOT pressed it returns False
src.car.ignition( start_is_pressed=False, key_is_close=False, brake_is_pressed=False ) -> False └── src/car/__init__.py └── def ignition( start_is_pressed, key_is_close=False, brake_is_pressed=False, ): ├── if start_is_pressed: │ if key_is_close: │ return brake_is_pressed └── return Falsesrc.car.ignition( start_is_pressed=False, key_is_close=False, brake_is_pressed=True ) -> False └── src/car/__init__.py └── def ignition( start_is_pressed, key_is_close=False, brake_is_pressed=False, ): ├── if start_is_pressed: │ if key_is_close: │ return brake_is_pressed └── return Falsesrc.car.ignition( start_is_pressed=False, key_is_close=True, brake_is_pressed=False ) -> False └── src/car/__init__.py └── def ignition( start_is_pressed, key_is_close=False, brake_is_pressed=False, ): ├── if start_is_pressed: │ if key_is_close: │ return brake_is_pressed └── return Falsesrc.car.ignition( start_is_pressed=False, key_is_close=True, brake_is_pressed=True ) -> False └── src/car/__init__.py └── def ignition( start_is_pressed, key_is_close=False, brake_is_pressed=False, ): ├── if start_is_pressed: │ if key_is_close: │ return brake_is_pressed └── return FalseIf the start button is pressed it checks if the key is close to the ignition
if the key is NOT close to the ignition it leaves the if statements then returns False
src.car.ignition( start_is_pressed=True, key_is_close=False, brake_is_pressed=False ) -> False └── src/car/__init__.py └── def ignition( start_is_pressed, key_is_close=False, brake_is_pressed=False, ): └── if start_is_pressed: ┌───┴── if key_is_close: │ return brake_is_pressed └── return Falsesrc.car.ignition( start_is_pressed=True, key_is_close=False, brake_is_pressed=True ) -> False └── src/car/__init__.py └── def ignition( start_is_pressed, key_is_close=False, brake_is_pressed=False, ): └── if start_is_pressed: ┌───┴── if key_is_close: │ return brake_is_pressed └── return Falseif the key is close to the ignition it returns the value of
brake_is_pressedif the brake is NOT pressed it returns False
src.car.ignition( start_is_pressed=True, key_is_close=True, brake_is_pressed=False ) -> False └── src/car/__init__.py └── def ignition( start_is_pressed, key_is_close=False, brake_is_pressed=False, ): └── if start_is_pressed: └── if key_is_close: └── return brake_is_pressed return False return Falseif the brake is pressed it returns True
src.car.ignition( start_is_pressed=True, key_is_close=True, brake_is_pressed=True ) -> True └── src/car/__init__.py └── def ignition( start_is_pressed, key_is_close=False, brake_is_pressed=False, ): └── if start_is_pressed: └── if key_is_close: └── return brake_is_pressed return True return False
The truth table for the Car Ignition is
key |
brake |
start button |
output |
|---|---|---|---|
NOT close |
NOT pressed |
pressed |
False |
NOT close |
pressed |
pressed |
False |
close |
NOT pressed |
pressed |
False |
close |
pressed |
pressed |
True |
key |
brake |
start button |
output |
|---|---|---|---|
NOT close |
NOT pressed |
NOT pressed |
False |
NOT close |
pressed |
NOT pressed |
False |
close |
NOT pressed |
NOT pressed |
False |
close |
pressed |
NOT pressed |
False |
I want to make sure the car is in park before it can start, so it does not immediately move when it is turned on (that would be a problem). The inputs will then be
was the start button pressed?
is the key close to the ignition?
is the brake being pressed?
is the gear in park?
test_park_w_brake_not_pressed_key_not_close_start_not_pressed
RED: make it fail
I go back to the terminal where the tests are running
I add a value for
in_parkto the assertion in test_brake_not_pressed_key_not_close_start_not_pressed for the case where the start button is NOT pressed AND the key is NOT close to the ignition AND the brake is being NOT pressed AND the car gear is in park, to test_brake_not_pressed_key_not_close_start_not_pressedkey
brake
start
gear
output
NOT close
NOT pressed
NOT pressed
in park
False
the terminal shows TypeError
TypeError: ignition() got an unexpected keyword argument 'in_park'because the test called the
ignitionfunction with a name (in_park) that is not in the parentheses of its definition.
GREEN: make it pass
I add
in_parkto the function signature insrc/car/__init__.py1def ignition( 2 start_is_pressed, key_is_close=False, 3 brake_is_pressed=False, in_park, 4 ): 5 if start_is_pressed: 6 if key_is_close: 7 return brake_is_pressed 8 return Falsethe terminal is my friend, and shows SyntaxError
SyntaxError: parameter without a default follows parameter with a defaultbecause parameters without default values must come before parameters with default values.
I add a default value for the
in_parkparameter in the function signature to make it a choice1def ignition( 2 start_is_pressed, key_is_close=False, 3 brake_is_pressed=False, in_park=False, 4 ):the test passes.
ignition( start_is_pressed=False, key_is_close=False, brake_is_pressed=False, in_park=True ) -> False
REFACTOR: make it better
I add an assertion for if the start button is NOT pressed AND the key is NOT close to the ignition AND the brake is being NOT pressed AND the car gear is NOT in park
key
brake
start
gear
output
NOT close
NOT pressed
NOT pressed
NOT in park
False
the terminal is my friend, and shows AssertionError
AssertionError: False is not truebecause the
ignitionfunction returns False and the assertion expects TrueI change assertTrue to assertFalse to match the result of the call
the test passes.
ignition( start_is_pressed=False, key_is_close=False, brake_is_pressed=False, in_park=True ) -> False ignition( start_is_pressed=False, key_is_close=False, brake_is_pressed=False, in_park=False ) -> FalseI change the name of the test to from test_brake_not_pressed_key_not_close_start_not_pressed to test_park_w_brake_not_pressed_key_not_close_start_not_pressed
test_park_w_brake_pressed_key_not_close_start_not_pressed
RED: make it fail
I go back to the terminal where the tests are running
I add a value for the
in_parkparameter to the assertion in test_brake_pressed_key_not_close_start_not_pressed for if the start button is NOT pressed AND the key is NOT close to the ignition AND the brake is being pressed AND the car gear is in parkkey
brake
start
gear
output
NOT close
pressed
NOT pressed
in park
False
the test is still green.
ignition( start_is_pressed=False, key_is_close=False, brake_is_pressed=True, in_park=True ) -> FalseI add an assertion for if the start button is NOT pressed AND the key is NOT close to the ignition AND the brake is being pressed AND the car gear is NOT in park
key
brake
start
gear
output
NOT close
pressed
NOT pressed
NOT in park
False
the terminal is my friend, and shows AssertionError
AssertionError: False is not true
GREEN: make it pass
I change assertTrue to assertFalse in test_brake_pressed_key_not_close_start_not_pressed
61 def test_brake_pressed_key_not_close_start_not_pressed(self):
62 self.assertFalse(
63 src.car.ignition(
64 start_is_pressed=False,
65 key_is_close=False,
66 brake_is_pressed=True,
67 in_park=True,
68 )
69 )
70 self.assertFalse(
71 src.car.ignition(
72 start_is_pressed=False,
73 key_is_close=False,
74 brake_is_pressed=True,
75 in_park=False,
76 )
77 )
78
79 def test_brake_not_pressed_key_not_close_start_not_pressed(self):
the test passes.
ignition(
start_is_pressed=False, key_is_close=False,
brake_is_pressed=True, in_park=True
) -> False
ignition(
start_is_pressed=False, key_is_close=False,
brake_is_pressed=True, in_park=False
) -> False
REFACTOR: make it better
I change the name from test_brake_pressed_key_not_close_start_not_pressed to test_park_w_brake_pressed_key_not_close_start_not_pressed
test_park_w_brake_not_pressed_key_close_start_not_pressed
RED: make it fail
I go back to the terminal where the tests are running
I add a value for the
in_parkparameter to the assertion in test_brake_not_pressed_key_close_start_not_pressed for if the start button is NOT pressed AND the key is close to the ignition AND the brake is NOT pressed AND the car gear is in parkkey
brake
start
gear
output
close
NOT pressed
NOT pressed
in park
False
the test is still green.
ignition( start_is_pressed=False, key_is_close=True, brake_is_pressed=False, in_park=True ) -> FalseI add an assertion for if the start button is NOT pressed AND the key is close to the ignition AND the brake is NOT pressed AND the car gear is NOT in park
key
brake
start
gear
output
close
NOT pressed
NOT pressed
NOT in park
False
the terminal is my friend, and shows AssertionError
AssertionError: False is not true
GREEN: make it pass
I change assertTrue to assertFalse in test_brake_not_pressed_key_close_start_not_pressed
52 def test_brake_not_pressed_key_close_start_not_pressed(self):
53 self.assertFalse(
54 src.car.ignition(
55 start_is_pressed=False,
56 key_is_close=True,
57 brake_is_pressed=False,
58 in_park=True,
59 )
60 )
61 self.assertFalse(
62 src.car.ignition(
63 start_is_pressed=False,
64 key_is_close=True,
65 brake_is_pressed=False,
66 in_park=False,
67 )
68 )
69
70 def test_park_w_brake_pressed_key_not_close_start_not_pressed(self):
the test passes.
ignition(
start_is_pressed=False, key_is_close=True,
brake_is_pressed=False, in_park=True
) -> False
ignition(
start_is_pressed=False, key_is_close=True,
brake_is_pressed=False, in_park=False
) -> False
REFACTOR: make it better
I change the name of the test from test_brake_not_pressed_key_close_start_not_pressed to test_park_w_brake_not_pressed_key_close_start_not_pressed
test_park_w_brake_pressed_key_close_start_not_pressed
RED: make it fail
I go back to the terminal where the tests are running
I add a value for the
in_parkparameter to the assertion in test_brake_pressed_key_close_start_not_pressed for if the start button is NOT pressed AND the key is close to the ignition AND the brake is being pressed AND the car gear is in parkkey
brake
start button
gear
output
close
pressed
NOT pressed
in park
False
the test is still green.
ignition( start_is_pressed=False, key_is_close=True, brake_is_pressed=True, in_park=True ) -> FalseI add an assertion for if the start button is NOT pressed AND the key is close to the ignition AND the brake is being pressed AND the car gear is NOT in park
key
brake
start
gear
output
close
pressed
NOT pressed
NOT in park
False
the terminal is my friend, and shows AssertionError
AssertionError: False is not true
GREEN: make it pass
I change assertTrue to assertFalse in test_brake_pressed_key_close_start_not_pressed
43 def test_brake_pressed_key_close_start_not_pressed(self):
44 self.assertFalse(
45 src.car.ignition(
46 start_is_pressed=False,
47 key_is_close=True,
48 brake_is_pressed=True,
49 in_park=True,
50 )
51 )
52 self.assertFalse(
53 src.car.ignition(
54 start_is_pressed=False,
55 key_is_close=True,
56 brake_is_pressed=True,
57 in_park=False,
58 )
59 )
60
61 def test_park_w_brake_not_pressed_key_close_start_not_pressed(self):
the test passes.
ignition(
start_is_pressed=False, key_is_close=True,
brake_is_pressed=True, in_park=True
) -> False
ignition(
start_is_pressed=False, key_is_close=True,
brake_is_pressed=True, in_park=False
) -> False
REFACTOR: make it better
I change the name from test_brake_pressed_key_close_start_not_pressed to test_park_w_brake_pressed_key_close_start_not_pressed
test_park_w_brake_not_pressed_key_not_close_start_pressed
RED: make it fail
I go back to the terminal where the tests are running
I add a value for the
in_parkparameter to the assertion in test_brake_not_pressed_key_not_close_start_pressed for if the start button is pressed AND the key is NOT close to the ignition AND the brake is NOT pressed AND the car gear is in parkkey
brake
start
gear
output
NOT close
NOT pressed
pressed
in park
False
the test is still green.
ignition( start_is_pressed=True, key_is_close=False, brake_is_pressed=False, in_park=True ) -> FalseI add an assertion for if the start button is pressed AND the key is NOT close to the ignition AND the brake is NOT pressed AND the car gear is NOT in park
key
brake
start
gear
output
NOT close
NOT pressed
pressed
NOT in park
False
the terminal is my friend, and shows AssertionError
AssertionError: False is not true
GREEN: make it pass
I change assertTrue to assertFalse in test_brake_not_pressed_key_not_close_start_pressed
34 def test_brake_not_pressed_key_not_close_start_pressed(self):
35 self.assertFalse(
36 src.car.ignition(
37 start_is_pressed=True,
38 key_is_close=False,
39 brake_is_pressed=False,
40 in_park=True,
41 )
42 )
43 self.assertFalse(
44 src.car.ignition(
45 start_is_pressed=True,
46 key_is_close=False,
47 brake_is_pressed=False,
48 in_park=False,
49 )
50 )
51
52 def test_park_w_brake_pressed_key_close_start_not_pressed(self):
the test passes.
ignition(
start_is_pressed=True, key_is_close=False,
brake_is_pressed=False, in_park=False
) -> False
ignition(
start_is_pressed=True, key_is_close=False,
brake_is_pressed=False, in_park=True
) -> False
REFACTOR: make it better
I change the name from test_brake_not_pressed_key_not_close_start_pressed to test_park_w_brake_not_pressed_key_not_close_start_pressed
test_park_w_brake_pressed_key_not_close_start_pressed
RED: make it fail
I go back to the terminal where the tests are running
I add a value for the
in_parkparameter to the assertion in test_brake_pressed_key_not_close_start_pressed for if the start button is pressed AND the key is NOT close to the ignition AND the brake is pressed AND the car gear is in parkkey
brake
start
gear
output
NOT close
pressed
pressed
in park
False
the test is still green.
ignition( start_is_pressed=True, key_is_close=False, brake_is_pressed=True, in_park=True ) -> FalseI add an assertion for if the start button is pressed AND the key is NOT close to the ignition AND the brake is pressed AND the car gear is NOT in park
key
brake
start
gear
output
NOT close
pressed
pressed
NOT in park
False
the terminal is my friend, and shows AssertionError
AssertionError: False is not true
GREEN: make it pass
I change assertTrue to assertFalse in test_brake_pressed_key_not_close_start_pressed
25 def test_brake_pressed_key_not_close_start_pressed(self):
26 self.assertFalse(
27 src.car.ignition(
28 start_is_pressed=True,
29 key_is_close=False,
30 brake_is_pressed=True,
31 in_park=True,
32 )
33 )
34 self.assertFalse(
35 src.car.ignition(
36 start_is_pressed=True,
37 key_is_close=False,
38 brake_is_pressed=True,
39 in_park=False,
40 )
41 )
42
43 def test_park_w_brake_not_pressed_key_not_close_start_pressed(self):
the test passes.
ignition(
start_is_pressed=True, key_is_close=False,
brake_is_pressed=True, in_park=True
) -> False
ignition(
start_is_pressed=True, key_is_close=False,
brake_is_pressed=True, in_park=False
) -> False
REFACTOR: make it better
I change the name from test_brake_pressed_key_not_close_start_pressed to test_park_w_brake_pressed_key_not_close_start_pressed
test_park_w_brake_not_pressed_key_close_start_pressed
RED: make it fail
I go back to the terminal where the tests are running
I add a value for the
in_parkparameter to the assertion in test_brake_not_pressed_key_close_start_pressed for if the start button is pressed AND the key is close to the ignition AND the brake is NOT pressed AND the car gear is in parkkey
brake
start
gear
output
close
NOT pressed
pressed
in park
False
the test is still green.
ignition( start_is_pressed=True, key_is_close=True, brake_is_pressed=False, in_park=True ) -> FalseI add an assertion for if the start button is pressed AND the key is close to the ignition AND the brake is NOT pressed AND the car gear is NOT in park
key
brake
start
gear
output
close
NOT pressed
pressed
NOT in park
False
the terminal is my friend, and shows AssertionError
AssertionError: False is not true
GREEN: make it pass
I change assertTrue to assertFalse in test_brake_not_pressed_key_close_start_pressed
16 def test_brake_not_pressed_key_close_start_pressed(self):
17 self.assertFalse(
18 src.car.ignition(
19 start_is_pressed=True,
20 key_is_close=True,
21 brake_is_pressed=False,
22 in_park=True,
23 )
24 )
25 self.assertFalse(
26 src.car.ignition(
27 start_is_pressed=True,
28 key_is_close=True,
29 brake_is_pressed=False,
30 in_park=False,
31 )
32 )
33
34 def test_park_w_brake_pressed_key_not_close_start_pressed(self):
the test passes.
ignition(
start_is_pressed=True, key_is_close=True,
brake_is_pressed=False, in_park=True
) -> False
ignition(
start_is_pressed=True, key_is_close=True,
brake_is_pressed=False, in_park=False
) -> False
REFACTOR: make it better
I change the name from test_brake_not_pressed_key_close_start_pressed to test_park_w_brake_not_pressed_key_close_start_pressed
test_park_w_brake_pressed_key_close_start_pressed
RED: make it fail
I go back to the terminal where the tests are running
I add a value for the
in_parkparameter to the assertion in test_brake_pressed_key_close_start_pressed for if the start button is pressed AND the key is close to the ignition AND the brake is being pressed AND the car gear is in parkkey
brake
start
gear
output
close
pressed
pressed
in park
True
the test is still green.
ignition( start_is_pressed=True, key_is_close=True, brake_is_pressed=True, in_park=True ) -> TrueI add an assertion for if the start button is pressed AND the key is close to the ignition AND the brake is being pressed AND the car gear is NOT in park
key
brake
start
gear
output
close
pressed
pressed
NOT in park
False
the terminal is my friend, and shows AssertionError
AssertionError: True is not false
GREEN: make it pass
I add an if statement to the ignition function in src/car/__init__.py
1def ignition(
2 start_is_pressed, key_is_close=False,
3 brake_is_pressed=False, in_park=False,
4 ):
5 if in_park == False:
6 return False
7 if start_is_pressed:
8 if key_is_close:
9 return brake_is_pressed
10 return False
the test passes.
ignition(
start_is_pressed=True, key_is_close=True,
brake_is_pressed=True, in_park=True
) -> True
ignition(
start_is_pressed=True, key_is_close=True,
brake_is_pressed=True, in_park=False
) -> False
REFACTOR: make it better
I make the if statement simpler with Logical Negation (NOT)
the test is still green, because
if something == Falseis the same asif not something == Trueis the same asif not something.I want the function to check if the start button is pressed before it checks the other conditions. I add an if statement, then change the return statement
still green.
I use Logical Conjunction (AND) to put the if statements together
green.
I remove the commented lines from the
ignitionfunction1def ignition( 2 start_is_pressed, key_is_close=False, 3 brake_is_pressed=False, in_park=False, 4 ): 5 if ( 6 start_is_pressed 7 and key_is_close 8 and brake_is_pressed 9 ): 10 return in_park 11 return FalseI change the name from test_brake_pressed_key_close_start_pressed to test_park_w_brake_pressed_key_close_start_pressed
When the ignition function is called. It checks if the start button is pressed then if the key is close to the ignition then if the brake is pressed
If the start button is NOT pressed it returns False
src.car.ignition( start_is_pressed=False, key_is_close=False, brake_is_pressed=False, in_park=True ) -> False └── src/car/__init__.py └── def ignition( start_is_pressed, key_is_close=False, brake_is_pressed=False, in_park=False, ): └── if ( ┌───┴── start_is_pressed │ and key_is_close │ and brake_is_pressed │ ): │ return in_park └── return Falsesrc.car.ignition( start_is_pressed=False, key_is_close=False, brake_is_pressed=False, in_park=False ) -> False └── src/car/__init__.py └── def ignition( start_is_pressed, key_is_close=False, brake_is_pressed=False, in_park=False, ): └── if ( ┌───┴── start_is_pressed │ and key_is_close │ and brake_is_pressed │ ): │ return in_park └── return Falsesrc.car.ignition( start_is_pressed=False, key_is_close=False, brake_is_pressed=True, in_park=True ) -> False └── src/car/__init__.py └── def ignition( start_is_pressed, key_is_close=False, brake_is_pressed=False, in_park=False, ): └── if ( ┌───┴── start_is_pressed │ and key_is_close │ and brake_is_pressed │ ): │ return in_park └── return Falsesrc.car.ignition( start_is_pressed=False, key_is_close=False, brake_is_pressed=True, in_park=False ) -> False └── src/car/__init__.py └── def ignition( start_is_pressed, key_is_close=False, brake_is_pressed=False, in_park=False, ): └── if ( ┌───┴── start_is_pressed │ and key_is_close │ and brake_is_pressed │ ): │ return in_park └── return Falsesrc.car.ignition( start_is_pressed=False, key_is_close=True, brake_is_pressed=False, in_park=True ) -> False └── src/car/__init__.py └── def ignition( start_is_pressed, key_is_close=False, brake_is_pressed=False, in_park=False, ): └── if ( ┌───┴── start_is_pressed │ and key_is_close │ and brake_is_pressed │ ): │ return in_park └── return Falsesrc.car.ignition( start_is_pressed=False, key_is_close=True, brake_is_pressed=False, in_park=False ) -> False └── src/car/__init__.py └── def ignition( start_is_pressed, key_is_close=False, brake_is_pressed=False, in_park=False, ): └── if ( ┌───┴── start_is_pressed │ and key_is_close │ and brake_is_pressed │ ): │ return in_park └── return Falsesrc.car.ignition( start_is_pressed=False, key_is_close=True, brake_is_pressed=True, in_park=True ) -> False └── src/car/__init__.py └── def ignition( start_is_pressed, key_is_close=False, brake_is_pressed=False, in_park=False, ): └── if ( ┌───┴── start_is_pressed │ and key_is_close │ and brake_is_pressed │ ): │ return in_park └── return Falsesrc.car.ignition( start_is_pressed=False, key_is_close=True, brake_is_pressed=True, in_park=False ) -> False └── src/car/__init__.py └── def ignition( start_is_pressed, key_is_close=False, brake_is_pressed=False, in_park=False, ): └── if ( ┌───┴── start_is_pressed │ and key_is_close │ and brake_is_pressed │ ): │ return in_park └── return Falseif the start button is pressed AND the key is NOT close to the ignition it leaves the if statements then returns False
src.car.ignition( start_is_pressed=True, key_is_close=False, brake_is_pressed=False, in_park=False ) -> False └── src/car/__init__.py └── def ignition( start_is_pressed, key_is_close=False, brake_is_pressed=False, in_park=False, ): └── if ( ├── start_is_pressed ┌───┴── and key_is_close │ and brake_is_pressed │ ): │ return in_park └── return Falsesrc.car.ignition( start_is_pressed=True, key_is_close=False, brake_is_pressed=False, in_park=True ) -> False └── src/car/__init__.py └── def ignition( start_is_pressed, key_is_close=False, brake_is_pressed=False, in_park=False, ): └── if ( ├── start_is_pressed ┌───┴── and key_is_close │ and brake_is_pressed │ ): │ return in_park └── return Falsesrc.car.ignition( start_is_pressed=True, key_is_close=False, brake_is_pressed=True, in_park=True ) -> False └── src/car/__init__.py └── def ignition( start_is_pressed, key_is_close=False, brake_is_pressed=False, in_park=False, ): └── if ( ├── start_is_pressed ┌───┴── and key_is_close │ and brake_is_pressed │ ): │ return in_park └── return Falsesrc.car.ignition( start_is_pressed=True, key_is_close=False, brake_is_pressed=True, in_park=False ) -> False └── src/car/__init__.py └── def ignition( start_is_pressed, key_is_close=False, brake_is_pressed=False, in_park=False, ): └── if ( ├── start_is_pressed ┌───┴── and key_is_close │ and brake_is_pressed │ ): │ return in_park └── return Falseif the start button is pressed AND the key is close to the ignition it checks if the brake is being pressed
if the start button is pressed AND the key is close to the ignition AND the brake is NOT pressed it leaves the if statement then returns False
src.car.ignition( start_is_pressed=True, key_is_close=True, brake_is_pressed=False, in_park=True ) -> False └── src/car/__init__.py └── def ignition( start_is_pressed, key_is_close=False, brake_is_pressed=False, in_park=False, ): └── if ( ├── start_is_pressed ├── and key_is_close ┌───┴── and brake_is_pressed │ ): │ return in_park └── return Falsesrc.car.ignition( start_is_pressed=True, key_is_close=True, brake_is_pressed=False, in_park=False ) -> False └── src/car/__init__.py └── def ignition( start_is_pressed, key_is_close=False, brake_is_pressed=False, in_park=False, ): └── if ( ├── start_is_pressed ├── and key_is_close ┌───┴── and brake_is_pressed │ ): │ return in_park └── return Falseif the start button is pressed AND the key is close to the ignition AND the brake is pressed it returns the value of
in_parkif the car gear is NOT in park it returns False
src.car.ignition( start_is_pressed=True, key_is_close=True, brake_is_pressed=True, in_park=False ) -> False └── src/car/__init__.py └── def ignition( start_is_pressed, key_is_close=False, brake_is_pressed=False, in_park=False, ): └── if ( ├── start_is_pressed ├── and key_is_close └── and brake_is_pressed ): └── return in_park return False return Falseif the car gear is in park it returns True
src.car.ignition( start_is_pressed=True, key_is_close=True, brake_is_pressed=True, in_park=True ) -> True └── src/car/__init__.py └── def ignition( start_is_pressed, key_is_close=False, brake_is_pressed=False, in_park=False, ): └── if ( ├── start_is_pressed ├── and key_is_close └── and brake_is_pressed ): └── return in_park return True return False
close the project
review
I ran tests for a car with these inputs:
was the start button pressed?
is the key close to the ignition?
is the brake being pressed?
is the car in park?
the inputs gave me this truth table
key |
brake |
start |
gear |
output |
|---|---|---|---|---|
close |
pressed |
pressed |
in park |
True |
close |
pressed |
pressed |
NOT in park |
False |
close |
NOT pressed |
pressed |
in park |
False |
close |
NOT pressed |
pressed |
NOT in park |
False |
key |
brake |
start |
gear |
output |
|---|---|---|---|---|
NOT close |
pressed |
pressed |
in park |
False |
NOT close |
pressed |
pressed |
NOT in park |
False |
NOT close |
NOT pressed |
pressed |
in park |
False |
NOT close |
NOT pressed |
pressed |
NOT in park |
False |
key |
brake |
start |
gear |
output |
|---|---|---|---|---|
close |
pressed |
NOT pressed |
in park |
False |
close |
pressed |
NOT pressed |
NOT in park |
False |
close |
NOT pressed |
NOT pressed |
in park |
False |
close |
NOT pressed |
NOT pressed |
NOT in park |
False |
key |
brake |
start |
gear |
output |
|---|---|---|---|---|
NOT close |
pressed |
NOT pressed |
in park |
False |
NOT close |
pressed |
NOT pressed |
NOT in park |
False |
NOT close |
NOT pressed |
NOT pressed |
in park |
False |
NOT close |
NOT pressed |
NOT pressed |
NOT in park |
False |
the only time I can start this car is if the start button is pressed AND the key is close to the ignition AND the brake is being pressed AND the car gear is in park.
code from the chapter
what is next?
rate pumping python
If this has been a 7 star experience for you, please CLICK HERE to leave a 5 star review of pumping python. It helps other people get into the book too.