-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfin.ele
342 lines (279 loc) · 6.5 KB
/
infin.ele
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
-- signatures
sig Company {
var users: set User,
var invoices: set Invoice,
var categories: set Category,
var tags: set Tag
}
var sig Registered in Company {}
sig User {}
sig Tag {}
sig Budget {}
sig Category {
var budget: lone Budget
}
sig Invoice {
var company: one Company,
var category: one Category,
var tags: set Tag
}
-- preds
pred emptyCompany[c : Company] {
one c
no c.tags
no c.categories
no c.categories.budget -- redundant
no c.users
no c.invoices
}
pred emptyInvoice[i : Invoice] {
one i
no i.company
no i.category
no i.tags
}
pred emptyCategory[cat : Category] {
one cat
no cat.budget
}
pred userRegistered[u : User] {
one u
some c : Registered | u in c.users
}
pred companyRegistered[c : Company] {
one c
c in Registered
}
pred invoiceProcessed[i : Invoice] {
one i
some c : Registered | i in c.invoices
}
pred categoryRegistered[cat : Category] {
one cat
some c : Registered | cat in c.categories
}
pred companyCategory[cat : Category, c : Company] {
one cat
cat in c.categories
}
pred tagsRegistered[t : Tag] {
some c : Registered | t in c.tags
}
pred companyTags[t : Tag, c : Company] {
t in c.tags
}
-- actions
pred sameUsers {
all c : Company | c.users' = c.users
}
pred sameInvoices {
all c : Company | c.invoices' = c.invoices
all c : Company | all i : c.invoices | i.company' = i.company and
i.category' = i.category and
i.tags' = i.tags
}
pred sameCategories {
all c : Company | c.categories' = c.categories
}
pred sameTags {
all c : Company | c.tags' = c.tags
}
pred sameBudgets {
all cat : Category | cat.budget' = cat.budget
}
pred sameRegistered {
Registered' = Registered
}
pred stutter {
sameUsers
sameInvoices
sameCategories
sameTags
sameRegistered
sameBudgets
}
pred registerUser[u : User, c : Company] {
emptyCompany[c]
not companyRegistered[c]
not userRegistered[u]
c.users' = c.users + u
Registered' = Registered + c
sameInvoices
sameCategories
sameTags
sameBudgets
all c0 : Company | c != c0 implies c.users' = c.users
}
pred addUserToCompany[u : User, c : Company] {
not userRegistered[u]
companyRegistered[c]
c.users' = c.users + u
sameInvoices
sameCategories
sameTags
sameBudgets
sameRegistered
all c0 : Company | c != c0 implies c0.users' = c0.users
}
pred addInvoiceToCompany[i : Invoice, c : Company, cat : Category, t : Tag] {
companyRegistered[c]
not invoiceProcessed[i]
emptyInvoice[i]
companyCategory[cat, c]
companyTags[t, c]
c.invoices' = c.invoices + i
i.company' = c
i.category' = cat
i.tags' = i.tags
sameUsers
sameCategories
sameTags
sameBudgets
sameRegistered
all c0 : Company | c != c0 implies c0.invoices' = c0.invoices
all i0 : Invoice | i != i0 implies i0.company' = i0.company and
i0.category' = i0.category and
i0.tags' = i0.tags
}
pred changeInvoiceCategory[i : Invoice, cat : Category] {
invoiceProcessed[i]
companyCategory[cat, i.company]
i.company' = i.company
i.category' = cat
i.tags' = i.tags
sameUsers
sameCategories
sameTags
sameBudgets
sameRegistered
all c : Company | c.invoices' = c.invoices
all i0 : Invoice | i != i0 implies i0.company' = i0.company and
i0.category' = i0.category and
i0.tags' = i0.tags
}
pred addCategoryToCompany[cat : Category, c : Company] {
companyRegistered[c]
not categoryRegistered[cat]
emptyCategory[cat]
c.categories' = c.categories + cat
sameInvoices
sameUsers
sameTags
sameBudgets
sameRegistered
all c0 : Company | c != c0 implies c0.categories' = c0.categories
}
pred addTagsToCompany[t : Tag, c : Company] {
companyRegistered[c]
some t
not tagsRegistered[t]
c.tags' = c.tags + t
sameInvoices
sameUsers
sameCategories
sameBudgets
sameRegistered
all c0 : Company | c != c0 implies c0.tags' = c0.tags
}
pred addInvoiceTags[i : Invoice, t : Tag] {
invoiceProcessed[i]
some t
companyTags[t, i.company]
t not in i.tags
i.company' = i.company
i.category' = i.category
i.tags' = i.tags + t
sameUsers
sameCategories
sameTags
sameBudgets
sameRegistered
all c : Company | c.invoices' = c.invoices
all i0 : Invoice | i != i0 implies i0.company' = i0.company and
i0.category' = i0.category and
i0.tags' = i0.tags
}
pred removeInvoiceTags[i : Invoice, t : Tag] {
invoiceProcessed[i]
some t
t in i.tags
i.company' = i.company
i.category' = i.category
i.tags' = i.tags - t
sameUsers
sameCategories
sameTags
sameBudgets
sameRegistered
all c : Company | c.invoices' = c.invoices
all i0 : Invoice | i != i0 implies i0.company' = i0.company and
i0.category' = i0.category and
i0.tags' = i0.tags
}
fact traces {
no Registered
always (
some u : User | some c : Company | some i : Invoice | some t : Tag | some cat : Category |
registerUser[u, c] or addUserToCompany[u, c] or
addInvoiceToCompany[i, c, cat, t] or addTagsToCompany[t, c] or addCategoryToCompany[cat, c] or
changeInvoiceCategory[i, cat] or addInvoiceTags[i, t] or removeInvoiceTags[i, t] or
stutter
)
}
run { some c : Company | emptyCompany[c] } for 3
check UsersBelongToOnlyOneCompany {
always (
all disj c1, c2 : Registered | no c1.users & c2.users
)
}
check CompanyHasAtLeastOneUser {
always (
all c : Registered | some c.users
)
}
check InvoicesBelongToOnlyOneCompany {
always (
all disj c1, c2 : Registered | no c1.invoices & c2.invoices
)
}
check CategoriesBelongToOnlyOneCompany {
always (
all disj c1, c2 : Registered | no c1.categories & c2.categories
)
}
check TagsBelongToOnlyOneCompany {
always (
all disj c1, c2 : Registered | no c1.tags & c2.tags
)
}
check BudgetsBelongToOnlyOneCompany {
always (
all disj c1, c2 : Registered | all cat1 : c1.categories | all cat2 : c2.categories |
no cat1.budget & cat2.budget
)
}
check BudgetsBelongToOnlyOneCategory {
always (
all c : Registered | all disj cat1, cat2 : c.categories | no cat1.budget & cat2.budget
)
}
check InvoiceCompanyIsConsistent {
always (
all c : Registered | all i : c.invoices | one i.company and i.company = c
)
}
check InvoiceCategoryBelongsToCompany {
always (
all c : Registered | all i : c.invoices | one i.category and i.category in c.categories
)
}
check InvoiceTagsBelongToCompany {
always (
all c : Registered | all i : c.invoices | i.tags in c.tags
)
}
check UsersBelongsToOnlyOneCompany {
always (
all u : User | all c : Registered | u in c.users implies always u in c.users
)
}