Use lists instead of files to store the checklist
diff --git a/tests/randmath.py b/tests/randmath.py
index abb1b31..3519012 100755
--- a/tests/randmath.py
+++ b/tests/randmath.py
@@ -19,17 +19,6 @@
import sys
import subprocess
-def silentremove(filename):
- try:
- os.remove(filename)
- except OSError as e:
- if e.errno != errno.ENOENT:
- raise
-
-def finish():
- silentremove(math)
- silentremove(opfile)
-
def gen(limit=4):
return random.randint(0, 2 ** (8 * limit))
@@ -77,11 +66,8 @@
def add(test, op):
- with open(math, "a") as f:
- f.write(test + "\n")
-
- with open(opfile, "a") as f:
- f.write(str(op) + "\n")
+ tests.append(test)
+ gen_ops.append(op)
def compare(exe, options, p, test, halt, expected, op, do_add=True):
@@ -199,8 +185,6 @@
testdir = os.path.dirname(script)
exedir = testdir + "/.."
-math = exedir + "/.math.txt"
-opfile = exedir + "/.ops.txt"
ops = [ '+', '-', '*', '/', '%', '^', '|' ]
files = [ "add", "subtract", "multiply", "divide", "modulus", "power", "modexp",
@@ -221,7 +205,8 @@
exponent = 8
bessel = 13
-finish()
+gen_ops = []
+tests = []
try:
i = 0
@@ -238,13 +223,7 @@
print("\nGoing through the checklist...\n")
-with open(math, "r") as f:
- tests = f.readlines()
-
-with open(opfile, "r") as f:
- ops = f.readlines()
-
-if len(tests) != len(ops):
+if len(tests) != len(gen_ops):
print("Corrupted checklist!")
print("Exiting...")
sys.exit(1)
@@ -253,7 +232,7 @@
print("\n{}".format(tests[i]))
- op = int(ops[i])
+ op = int(gen_ops[i])
if op != modexp:
exe = "bc"
@@ -296,5 +275,4 @@
else:
print("No")
-
-finish()
+print("Done!")