@@ -42,20 +42,29 @@ Testing Constraints Via Membership
42
42
Testing Non-Contiguous Membership
43
43
-----------------------------------
44
44
45
- * Uses vertical bar "choice" syntax
45
+ * We use :ada: ` in ` to indicate membership in a range of values
46
46
47
- .. code :: Ada
47
+ .. code :: Ada
48
+
49
+ if Color in Red .. Green then
50
+ if Index in List'Range then
51
+
52
+ * But what if the values are not contiguous?
53
+
54
+ * We could use a Boolean conjunction
55
+
56
+ .. code :: Ada
57
+
58
+ if Index = 1 or Index = 3 or Index = 5 then
59
+
60
+ * Or we could simplify it by specifying a collection (or set)
61
+
62
+ .. code :: Ada
63
+
64
+ if Index in 1 | 3 | 5 then
48
65
49
- declare
50
- M : Month_Number := Month (Clock);
51
- begin
52
- if M in 9 | 4 | 6 | 11 then
53
- Put_Line ("31 days in this month");
54
- elsif M = 2 then
55
- Put_Line ("It's February, who knows?");
56
- else
57
- Put_Line ("30 days in this month");
58
- end if;
66
+ * **| ** is used to separate members
67
+ * So :ada: `1 | 3 | 5 ` is the set for which we are verifying membership
59
68
60
69
..
61
70
language_version 2012
@@ -81,7 +90,7 @@ Which condition(s) is (are) legal?
81
90
82
91
Explanations
83
92
84
- A. To use :ada: `or `, both sides of the comparison must be duplicated (e.g. :ada: `Today = Mon or Today = Wed `)
93
+ A. :ada: ` Wed ` and :ada: `Fri ` are not Boolean expressions - need to compare each of them to :ada: `Today `
85
94
B. Legal - should always return :ada: `True `
86
95
C. Legal - returns :ada: `True ` if :ada: `Today ` is :ada: `Sat ` or :ada: `Sun `
87
96
D. Legal - returns :ada: `True ` if :ada: `Today ` is :ada: `Tue ` or :ada: `Thu `
0 commit comments