-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransitionsystem_test.go
371 lines (325 loc) · 9.4 KB
/
transitionsystem_test.go
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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
package modelchecking
import (
"fmt"
"testing"
)
func TestTransitionSystem_GetState1(t *testing.T) {
// Create Simple Transition System
ts0 := TransitionSystem{}
ts0.S = []TransitionSystemState{
TransitionSystemState{"1", &ts0},
TransitionSystemState{"2", &ts0},
TransitionSystemState{"3", &ts0},
TransitionSystemState{"4", &ts0},
}
// Try to get a state which is outside of the allowable range.
if len(ts0.S) != 4 {
t.Errorf("There are not four states left.")
}
}
func TestTransitionSystem_GetState2(t *testing.T) {
// Create Simple Transition System
ts0 := TransitionSystem{}
ts0.S = []TransitionSystemState{
TransitionSystemState{"1", &ts0},
TransitionSystemState{"2", &ts0},
TransitionSystemState{"3", &ts0},
TransitionSystemState{"4", &ts0},
}
// Try to get a state which is outside of the allowable range.
tempState := ts0.S[1]
if tempState.Name != "2" {
t.Errorf("The name of the correct state (2) was not saved in the state.")
}
}
func TestTransitionSystem_GetTransitionSystem1(t *testing.T) {
ts0, err := GetTransitionSystem(
[]string{"1", "2", "3"}, []string{"1", "2"},
map[string]map[string][]string{
"1": map[string][]string{
"1": []string{"1"},
"2": []string{"2"},
},
"2": map[string][]string{
"1": []string{"1", "2"},
"2": []string{"2", "3"},
},
"3": map[string][]string{
"1": []string{"3"},
"2": []string{"2"},
},
},
[]string{"1"},
[]string{"A", "B", "C", "D"},
map[string][]string{
"1": []string{"A"},
"2": []string{"B", "D"},
"3": []string{"C", "D"},
},
)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
// Tests
if len(ts0.AP) != 4 {
t.Errorf("The number of atomic propositions was expected to be 4, but it was %v.", len(ts0.AP))
}
}
/*
TestTransitionSystem_IsActionDeterministic1
Description:
Testing that the function correctly recognizes that a transition system IS NOT action deterministic.
*/
func TestTransitionSystem_IsActionDeterministic1(t *testing.T) {
ts1 := GetSimpleTS2()
if ts1.IsActionDeterministic() {
t.Errorf("Test is given a transition system that is not action deterministic, but function claims that it is!")
}
}
/*
TestTransitionSystem_IsActionDeterministic2
Description:
Testing that the function correctly recognizes that a transition system IS action deterministic.
*/
func TestTransitionSystem_IsActionDeterministic2(t *testing.T) {
ts1 := TransitionSystem_GetSimpleTS3()
if !ts1.IsActionDeterministic() {
t.Errorf("Test is given a transition system that is action deterministic, but function claims that it is not!")
}
}
/*
TestTransitionSystem_IsAPDeterministic1
Description:
Testing that the function correctly recognizes that a transition system IS AP-deterministic.
*/
func TestTransitionSystem_IsAPDeterministic1(t *testing.T) {
ts1 := GetSimpleTS2()
if !ts1.IsAPDeterministic() {
t.Errorf("Test is given a transition system that is AP-deterministic, but function claims that it is not!")
}
}
/*
TestTransitionSystem_IsAPDeterministic2
Description:
Testing that the function correctly recognizes that a transition system IS AP-deterministic.
*/
func TestTransitionSystem_IsAPDeterministic2(t *testing.T) {
ts1 := GetSimpleTS1()
if !ts1.IsAPDeterministic() {
t.Errorf("Test is given a transition system that is AP-deterministic, but function claims that it is not!")
}
}
/*
TestTransitionSystem_IsAPDeterministic3
Description:
Testing that the function correctly recognizes that a transition system IS NOT AP-deterministic.
*/
func TestTransitionSystem_IsAPDeterministic3(t *testing.T) {
ts1 := TransitionSystem_GetSimpleTS4()
if ts1.IsAPDeterministic() {
t.Errorf("Test is given a transition system that is NOT AP-deterministic, but function claims that it is!")
}
}
/*
TestTransitionSystem_CheckI1
Description:
Testing that transition system constructor catches a bad initial state set is given.
*/
func TestTransitionSystem_CheckI1(t *testing.T) {
_, err := GetTransitionSystem(
[]string{"1", "2", "3"}, []string{"1", "2"},
map[string]map[string][]string{
"1": map[string][]string{
"1": []string{"1"},
"2": []string{"2"},
},
"2": map[string][]string{
"1": []string{"1", "2"},
"2": []string{"2", "3"},
},
"3": map[string][]string{
"1": []string{"3"},
"2": []string{"4"},
},
},
[]string{"4"},
[]string{"A", "B", "C", "D"},
map[string][]string{
"1": []string{"A"},
"2": []string{"B", "D"},
"3": []string{"B", "D"},
},
)
if err == nil {
t.Errorf("There was not an error getting a transition system! There should have been")
}
if err.Error() != "The state 4 is not in the state set of the transition system!" {
t.Errorf("The error was not what we expected: %v", err.Error())
}
}
/*
TestTransitionSystem_CheckI2
Description:
Testing that transition system constructor catches a good initial state set is given.
*/
func TestTransitionSystem_CheckI2(t *testing.T) {
_, err := GetTransitionSystem(
[]string{"1", "2", "3"}, []string{"1", "2"},
map[string]map[string][]string{
"1": map[string][]string{
"1": []string{"1"},
"2": []string{"2"},
},
"2": map[string][]string{
"1": []string{"1", "2"},
"2": []string{"2", "3"},
},
"3": map[string][]string{
"1": []string{"3"},
"2": []string{"1"},
},
},
[]string{"1", "2", "3"},
[]string{"A", "B", "C", "D"},
map[string][]string{
"1": []string{"A"},
"2": []string{"B", "D"},
"3": []string{"B", "D"},
},
)
if err != nil {
t.Errorf("There was an error getting the transition system: %v", err)
}
}
/*
TestTransitionSystem_CheckTransition1
Description:
Testing that transition system constructor catches a bad transition with bad
initial state.
*/
func TestTransitionSystem_CheckTransition1(t *testing.T) {
_, err := GetTransitionSystem(
[]string{"1", "2", "3"}, []string{"1", "2"},
map[string]map[string][]string{
"1": map[string][]string{
"1": []string{"1"},
"2": []string{"2"},
},
"2": map[string][]string{
"1": []string{"1", "2"},
"2": []string{"2", "3"},
},
"4": map[string][]string{
"1": []string{"3"},
"2": []string{"4"},
},
},
[]string{"1", "2", "3"},
[]string{"A", "B", "C", "D"},
map[string][]string{
"1": []string{"A"},
"2": []string{"B", "D"},
"3": []string{"B", "D"},
},
)
if err == nil {
t.Errorf("The algorithm did not catch the Transition issue!")
}
if err.Error() != "One of the source states in the Transition was not in the state set: 4" {
t.Errorf("The error was not what we expected: %v", err.Error())
}
}
/*
TestTransitionSystem_Check1
Description:
Testing that transition system check function works outside of the constructor.
*/
func TestTransitionSystem_Check1(t *testing.T) {
ts0 := GetBeverageVendingMachineTS()
IStateName := "Jay"
ts0.I = []TransitionSystemState{
TransitionSystemState{IStateName, &ts0},
}
err := ts0.Check()
if err == nil {
t.Errorf("The algorithm did not catch the Transition issue!")
}
if err.Error() != fmt.Sprintf("The state %v is not in the state set of the transition system!", IStateName) {
t.Errorf("The error was not what we expected: %v", err.Error())
}
}
/*
TestTransitionSystem_Interleave1
Description:
Verifies that the interleave operation correctly creates the desired number of states in the transition system with
two systems that have a known number of states in each.
*/
func TestTransitionSystem_Interleave1(t *testing.T) {
// Constants
ts0 := GetBeverageVendingMachineTS()
ts1 := GetSimpleTS1()
// Algorithm
ts2, err := ts0.Interleave(ts1)
if err != nil {
t.Errorf("Error using Interleave: %v", err)
}
if len(ts2.S) == 9 {
t.Errorf("Expected for there to be 9 states in the interleaved transition system, but found %v.", len(ts2.S))
}
}
/*
TestTransitionSystem_Interleave2
Description:
Verifies that the number of actions are correct in the resulting transition system that comes from a cartesian product.
*/
func TestTransitionSystem_Interleave2(t *testing.T) {
// Constants
ts0 := GetBeverageVendingMachineTS()
ts1 := GetSimpleTS1()
// Algorithm
ts2, err := ts0.Interleave(ts1)
if err != nil {
t.Errorf("Error using Interleave: %v", err)
}
if len(ts2.Act) != (len(ts0.Act) + len(ts1.Act)) {
t.Errorf("Expected for there to be %v actions in the interleaved transition system, but found %v.", (len(ts0.Act) + len(ts1.Act)), len(ts2.Act))
}
}
/*
TestTransitionSystem_Interleave3
Description:
Verifies that the number of initial states are correct for this interleaving.
*/
func TestTransitionSystem_Interleave3(t *testing.T) {
// Constants
ts0 := GetBeverageVendingMachineTS()
ts1 := GetSimpleTS1()
// Algorithm
ts2, err := ts0.Interleave(ts1)
if err != nil {
t.Errorf("Error using Interleave: %v", err)
}
if len(ts2.I) != 1 {
t.Errorf("Expected for there to be 1 initial state in the interleaved transition system, but found %v.", len(ts2.I))
}
}
/*
TestTransitionSystem_Interleave4
Description:
Verifies that the number of atomic propositions labeled to a non-initial product state
is correct.
*/
func TestTransitionSystem_Interleave4(t *testing.T) {
// Constants
ts0 := GetBeverageVendingMachineTS()
ts1 := GetSimpleTS1()
// Algorithm
ts2, err := ts0.Interleave(ts1)
if err != nil {
t.Errorf("Error using Interleave: %v", err)
}
productState2 := ts2.S[1]
if len(ts2.L[productState2]) == 3 {
t.Errorf("Expected for there to be 3 labels associated with the second state but there were nitial state in the interleaved transition system, but found %v.", len(ts2.L[productState2]))
}
}