-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformal_specification.als
182 lines (137 loc) · 5.47 KB
/
formal_specification.als
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
module falaCidadao
------------------------------------------------------------------------------------------
--------------- Fala, Cidadão! ---------------
------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------
---------------> Signatures <---------------
------------------------------------------------------------------------------------------
abstract sig User {
problems: set Problem
}
sig Citizen, Administrator extends User { }
sig Problem {
comments: set Comment,
state: State
}
sig Comment {
owner: one User
}
sig State {
actualStatus: Status,
nextStatus: Status
}
abstract sig Status { }
sig InAnalysis, OnHold, InProgress, Concluded extends Status { }
------------------------------------------------------------------------------------------
---------------> Functions <---------------
------------------------------------------------------------------------------------------
fun getProblems [u: User]: set Problem {
Problem & u.problems
}
fun getActualStatus [s: State]: Status {
Status & s.actualStatus
}
fun getNextStatus [s: State]: Status {
Status & s.nextStatus
}
------------------------------------------------------------------------------------------
---------------> Predicates <---------------
------------------------------------------------------------------------------------------
pred actualStatusIsInAnalysis [s: State] {
getActualStatus[s] in InAnalysis
}
pred nextStatusIsOnHold [s: State] {
getNextStatus[s] in OnHold
}
pred actualStatusIsOnHold [s: State] {
getActualStatus[s] in OnHold
}
pred nextStatusIsInProgress [s: State] {
getNextStatus[s] in InProgress
}
pred actualStatusIsInProgress [s: State] {
getActualStatus[s] in InProgress
}
pred nextStatusIsConcluded [s: State] {
getNextStatus[s] in Concluded
}
pred actualStatusIsConcluded [s: State] {
getActualStatus[s] in Concluded
}
pred show [] {}
------------------------------------------------------------------------------------------
---------------> Facts <---------------
------------------------------------------------------------------------------------------
fact onlyCitizensCanCreateProblems {
all a: Administrator | #getProblems[a] = 0
}
fact eachProblemHasOnlyOneCreator {
all p: Problem | one p.~problems
}
fact commentsOnlyExistInOneProblem {
all c: Comment | one c.~comments
}
fact stateOnlyExistInOneProblem {
all s: State | one s.~state
}
fact eachCommentHasOnlyOneOwner {
all u: User | one u.~owner
}
fact actualStatusIsInAnalysisNextIsOnHold {
all s: State | actualStatusIsInAnalysis[s] implies nextStatusIsOnHold[s]
}
fact actualStatusIsOnHoldNextIsInProgress {
all s: State | actualStatusIsOnHold[s] implies nextStatusIsInProgress[s]
}
fact actualStatusIsInProgressNextIsConcluded {
all s: State | actualStatusIsInProgress[s] implies nextStatusIsConcluded[s]
}
fact actualStatusIsConcludedNextIsConcluded {
all s: State | actualStatusIsConcluded[s] implies nextStatusIsConcluded[s]
}
------------------------------------------------------------------------------------------
---------------> Asserts <---------------
------------------------------------------------------------------------------------------
assert testOnlyCitizensCanCreateProblems {
all a: Administrator | #a.problems = 0
}
assert testEachProblemHasOnlyOneCreator {
all p: Problem | #(p.~problems) = 1
}
assert testCommentsOnlyExistInOneProblem {
all c: Comment | #(c.~comments) = 1
}
assert testStateOnlyExistInOneProblem {
all s: State | #(s.~state) = 1
}
assert testEachCommentHasOnlyOneOwner {
all u: User | #(u.~owner) = 1
}
assert testActualStatusIsInAnalysisNextIsOnHold {
all s: State | (getActualStatus[s] in InAnalysis) <=> (getNextStatus[s] in OnHold)
}
assert testActualStatusIsOnHoldNextIsInProgress {
all s: State | (getActualStatus[s] in OnHold) <=> (getNextStatus[s] in InProgress)
}
assert testActualStatusIsInProgressNextIsConcluded {
all s: State | (getActualStatus[s] in InProgress) => (getNextStatus[s] in Concluded)
}
assert testActualStatusIsConcludedNextIsConcluded {
all s: State | (getActualStatus[s] in Concluded) => (getNextStatus[s] in Concluded)
}
------------------------------------------------------------------------------------------
---------------> Checks <---------------
------------------------------------------------------------------------------------------
check testOnlyCitizensCanCreateProblems for 50
check testEachProblemHasOnlyOneCreator for 50
check testCommentsOnlyExistInOneProblem for 50
check testStateOnlyExistInOneProblem for 50
check testEachCommentHasOnlyOneOwner for 50
check testActualStatusIsInAnalysisNextIsOnHold for 50
check testActualStatusIsOnHoldNextIsInProgress for 50
check testActualStatusIsInProgressNextIsConcluded for 50
check testActualStatusIsConcludedNextIsConcluded for 50
------------------------------------------------------------------------------------------
---------------> Show <---------------
------------------------------------------------------------------------------------------
run show for 20