Logo BCDDLogo CSC
BCDDBehavioural Contract-Driven Design
version 1.0-beta
ITEN

Chapter 8 — Making a guarantee precise

Guarantee g2, “the light switches off by itself after a while”, is approved but vague: it does not state how long the light must stay on, so whoever implements the installation does not know it and acceptance testing has no value to measure. The chapter describes how to make a guarantee precise without deleting it and how to submit the CSC to a language model, which asks questions about the points that are still vague. It then describes how to give a name to values and how to mark the numbers not yet decided.

The detail

A detail is a contractual line that makes precise a guarantee or an assumption already written. It is written with DETAILS followed by the short name of the line it makes precise:

  GUARANTEE g2a DETAILS g2: 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"

The line reads: guarantee g2a, detail of g2. The detail respects three rules:

  1. it adds, it does not replace: g2 remains in force, and g2a is added to it;
  2. it does not contradict: there must exist a behaviour of the installation that satisfies both lines;
  3. it is pending approval when created: a detail without a STATUS of its own is pending approval even if the guarantee it makes precise is approved. A detail does not follow the STATUS of the header.

The third rule makes it possible to add details under the guarantees of an approved CSC without their becoming approved in the absence of a decision. Assumptions can be made precise in the same way.

A detail can in turn have details. The level of a line indicates how many steps of DETAILS separate it from a line without DETAILS: g2 has level 0, g2a level 1, a detail of g2a level 2.

The language model's questions

The bcdd refine command submits the CSC to a language model, which asks questions about the vague points and, on the basis of the answers, proposes new lines. A run of bcdd refine proceeds as follows:

  1. the model asks at most five questions, each with some proposed answers. The reply is the number of a proposed answer or an answer of one's own; pressing Enter without typing anything skips the question;
  2. on the basis of the answers, the model proposes new details or the replacement of lines pending approval;
  3. each proposal is accepted (y) or discarded (n);
  4. at the end the command asks for confirmation before writing the accepted proposals into the file; without the final confirmation the file does not change.

For the CSC of the light the run looks like this (the initial lines, which report the check of the file and the call to the model, are omitted):

$ bcdd refine UsoLuce.csc
…
QUESTION 1 of 2
  How long after the last press must the light switch off, and with what tolerance?
  1) 30 seconds, with a tolerance of 5 seconds
  2) 60 seconds, with a tolerance of 5 seconds
  3) 3 minutes, with a tolerance of 10 seconds
answer (1 to 3, or write your own; press Enter alone to skip): 2
  choice 2: 60 seconds, with a tolerance of 5 seconds

QUESTION 2 of 2
  What effect does a press while the light is on have on the on-time?
  1) it restarts the count from the beginning
  2) it changes nothing
answer (1 to 2, or write your own; press Enter alone to skip): 1
  choice 1: it restarts the count from the beginning
…
PROPOSAL 1 of 2, details g2 (line 16)
  GUARANTEE g2a DETAILS g2 STATUS HYPOTHESIS: 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"
accept? y = yes, n = no, q = quit (discards the rest): y

PROPOSAL 2 of 2, details g2 (line 16)
  GUARANTEE g2b DETAILS g2 STATUS HYPOTHESIS: 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"
accept? y = yes, n = no, q = quit (discards the rest): y

summary: accepted 2, discarded by you 0, discarded by the check 0
write 2 proposals (4 lines) in UsoLuce.csc and 2 answers in UsoLuce.csc.dialogo? y = yes, n = no: y
written UsoLuce.csc: 2 proposals (4 lines)
written UsoLuce.csc.dialogo: 2 answers

The questions and proposals depend on the language model and vary from one run to another; those shown are an example.

The questions and the answers given are kept in the file UsoLuce.csc.dialogo, next to the CSC; the output reports the number of answers written. At the next run bcdd refine passes the answers already given to the model, so that it does not ask the same questions again.

The proposals enter the file with an explicit STATUS HYPOTHESIS, immediately below the guarantee they make precise. Lines 14-21 of the file become:

  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 HYPOTHESIS: 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 HYPOTHESIS: 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"

bcdd refine has four limits:

The report

$ bcdd check --strict UsoLuce.csc
bcdd check --strict UsoLuce.csc
lines: 34 (recognised 29, comments 1, blank 4, unrecognised 0)
blocks: 1
  line 3: CSC UsoLuce VERSION 0.1, STATUS RATIFIED BY D-7

1. ERRORS: 0

