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

Chapter 6 — The types of values

The light now has three operating modes: off, on, and on for cleaning. The state accesa, which can only be true or false, is no longer enough to describe them. The chapter introduces types, which establish which values the states and parameters observed at the boundary can take.

The type

The type of a state or of a parameter is the set of values it can take (chapter 2). The type is written after the colon: accesa : Boolean, durata: Duration. bcdd recognises the following types:

Type Values Example value
Boolean true or false true, false
Integer [a .. b] integers from a to b 3
Real [a .. b] real numbers from a to b 0.5
String strings "second floor"
Duration durations, in seconds (s) or milliseconds (ms) 60 s, 250 ms
Sequence of T ordered sequences of values of type T —
Optional T a value of type T, or no value —

The range in square brackets, [a .. b], is optional for Integer and Real: it limits the values admitted. The decimal separator in numbers is the full stop. The units of a duration are only s and ms, written after the number on the same line, with or without a space (250 ms, 50ms).

The list of values

None of the types in the table is suitable for the three modes of the light. A new type is therefore declared, defined by a list of values that is given a name:

  TYPE       Modo := {spenta, accesa, in_pulizia}

TYPE introduces the declaration of a type; Modo is the name of the type; the curly braces enclose its values, separated by commas. A value of this type can only be one of the three names in the list. The values are names, not strings: they are written without quotation marks.

The state accesa is replaced by the state modo, of type Modo:

  STATE      modo : Modo INITIAL spenta

The initial value is one of the values of the list.

The CSC with types

-- The staircase light, as seen by the person on the stairs and by the caretaker.

CSC UsoLuce VERSION 0.1
  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 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"
END

The new guarantee g7 refers to the mode in_pulizia. Guarantees g1 to g6 remain unchanged: they describe the light on or off in words, without using the state modo, and their meaning does not change.

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

1. ERRORS: 0

2. DEGREE OF THE CONTRACTUAL LINES
  verbal: 8
  formal: 0
  declared extension: 0
  unrecognised: 0
  line 13: GUARANTEE g1 verbal
  line 15: GUARANTEE g2 verbal
  line 17: GUARANTEE g3 verbal
  line 19: GUARANTEE g4 verbal
  line 21: GUARANTEE g5 verbal
  line 23: GUARANTEE g6 verbal
  line 25: GUARANTEE g7 verbal
  line 27: ASSUME a1 verbal

3. UNDECIDED: 0

4. PENDING APPROVAL, NOT CONTRACT: 8
  line 13: GUARANTEE g1
  line 15: GUARANTEE g2
  line 17: GUARANTEE g3
  line 19: GUARANTEE g4
  line 21: GUARANTEE g5
  line 23: GUARANTEE g6
  line 25: GUARANTEE g7
  line 27: ASSUME a1

5. UNRECOGNISED LINES: 0

6. UNDECLARED TYPES: 0

7. CSCs NAMED BUT NOT CHECKED: 0

outcome: no errors

Types described in words and undeclared types

A type can also be described in words, when its values cannot be listed:

  TYPE       Testo := VERBAL "the text shown by the display next to the button"

A type described in words has a name and a description in quotation marks; bcdd records its name but does not interpret its description.

A type used in a state or in a parameter without being declared is an undeclared type. It is not an error: bcdd lists it in section 6 of the report (UNDECLARED TYPES), with the line in which it is used. If the state STATE messaggio : Testo INITIAL "" is added to UsoLuce.csc without the line TYPE Testo, the report shows:

6. UNDECLARED TYPES: 1
  Testo: line 12
…
outcome: no errors

With the line TYPE Testo := VERBAL "…" in the same block, section 6 no longer lists anything.

Summary

Special cases

Value with the name of another element. The values of a list belong to the same set of names as states, events, requests and short names: a name cannot be used twice. If, next to the type Modo, the state STATE accesa : Boolean INITIAL false is also left in place, the name accesa is used twice:

1. ERRORS: 1
  line 12: [E01] name already used at line 6: accesa

Value outside the list. With INITIAL buia the value does not belong to any list of the CSC:

1. ERRORS: 1
  line 11: [E03] name not declared as a value of TYPE: buia

Value of a different type. bcdd checks that the initial value belongs to the type of the state. In the line STATE modo : Modo INITIAL false the value false is not a value of Modo:

1. ERRORS: 1
  line 11: [E25] value not of type Modo: false

The same check applies to the values written in scenarios (chapter 9).

Range limits reversed. bcdd does not check that the first limit of a range is less than or equal to the second.

Unrecognised units. A duration written in minutes, 1 min, is not recognised: it is written 60 s.

Other forms of types. The language also provides the type Record {…}, which groups several fields, each with a name, and the named type TYPE Name := Type, described in chapter 23. The value ABSENT indicates that a value of type Optional is absent: STATE ultimo : Optional Modo INITIAL ABSENT is a state that initially has no value.