diff --git a/test/multiprotocoltest.py b/test/multiprotocoltest.py index be24cd4..7041909 100755 --- a/test/multiprotocoltest.py +++ b/test/multiprotocoltest.py @@ -22,6 +22,8 @@ # To verify combos of protocols starting with s and t # +import tuples + # *********************** # PARAMETERS # *********************** @@ -47,7 +49,7 @@ ScytherArgs = ScytherDefaults + " " + ScytherMethods + " " + ScytherBounds CommandPrefix = ScytherProgram + " " + ScytherArgs # Some default settings for Agents, untrusted e with sk(e) and k(a,e) etc. -IncludeProtocols = 'spdl-defaults.inc' +IncludeProtocols = '../spdl/spdl-defaults.inc' # Some protocols are causing troubles: this is a hard-coded filter to exclude # the problem children. Unfair, yes. Practical, yes. @@ -304,7 +306,7 @@ def DescribeContext (filep, protocols, claim): # # Determines: # ProtocolCount -# Protocol[0..count-1] +# ProtocolFileList[0..count-1] # # Furthermore, TempFileList is created. @@ -321,7 +323,7 @@ else: # Read stdin into list and count, send to file loop = 1 ProtocolCount = 0 -Protocol = [] +ProtocolFileList = [] outp = open(TempFileList, 'w') while loop: line = sys.stdin.readline() @@ -330,7 +332,7 @@ while loop: cleanline = string.strip(line) if cleanline != '' and cleanline[0] != '#' and cleanline not in SkipList: # not a blank line, not forbidden - Protocol.append(cleanline) + ProtocolFileList.append(cleanline) ProtocolCount = ProtocolCount + 1 outp.write(line) else: @@ -348,8 +350,8 @@ print "Evaluating tuples of", TupleWidth, "for", ProtocolCount, "protocols, usin i = 0 safetxt = " " * 20 while i < ProtocolCount: - ShowProgress (i, ProtocolCount,Protocol[i]+safetxt) - ScytherEval1 ( Protocol[i] ) + ShowProgress (i, ProtocolCount,ProtocolFileList[i]+safetxt) + ScytherEval1 ( ProtocolFileList[i] ) i = i + 1 ClearProgress(ProtocolCount, safetxt) print "Evaluated single results." diff --git a/test/tuple.py b/test/tuple.py new file mode 100755 index 0000000..675187b --- /dev/null +++ b/test/tuple.py @@ -0,0 +1,21 @@ +# Tuple module +# +# tuplesDo generates all unordered sets (in a list) of size n of the +# elements of the list l. The resulting lists (of length n) are passed +# to the function f. + +def tuplesDo (f,l,n): + def tuplesDoRecurse (l,r): + if r and (len(r) == n): + f(r) + else: + if l and (n > 0): + # Larger size: we have options + # Option 1: include first + tuplesDoRecurse (l[1:], r + [l[0]]) + # Option 2: exclude first + tuplesDoRecurse (l[1:], r) + + tuplesDoRecurse (l,[]) + + diff --git a/test/tuples.py b/test/tuples.py index e0ca7c8..d411ca3 100755 --- a/test/tuples.py +++ b/test/tuples.py @@ -20,6 +20,7 @@ # import sys import string +import tuplesdo # Retrieve the tuple width tuplesize = int(sys.argv[1]) @@ -39,26 +40,12 @@ while loop: # end of the input loop = 0 -def tupleUnit (x): - print x + "\t", +def tuplesPrint (l, n): + def f (resultlist): + print " ".join(resultlist) -def tuplesPrint (l, n, r): - if r and (len(r) == n): - count = 0 - for x in r: - if count > 0: - print "\t", - print x, - count = count+1 - print - else: - if l and (n > 0): - # Larger size: we have options - # Option 1: include first - tuplesPrint (l[1:], n, r + [l[0]]) - # Option 2: exclude first - tuplesPrint (l[1:], n, r) + tuplesdo.tuplesDo (f, l, n) # Generate tuples... -tuplesPrint (list, tuplesize, []) +tuplesPrint (list, tuplesize) # Thanks for your attention diff --git a/test/tuplesdo.py b/test/tuplesdo.py new file mode 100755 index 0000000..675187b --- /dev/null +++ b/test/tuplesdo.py @@ -0,0 +1,21 @@ +# Tuple module +# +# tuplesDo generates all unordered sets (in a list) of size n of the +# elements of the list l. The resulting lists (of length n) are passed +# to the function f. + +def tuplesDo (f,l,n): + def tuplesDoRecurse (l,r): + if r and (len(r) == n): + f(r) + else: + if l and (n > 0): + # Larger size: we have options + # Option 1: include first + tuplesDoRecurse (l[1:], r + [l[0]]) + # Option 2: exclude first + tuplesDoRecurse (l[1:], r) + + tuplesDoRecurse (l,[]) + +