2. DEGREE OF THE CONTRACTUAL LINES
  verbal: 10
  formal: 0
  declared extension: 0
  unrecognised: 0
  line 14: GUARANTEE g1 verbal
  line 16: GUARANTEE g2 verbal
  line 18: GUARANTEE g2a verbal
  line 20: GUARANTEE g2b verbal
  line 22: GUARANTEE g3 verbal
  line 24: GUARANTEE g4 verbal
  line 26: GUARANTEE g5 verbal
  line 28: GUARANTEE g6 verbal
  line 30: GUARANTEE g7 verbal
  line 32: ASSUME a1 verbal

3. UNDECIDED: 0

4. PENDING APPROVAL, NOT CONTRACT: 2
  line 18: GUARANTEE g2a
  line 20: GUARANTEE g2b

5. UNRECOGNISED LINES: 0

6. UNDECLARED TYPES: 0

7. CSCs NAMED BUT NOT CHECKED: 0

14. TO BE JUDGED: 2
  line 18: GUARANTEE g2a DETAILS g2: consistency between the line and the line that details it, one of the two in words
  line 20: GUARANTEE g2b DETAILS g2: consistency between the line and the line that details it, one of the two in words

outcome: no errors

The CSC remains approved with decision D-7; only the two new details appear in section 4.

Section 14, TO BE JUDGED, lists what can be established only by judgement. A detail in words must add precision to the line it makes precise, without contradicting it; but bcdd does not interpret the meaning of the text. Therefore, when the detail or the line it makes precise is written in words, the report states that the consistency between the two remains to be judged. An entry in section 14 is not an error and does not change the exit code. The section appears only when it has at least one entry.

The building manager approves the two details with a new decision:

$ bcdd ratify UsoLuce.csc --all D-9
approved with D-9 in CSC UsoLuce: 2 lines
  line 18: GUARANTEE g2a
  line 20: GUARANTEE g2b
contract: 10

With --all the command modifies only the lines still pending approval: the STATUS of g2a and of g2b becomes STATUS RATIFIED BY D-9, while the header, already approved, does not change.

Named constants

A value that recurs in several lines can be declared once only, with a name, by means of DEFINE:

  DEFINE     DURATA_LUCE := 60 s
  DEFINE     TOLLERANZA := 5 s

A named constant is written with DEFINE, the name, the sign := and the value: a number, with or without a unit, a string, true, false or one of the values of a list. The units admitted are the same as for durations, s and ms. The value can also be an expression computed from other values (chapter 23).

bcdd does not link the name to the text of the guarantees: in VERBAL "the light switches off after DURATA_LUCE" the name is plain text, and bcdd does not check that a corresponding DEFINE line exists.

The DEFINE line is a declaration, like the TYPE, CAPABILITY, EVENT and STATE lines: it declares an element of the CSC. Unlike a contractual line, a declaration does not have a STATUS of its own and always takes that of the header. If it were added to an approved CSC, it would be approved without a decision: for this reason it is not added to an approved CSC, but written in a CSC still pending approval or in a new version (chapter 10). In the CSC of the light, approved with D-7, the numbers remain written in the text of the details.

Numbers not yet decided

A number that has not yet been decided is declared with the value UNDECIDED, “not decided”:

  DEFINE     ANTICIPO_AVVISO := UNDECIDED

An undecided number indicates that a decision is missing. bcdd lists it in section 3 of the report as long as it remains so. In a working copy of the CSC of the light still pending approval, with the three DEFINE lines of this chapter at lines 7-9:

1. ERRORS: 0
…
3. UNDECIDED: 1
  line 9: ANTICIPO_AVVISO
…
outcome: no errors

An undecided number is not an error. When the decision is taken, the value is written by hand in place of UNDECIDED; no command does it.

Summary

Special cases

Detail of a non-existent guarantee. If g2b has DETAILS g9 and g9 does not exist:

1. ERRORS: 1
  line 20: [E02] DETAILS names an id that is neither a GUARANTEE nor an ASSUME of this CSC: g9

Circular details. If g2a is a detail of g2b and g2b is a detail of g2a, the two details form a cycle and neither of them makes a guarantee precise; bcdd reports error E05:

1. ERRORS: 1
  line 18: [E05] circular DETAILS: g2a -> g2b -> g2a

Unit in minutes. The line DEFINE DURATA_LUCE := 1 min is not recognised:

5. UNRECOGNISED LINES: 1
  line 7: DEFINE     DURATA_LUCE := 1 min

No questions. When the model detects no vague points, bcdd refine states it in one line and the file does not change:

the CSC UsoLuce is precise enough: no questions and no proposals, UsoLuce.csc does not change

Details beyond level 2. bcdd check accepts details at any level; the level 2 limit applies only to the proposals of bcdd refine.