What you learn today
- Normal case, edge case, failure
- Table of expectations
- Test after every change
“It works” usually means: it worked once, at 101 kPa, with all sensors. A test case records what the chip must do in a certain situation. With a handful of them you check in a minute after every change whether everything still holds.
Three kinds of test cases
- Normal case: typical values that occur every day – 101.3 kPa in the hall.
- Edge case: exactly on the threshold and just beside it – 90.0 and 89.9 kPa. This is where mix-ups of
sltandslehide. - Failure: sensor gone, value NaN, device missing. The chip has to go into the safe state.
The table of expectations
Write the table before you program. For the pressure light of the hall it looks like this:
| Case | Pressure | Colour | Flashing light | Display |
|---|---|---|---|---|
| normal | 101.3 | green | off | 101.3 |
| green lower limit | 90 | green | off | 90 |
| just below | 89.9 | yellow | off | 89.9 |
| green upper limit | 110 | green | off | 110 |
| just above | 110.1 | yellow | off | 110.1 |
| yellow limit | 80 and 120 | yellow | off | – |
| outside | 79.9 or 120.1 | red | on | – |
| sensor gone | – | red | on | -1 |
Every row is a question to the code. Whether “90 still counts as green” is right is decided only by sge or sgt:
define GRUEN_MIN 90 # kPa, green from here, 90 is included
define GRUEN_MAX 110 # kPa, green up to here, 110 is included
sge low p GRUEN_MIN
sle high p GRUEN_MAX
and green low high
The tests in the academy are exactly such tables: set values, run ticks, expect a result. In the game you do the same with a dial as test value – more on that in the big project.
After every change
A small change to one limit can break a completely different line. That is why all test cases run after every change, not just the one you are working on. In the simulator that takes a minute, in the game after a failure it often takes an evening.
Write the limits as defines and note in the comment whether the limit value itself is included. Then there is no argument between table and code later.
Exercise
Task
Build the pressure light according to the table above. Sensor “Halle”, display “Druck” (shows the pressure, -1 on failure, colour via Color), flashing light “Druckalarm”. Green: 90 to 110 kPa inclusive. Yellow: 80 to 120 kPa inclusive, outside green. Red otherwise and with a missing sensor – then the alarm flashes as well.
Hints
Hint 1
Limits included means sge at the bottom and sle at the top.
Hint 2
Check the yellow band (80–120) first, then lay green over it with select.
Hint 3
Red is everything outside the yellow band: seqz then gives the alarm. NaN ends up there automatically.
Quiz
4 questions. You pass from 60 % – the server does the grading.
Complete the day
- Passed the simulator exercise
- Passed the quiz with at least 60 %
Without an account progress is saved in this browser only.
Report a mistake in this lesson
Please sign in to report. Sign in