-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsim_tester.py
56 lines (45 loc) · 1.28 KB
/
sim_tester.py
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
#! /bin/python
# @param1 the first file with result of a simulation over an automaton
# @param2 the second file with result of a simulation over an automaton
import sys
def getSim(fileToLoad):
mappingStates=0
simulationResult=1
state=mappingStates
dic1 = {}
sim1 = {}
line=0
for i in fileToLoad:
if i == "\n": # end of mapping part of file
if state == mappingStates:
dic1[int(max(dic1.keys()))+1]="x" # add start state
state = state+1 # change states
continue
if state == mappingStates:
ml = i.split()
dic1[ml[2]] = ml[0]
if state == simulationResult:
inds = [i for i,x in enumerate(i) if x=="1"]
for ind in inds:
try:
sim1[dic1[str(line)]].extend([dic1[str(ind)]])
except KeyError:
sim1[dic1[str(line)]]=[dic1[str(ind)]]
sim1[dic1[str(line)]].sort()
line=line+1
return sim1
if len (sys.argv) < 3:
sys.stderr.write("Not enough parameters")
exit(1)
firstFile = open(sys.argv[1],'r')
try:
sim1 = getSim(firstFile)
firstFile.close()
secondFile = open(sys.argv[2],'r')
sim2 = getSim(secondFile)
if sim1 == sim2:
print "Simulations "+sys.argv[1]+" "+sys.argv[2]+" are identical"
else:
print "Simulations "+sys.argv[1]+" "+sys.argv[2]+" are not identical"
except KeyError:
sys.stderr.write("Bad format of a simulation output\n")