Chapter 9 — Examples that fix the intention
Guarantees describe behaviour in general. A concrete case, described instant by instant, makes it possible to check that the writer and the reader understand them in the same way: two presses 100 seconds apart are admitted, a switch-off after 30 seconds is not. The chapter introduces scenarios.
The scenario
A scenario is a short sequence of instants that the contract must admit or reject. It is written with
SCENARIO:
SCENARIO s1 EXPECT ADMITTED
@0 s premuto modo = accesa
@55 s avviso
@60 s modo = spenta
@100 s premuto modo = accesa
SCENARIO s1 opens the scenario, with its short name. EXPECT ADMITTED means that the scenario must be
admitted, that is that it satisfies the contract; EXPECT REJECTED means that it must be rejected, that is that it
violates it.
Each line that follows begins with @ and describes an instant of the scenario: @0 s is the beginning, @55 s is
55 seconds later. The instants are written in chronological order, all with a unit (s or ms) or all
without. In an instant what happens and what is observed are written:
| Element | Meaning | Example |
|---|---|---|
| name of an event | the event happens at that instant | premuto |
state = value |
at that instant the state has that value | modo = accesa |
| lifecycle phase, with the request in parentheses | the request reaches that phase at that instant | requested(Pulizie) |
VERBAL "…" |
an assertion in words about that instant | VERBAL "the caretaker requests three hours of cleaning" |
The sequence of instants written in a scenario is its trace. In the messages of bcdd the instant of a
scenario is called “step” (chapter 21).
Scenario s1 reads as follows: at instant 0 someone presses the button and the light switches on; at instant 55
the light emits the warning; at instant 60 the light is off; at instant 100 a new press switches it on again.
The contract admits it.
The starting state
A scenario begins with the states at their initial value. To start from a different situation the
starting state is given with GIVEN, before EXPECT:
SCENARIO s3 GIVEN modo = in_pulizia EXPECT ADMITTED
@0 s premuto modo = in_pulizia
The scenario starts with cleaning in progress: a press of the button does not change the mode, as established by g7.
States not named in GIVEN start from their initial value.
Where scenarios are written
A scenario is a declaration (chapter 8): it does not have a STATUS of its own and takes that of the
header of the CSC.
Like a DEFINE line, it is not added to an approved CSC. The scenarios of the light are therefore written in a
new version, 0.2, pending approval: the version number and the STATUS of the header change, and a
comment at the top states what changes. The complete procedure for writing a new version is described
in chapter 10.
-- The staircase light, as seen by the person on the stairs and by the caretaker.
-- VERSION 0.2: scenarios s1-s4 added. Pending approval.
CSC UsoLuce VERSION 0.2
STATUS HYPOTHESIS
PURPOSE "The person on the stairs presses a button and has light to go up or down"
TYPE Modo := {spenta, accesa, in_pulizia}
CAPABILITY Pulizie(durata: Duration)
EVENT IN premuto
EVENT OUT avviso
STATE modo : Modo INITIAL spenta
GUARANTEE g1: VERBAL "When someone presses the button, the light switches on"
VERIFY BY JUDGEMENT "a person who presses the button and watches"
GUARANTEE g2: VERBAL "The light switches off by itself after a while"
VERIFY BY JUDGEMENT "a person with a watch"
GUARANTEE g2a DETAILS g2 STATUS RATIFIED BY D-9: VERBAL "The light switches off 60 s after the last press, with a tolerance of 5 s"
VERIFY BY JUDGEMENT "a person who measures with a stopwatch the time between the last press and switch-off"
GUARANTEE g2b DETAILS g2 STATUS RATIFIED BY D-9: VERBAL "A press while the light is on restarts the count of 60 s from the beginning"
VERIFY BY JUDGEMENT "a person who presses the button again while the light is on and measures with a stopwatch the time until switch-off"
GUARANTEE g3: VERBAL "Shortly before switching off, the light gives a warning to the person on the stairs"
VERIFY BY JUDGEMENT "a person on the stairs who waits for the light to switch off"
GUARANTEE g4: VERBAL "A cleaning request is rejected if the requested duration exceeds two hours; otherwise it is accepted"
VERIFY BY JUDGEMENT "the caretaker, who requests cleaning with different durations"
GUARANTEE g5: VERBAL "After an accepted request the light stays on for the whole requested duration; when it expires the request has succeeded"
VERIFY BY JUDGEMENT "the caretaker, with a watch"
GUARANTEE g6: VERBAL "If the light cannot stay on until the duration expires, the request has failed"
VERIFY BY JUDGEMENT "the caretaker, who removes the lamp during cleaning"
GUARANTEE g7: VERBAL "During cleaning the mode is in_pulizia, and a press of the button does not change it"
VERIFY BY JUDGEMENT "the caretaker, who presses the button during cleaning"
ASSUME a1: VERBAL "Whoever presses the button holds it down for at least a tenth of a second"
VERIFY BY JUDGEMENT "a person who observes how the button is pressed"
SCENARIO s1 EXPECT ADMITTED
@0 s premuto modo = accesa
@55 s avviso
@60 s modo = spenta
@100 s premuto modo = accesa
SCENARIO s2 EXPECT REJECTED
@0 s premuto modo = accesa
@30 s modo = spenta
SCENARIO s3 GIVEN modo = in_pulizia EXPECT ADMITTED
@0 s premuto modo = in_pulizia
SCENARIO s4 EXPECT ADMITTED
@0 s requested(Pulizie) VERBAL "the caretaker requests three hours of cleaning"
@0 s rejected(Pulizie)
END
Scenario s2 must be rejected: the light switches off 30 seconds after the press, in conflict with detail g2a.
Scenario s4 uses the lifecycle of chapter 5: the caretaker requests three hours of cleaning and the request is
rejected, as established by g4. The requested duration, which is a parameter of the request, is indicated with
an assertion in words.
What bcdd checks
$ bcdd check --strict UsoLuce.csc
bcdd check --strict UsoLuce.csc
lines: 49 (recognised 42, comments 2, blank 5, unrecognised 0)
blocks: 1
line 4: CSC UsoLuce VERSION 0.2, STATUS HYPOTHESIS
1. ERRORS: 0
…
outcome: no errors
On scenarios bcdd checks the form: that the names used are events, states and requests declared in the CSC,
that the values of the starting state belong to a list of values of the CSC and that the time of the instants does not
decrease. It does not check, on the other hand, that a scenario is really admitted or rejected by the guarantees: with guarantees
written in words this assessment is up to whoever writes the CSC. The verification of outcomes is dealt with in
chapter 24. Section 4 of the report of this version is described in chapter 10.
The limit of a scenario
A scenario forbids nothing that it does not describe. In s1 no warning appears between instant 0 and
instant 55: the scenario does not rule out the emission of warnings in that interval. In the same way, an admitted
scenario does not establish that the installation must always behave like this: it shows one possible behaviour.
Scenarios express the intention of the writer and make it possible to discuss it on concrete cases; the obligations remain in the guarantees.
Summary
- A scenario (
SCENARIO) is a sequence of instants that the contract must admit (EXPECT ADMITTED) or reject (EXPECT REJECTED). - Each instant (
@) indicates a time and what happens or is observed: events, values of states, phases of a request, assertions in words. - The starting state (
GIVEN) indicates the initial values of the scenario, when they are not those declared. - A scenario is a declaration: it takes the
STATUSof the header and is not added to an approved CSC. - A scenario does not forbid what it does not describe;
bcddchecks its form, not its outcome.
Special cases
Undeclared event. If allarme is written at instant 55 instead of avviso:
1. ERRORS: 1
line 38: [E03] name not declared as EVENT: allarme
The same error, with CAPABILITY or STATE in place of EVENT, also appears for a request with a wrong name
in requested(Pulizia) and for an undeclared state in GIVEN accesa = true.
Decreasing time. If the second press is written @50 s, after @60 s:
1. ERRORS: 1
line 40: [E12] the time of the step decreases: @50 s after @60 s
Two instants with the same time, on the other hand, are admitted, as in s4.
Instants with and without unit. If the instant @60 s is written @60, without a unit:
1. ERRORS: 1
line 39: [E12] steps with and without a time unit in the same SCENARIO
Scenario declared rejected but admitted by the guarantees. If in s2 the switch-off happens at @60 s, the
scenario satisfies the contract, although it is declared with EXPECT REJECTED. bcdd check does not detect
this, because it does not evaluate guarantees written in words.

