Lesson map
Lesson 06. Map, example, EX052.
flowchart TD
N["One dependency key"] --> A{"len of names greater than 1?"}
N --> B{"Does the key contain Sam?"}
A --> F["SINGLE POINT OF FAILURE if either is true"]
B --> F
F --> Q{"Does this print contain ok?"}
Q -->|No| K["The else branch is unused"]
Either test is enough. This run takes neither line to ok.
Logical drawing
condition
len(names) > 1 or "Sam" in the key
true
SINGLE POINT OF FAILURE
false, unused here
ok
this print
two failure lines
zero ok lines
Learning outcomes
After this chapter, you should be able to:
- Name the two tests in the flag expression.
- Say which test fires for each printed line.
- Refuse an
okline that this run does not contain.
6.1 One true test selects the failure label. The other test still exists.
The flag line is a conditional expression. The failure label is chosen when len(names) > 1 is true or when "Sam" in d is true. Otherwise the label is the literal ok. The inbox key has two names, so the length test alone selects the failure label. The form key has one name, so the length test is false there, and the substring test is what selects the failure label. Both lines print SINGLE POINT OF FAILURE for different reasons. The word or means the script does not require both tests to be true.
This output contains no ok line. A dependency whose name list had length one, and whose key did not contain Sam, would print ok. No such key is created by these four tuples, so the else branch is real code and an absent result. Adding an ok line to "show the other branch" would invent a dependency.
Lesson table; scroll horizontally to read all columns →
| Key in this print | Test that fires |
|---|---|
| coordinator inbox | Length is 2 |
| form owner Sam | The key contains Sam |
An ok line |
Not produced by this run |
6.2 Worked example
Lesson table; scroll horizontally to read all columns →
| Offered reading | What the expression did | Decision |
|---|---|---|
| Both printed lines use the failure label | Each key made one test true | Keep |
| The inbox line does not need the substring | Length 2 is enough | Keep |
| "Both tests failed, so the label is a score." | or is not a sum |
Refuse |
| "The script printed ok for advisories." | Advisories are not a deps key |
Refuse |
Synthetic case. Two failure lines are the whole flag result.
Errors and limits
Do not insert an ok row in order to illustrate the unused branch.
Apply
- EX052 — Two tests. Why do both dependency lines say
SINGLE POINT OF FAILURE, and does this print containok?Show marking criteria
Rubric: 3 = the inbox line fails the length test; the form line fails the substring test;ordoes not add the tests; this print has nookline;; 2 = each line has its own true test andokis absent;; 1 = one line;; 0 = none.