reorg test code towards parameterisation
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 8 Jul 2019 10:58:36 +0000 (11:58 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Mon, 8 Jul 2019 10:58:36 +0000 (11:58 +0100)
src/ieee754/fpadd/test/test_fpadd_pipe_32.py
src/ieee754/fpcommon/test/fpmux.py

index c1d852fc3c14f07b6a44b2aee83f7fb18718c97c..7bcec6128e25e8fe7b59c977cbdbceab94e8acbc 100644 (file)
@@ -14,59 +14,52 @@ from sfpy import Float32
 from operator import add
 
 
-def test_pipe_fp32_rand1():
-    dut = FPADDMuxInOut(32, 4)
-    pipe_cornercases_repeat(dut, "add_rand1", unit_test_single, Float32,
-                                 32, get_rand1, corner_cases, add, 10)
+class PipeFPCase:
+    def __init__(self, dut, name, mod, fmod, width, cc, fpfn, count):
+        self.dut = dut
+        self.name = name
+        self.mod = mod
+        self.fmod = fmod
+        self.width = width
+        self.cc = cc
+        self.fpfn = fpfn
+        self.count = count
 
-def test_pipe_fp32_n127():
-    dut = FPADDMuxInOut(32, 4)
-    pipe_cornercases_repeat(dut, "add_n127", unit_test_single, Float32,
-                                 32, get_n127, corner_cases, add, 10)
+    def run(self, name, fn):
+        name = "%s_%s" % (self.name, name)
+        pipe_cornercases_repeat(self.dut, name, self.mod, self.fmod,
+                                self.width, fn, self.cc, self.fpfn,
+                                self.count)
 
-def test_pipe_fp32_nan_noncan():
-    dut = FPADDMuxInOut(32, 4)
-    pipe_cornercases_repeat(dut, "add_noncan", unit_test_single, Float32,
-                                 32, get_nan_noncan, corner_cases, add, 10)
+    def run_cornercases(self):
+        vals = repeat(self.dut.num_rows, get_corner_cases(self.mod))
+        tname = "test_fp%s_pipe_fp%d_cornercases" % (self.name, self.width)
+        runfp(self.dut, self.width, tname, self.fmod, self.fpfn, vals=vals)
 
-def test_pipe_fp32_nearly_zero():
-    dut = FPADDMuxInOut(32, 4)
-    pipe_cornercases_repeat(dut, "add_nearlyzero", unit_test_single, Float32,
-                                 32, get_nearly_zero, corner_cases, add, 10)
+    def run_regressions(self, regressions_fn):
+        vals = repeat(self.dut.num_rows, regressions_fn())
+        tname = "test_fp%s_pipe_fp%d_regressions" % (self.name, self.width)
+        runfp(self.dut, self.width, tname, self.fmod, self.fpfn, vals=vals)
 
-def test_pipe_fp32_nearly_inf():
-    dut = FPADDMuxInOut(32, 4)
-    pipe_cornercases_repeat(dut, "add_nearlyinf", unit_test_single, Float32,
-                                 32, get_nearly_inf, corner_cases, add, 10)
+    def run_random(self):
+        tname = "test_fp%s_pipe_fp%d_rand" % (self.name, self.width)
+        runfp(self.dut, self.width, tname, self.fmod, self.fpfn)
 
-def test_pipe_fp32_corner_rand():
-    dut = FPADDMuxInOut(32, 4)
-    pipe_cornercases_repeat(dut, "add_corner_rand", unit_test_single, Float32,
-                                 32, get_corner_rand, corner_cases, add, 10)
 
-def test_pipe_fp32_cornercases():
+def test_pipe_fp32():
     dut = FPADDMuxInOut(32, 4)
-    vals = repeat(dut.num_rows, get_corner_cases(unit_test_single))
-    runfp(dut, 32, "test_fpadd_pipe_fp32_cornercases", Float32, add, vals=vals)
-
-def test_pipe_fp32_regressions():
-    dut = FPADDMuxInOut(32, 4)
-    vals = repeat(dut.num_rows, regressions())
-    runfp(dut, 32, "test_fpadd_pipe_fp32_regressions", Float32, add, vals=vals)
-
-def test_pipe_fp32_rand():
-    dut = FPADDMuxInOut(32, 4)
-    runfp(dut, 32, "test_fpadd_pipe_fp32_rand", Float32, add)
+    pc = PipeFPCase(dut, "add", unit_test_single, Float32,
+                   32, corner_cases, add, 10)
+    pc.run("rand1", get_rand1)
+    pc.run("n127", get_n127)
+    pc.run("noncan", get_nan_noncan)
+    pc.run("nearlyzero", get_nearly_zero)
+    pc.run("nearlyinf", get_nearly_inf)
+    pc.run("corner_rand", get_corner_rand)
+    pc.run_cornercases()
+    pc.run_regressions(regressions)
+    pc.run_random()
 
 
 if __name__ == '__main__':
-    test_pipe_fp32_regressions()
-    test_pipe_fp32_cornercases()
-    test_pipe_fp32_rand()
-    test_pipe_fp32_rand1()
-    test_pipe_fp32_nan_noncan()
-    test_pipe_fp32_n127()
-    test_pipe_fp32_nearly_zero()
-    test_pipe_fp32_nearly_inf()
-    test_pipe_fp32_corner_rand()
-
+    test_pipe_fp32()
index 273c80253fe9db0d78a3310de898d1042a3200c9..90db317f9916bdb07ef4ddc22b567caf328cf93c 100644 (file)
@@ -157,7 +157,6 @@ def repeat(num_rows, vals):
     """
     vals = list(vals)
     n_to_repeat = len(vals) % num_rows
-    print (vals, vals[-1])
     return vals + [vals[-1]] * n_to_repeat