-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransitionsystemstate_test.go
390 lines (309 loc) · 8.77 KB
/
transitionsystemstate_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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
package modelchecking
import (
"fmt"
"testing"
)
/*
TestTransitionSystem_Satisfies1
Description:
Tests if the Satisfies() member function correctly identifies when the system
satisfies a given transition system.
*/
func TestTransitionSystem_Satisfies1(t *testing.T) {
// Constants
ts1 := GetSimpleTS1()
ap2 := AtomicProposition{Name: "B"}
// Test
state2 := ts1.S[1]
tf, err := state2.Satisfies(ap2)
if err != nil {
t.Errorf("There was an error while testing satisfies: %v", err.Error())
}
if !tf {
t.Errorf("ap1 (%v) is supposed to be satisfied by ts1.", ap2.Name)
}
}
/*
TestTransitionSystem_Satisfies2
Description:
Tests if the Satisfies() member function correctly identifies when the system
satisfies a given transition system.
*/
func TestTransitionSystem_Satisfies2(t *testing.T) {
// Constants
ts1 := GetSimpleTS1()
ap2 := AtomicProposition{Name: "B"}
// Test
state2 := ts1.S[0]
tf, err := state2.Satisfies(ap2)
if err != nil {
t.Errorf("There was an error while testing satisfies: %v", err.Error())
}
if tf {
t.Errorf("ap1 (%v) is supposed to NOT be satisfied by ts1.", ap2.Name)
}
}
/*
TestTransitionSystemState_Post1
Description:
Tests if the Post() member function correctly identifies when the system
satisfies a given transition system.
*/
func TestTransitionSystemState_Post1(t *testing.T) {
// Constants
ts1 := GetSimpleTS1()
// Test
state2 := ts1.S[1]
nextStates, err := Post(state2, "1")
if err != nil {
t.Errorf("There was an error while testing Post: %v", err.Error())
}
if len(nextStates) != 2 {
t.Errorf("Expected there to be 2 options for next state but received %v options. %v", len(nextStates), nextStates[0])
}
}
/*
TestTransitionSystemState_Post2
Description:
Tests if the Post() member function correctly creates the ancestors
when there is no action given.
*/
func TestTransitionSystemState_Post2(t *testing.T) {
// Constants
ts1 := GetSimpleTS1()
// Test
state1 := ts1.S[0]
state3 := ts1.S[2]
nextStates, err := Post(state1)
if err != nil {
t.Errorf("There was an error while testing Post: %v", err.Error())
}
if len(nextStates) != 2 {
t.Errorf("Expected there to be 2 options for next state but received %v options. %v", len(nextStates), nextStates[0])
}
if state3.In(nextStates) {
t.Errorf("Expected for state3 to not be in the post result, but it was found there!")
}
}
/*
TestTransitionSystemState_Post3
Description:
Tests if the Post() member function correctly creates a post set which
DOES NOT include all states in the system.
*/
func TestTransitionSystemState_Post3(t *testing.T) {
// Constants
ts1 := GetSimpleTS1()
// Test
state2 := ts1.S[1]
nextStates, err := Post(state2)
if err != nil {
t.Errorf("There was an error while testing Post: %v", err.Error())
}
if len(nextStates) != 3 {
t.Errorf("Expected there to be 3 options for next state but received %v options. %v", len(nextStates), nextStates[0])
}
}
/*
TestTransitionSystemState_Pre1
Description:
Tests if the Pre() member function correctly finds the proper state when given a
state and action with only one possible predecessor.
*/
func TestTransitionSystemState_Pre1(t *testing.T) {
// Constants
ts1 := GetSimpleTS1()
// Test
state3 := ts1.S[2]
predecessors, err := Pre(state3, "1")
if err != nil {
t.Errorf("There was an error while testing Post: %v", err.Error())
}
if len(predecessors) != 1 {
t.Errorf("Expected there to be 1 options for next state but received %v options. %v", len(predecessors), predecessors[0])
}
if !predecessors[0].Equals(state3) {
t.Errorf("Expected for the predecessor to be state3 but received the state%v.", predecessors[0])
}
}
/*
TestTransitionSystemState_Pre2
Description:
Tests if the Pre() member function correctly finds the proper state when given a
state only.
*/
func TestTransitionSystemState_Pre2(t *testing.T) {
// Constants
ts1 := GetSimpleTS1()
// Test
state3 := ts1.S[2]
predecessors, err := Pre(state3)
if err != nil {
t.Errorf("There was an error while testing Post: %v", err.Error())
}
if len(predecessors) != 2 {
t.Errorf("Expected there to be 2 options for next state but received %v options. %v", len(predecessors), predecessors[0])
}
if !ts1.S[1].In(predecessors) {
t.Errorf("Expected for state2 to be in predecessors, but it was not!")
}
if ts1.S[0].In(predecessors) {
t.Errorf("Expected for state1 to NOT be in predecessors, but it was!")
}
}
/*
TestTransitionSystemState_Post4
Description:
Tests if the Post() member function correctly finds an empty set when
given the right system and inputs.
*/
func TestTransitionSystemState_Post4(t *testing.T) {
// Constants
ts1 := GetSimpleTS2()
// Test
state4 := ts1.S[3]
ancestors, err := Post(state4)
if err != nil {
t.Errorf("There was an error while testing Post: %v", err.Error())
}
if len(ancestors) != 0 {
t.Errorf("Expected there to be 0 options for next state but received %v options. %v", len(ancestors), ancestors[0])
}
}
/*
TestTransitionSystemState_Pre3
Description:
Tests if the Pre() member function correctly finds an empty set when
given.
*/
func TestTransitionSystemState_Pre3(t *testing.T) {
// Constants
ts1 := GetSimpleTS2()
// Test
state5 := ts1.S[4]
predecessors, err := Pre(state5)
if err != nil {
t.Errorf("There was an error while testing Post: %v", err.Error())
}
if len(predecessors) != 0 {
t.Errorf("Expected there to be 0 options for next state but received %v options. %v", len(predecessors), predecessors[0])
}
}
/*
TestTransitionSystemState_IsTerminal1
Description:
Tests if the IsTerminal() function correctly identifies a terminal state.
*/
func TestTransitionSystemState_IsTerminal1(t *testing.T) {
// Constants
ts1 := GetSimpleTS2()
// Test
state4 := ts1.S[3]
if !state4.IsTerminal() {
t.Errorf("There was an error while verifying that state4 was terminal. Function claims that it is not!")
}
}
/*
TestTransitionSystemState_IsReachable1
Description:
Verifies that a state in the Vending Machine example is truly reachable.
*/
func TestTransitionSystemState_IsReachable1(t *testing.T) {
ts1 := GetBeverageVendingMachineTS()
beerState := ts1.S[2]
// Test to see if this is reachable
if !beerState.IsReachable() {
t.Errorf("The IsReachable() method did not correctly identify that the state was reachable.")
}
}
/*
TestTransitionSystemState_IsReachable2
Description:
Verifies that a state is unreachable.
*/
func TestTransitionSystemState_IsReachable2(t *testing.T) {
ts1 := GetSimpleTS2()
state5 := ts1.S[4]
// Test to see if this is reachable
if state5.IsReachable() {
t.Errorf("The IsReachable() method did not correctly identify that state5 was unreachable.")
}
}
/*
TestTransitionSystemState_Equals1
Description:
Tests to see if two "product" states are equal to one another.
The two sample tuples are equal.
*/
func TestTransitionSystemState_Equals1(t *testing.T) {
ts1 := GetBeverageVendingMachineTS()
s0 := ts1.S[0]
s1 := ts1.S[1]
prodState0 := TransitionSystemState{
Name: fmt.Sprintf("(%v,%v)", s0, s1),
System: &ts1,
}
prodState1 := TransitionSystemState{
Name: fmt.Sprintf("(%v,%v)", s0, s1),
System: &ts1,
}
// Test
if !prodState0.Equals(prodState1) {
t.Errorf("The Equals function incorrectly claims that the two product states are not equal to one another.")
}
}
/*
TestTransitionSystemState_Equals2
Description:
Tests to see if two "product" states are equal to one another.
The two sample tuples are NOT equal.
*/
func TestTransitionSystemState_Equals2(t *testing.T) {
ts1 := GetBeverageVendingMachineTS()
s0 := ts1.S[0]
s1 := ts1.S[1]
prodState0 := TransitionSystemState{
Name: fmt.Sprintf("(%v,%v)", s0, s1),
System: &ts1,
}
prodState1 := TransitionSystemState{
Name: fmt.Sprintf("(%v,%v)", s1, s1),
System: &ts1,
}
// Test
if prodState0.Equals(prodState1) {
t.Errorf("The Equals function incorrectly claims that the two product states are equal to one another.")
}
}
/*
TestTransitionSystemState_String1
Description:
Tests the String() function to make sure that it works properly.
*/
func TestTransitionSystemState_String1(t *testing.T) {
ts1 := GetBeverageVendingMachineTS()
s0 := ts1.S[0]
// Verify that the first state's string is "pay"
// fmt.Println(ts1)
if s0.String() != "pay" {
t.Errorf("The String() evaluation of s0 is \"%v\". Expected \"pay\".", s0)
}
}
/*
TestTransitionSystemState_String2
Description:
Tests the String() function to make sure that it works properly for a state that has
two states in it as a tuple.
*/
func TestTransitionSystemState_String2(t *testing.T) {
ts1 := GetBeverageVendingMachineTS()
s0 := ts1.S[0]
s1 := ts1.S[1]
s2 := TransitionSystemState{
Name: fmt.Sprintf("(%v,%v)", s0, s1),
}
// Verify that the first state's string is "pay"
if s2.String() != "(pay,select)" {
t.Errorf("The String() evaluation of s0 is \"%v\". Expected \"pay x select\".", s2)
}
}