From 7057a7cac357418f6dbd733425bd46c9488ec23b Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Thu, 25 Jul 2019 00:10:19 -0700 Subject: [PATCH] switch fpdiv/test/test_fp*.py to use unittest --- src/ieee754/fpdiv/test/test_fpdiv_pipe.py | 26 ++++++++------- src/ieee754/fpdiv/test/test_fpdiv_pipe_16.py | 14 +++++--- src/ieee754/fpdiv/test/test_fpdiv_pipe_32.py | 14 +++++--- src/ieee754/fpdiv/test/test_fprsqrt_pipe.py | 34 +++++++++++--------- src/ieee754/fpdiv/test/test_fpsqrt_pipe.py | 33 ++++++++++--------- 5 files changed, 69 insertions(+), 52 deletions(-) diff --git a/src/ieee754/fpdiv/test/test_fpdiv_pipe.py b/src/ieee754/fpdiv/test/test_fpdiv_pipe.py index c0b521b6..451d979d 100644 --- a/src/ieee754/fpdiv/test/test_fpdiv_pipe.py +++ b/src/ieee754/fpdiv/test/test_fpdiv_pipe.py @@ -4,22 +4,24 @@ from ieee754.fpdiv.pipeline import (FPDIVMuxInOut,) from ieee754.fpcommon.test.fpmux import runfp +import unittest from sfpy import Float64, Float32, Float16 from operator import truediv as div -def test_pipe_div_fp16(): - dut = FPDIVMuxInOut(16, 4) - runfp(dut, 16, "test_fpdiv_pipe_fp16", Float16, div) -def test_pipe_div_fp32(): - dut = FPDIVMuxInOut(32, 4) - runfp(dut, 32, "test_fpdiv_pipe_fp32", Float32, div) +class TestDivPipe(unittest.TestCase): + def test_pipe_div_fp16(self): + dut = FPDIVMuxInOut(16, 4) + runfp(dut, 16, "test_fpdiv_pipe_fp16", Float16, div) + + def test_pipe_div_fp32(self): + dut = FPDIVMuxInOut(32, 4) + runfp(dut, 32, "test_fpdiv_pipe_fp32", Float32, div) + + def test_pipe_div_fp64(self): + dut = FPDIVMuxInOut(64, 4) + runfp(dut, 64, "test_fpdiv_pipe_fp64", Float64, div) -def test_pipe_div_fp64(): - dut = FPDIVMuxInOut(64, 4) - runfp(dut, 64, "test_fpdiv_pipe_fp64", Float64, div) if __name__ == '__main__': - test_pipe_div_fp16() - test_pipe_div_fp32() - test_pipe_div_fp64() + unittest.main() diff --git a/src/ieee754/fpdiv/test/test_fpdiv_pipe_16.py b/src/ieee754/fpdiv/test/test_fpdiv_pipe_16.py index b6ba0e29..da617e9e 100644 --- a/src/ieee754/fpdiv/test/test_fpdiv_pipe_16.py +++ b/src/ieee754/fpdiv/test/test_fpdiv_pipe_16.py @@ -6,13 +6,17 @@ from ieee754.fpcommon.test.case_gen import run_pipe_fp from ieee754.fpcommon.test import unit_test_half from ieee754.fpdiv.test.div_data16 import regressions +import unittest from sfpy import Float16 from operator import truediv as div -def test_pipe_fp16(): - dut = FPDIVMuxInOut(16, 4) - run_pipe_fp(dut, 16, "div16", unit_test_half, Float16, - regressions, div, 10) + +class TestDivPipe(unittest.TestCase): + def test_pipe_fp16(self): + dut = FPDIVMuxInOut(16, 4) + run_pipe_fp(dut, 16, "div16", unit_test_half, Float16, + regressions, div, 10) + if __name__ == '__main__': - test_pipe_fp16() + unittest.main() diff --git a/src/ieee754/fpdiv/test/test_fpdiv_pipe_32.py b/src/ieee754/fpdiv/test/test_fpdiv_pipe_32.py index ddebfbce..d79eddce 100644 --- a/src/ieee754/fpdiv/test/test_fpdiv_pipe_32.py +++ b/src/ieee754/fpdiv/test/test_fpdiv_pipe_32.py @@ -6,13 +6,17 @@ from ieee754.fpcommon.test.case_gen import run_pipe_fp from ieee754.fpcommon.test import unit_test_single from ieee754.fpdiv.test.div_data32 import regressions +import unittest from sfpy import Float32 from operator import truediv as div -def test_pipe_fp32(): - dut = FPDIVMuxInOut(32, 4) - run_pipe_fp(dut, 32, "div32", unit_test_single, Float32, - regressions, div, 10) + +class TestDivPipe(unittest.TestCase): + def test_pipe_fp32(self): + dut = FPDIVMuxInOut(32, 4) + run_pipe_fp(dut, 32, "div32", unit_test_single, Float32, + regressions, div, 10) + if __name__ == '__main__': - test_pipe_fp32() + unittest.main() diff --git a/src/ieee754/fpdiv/test/test_fprsqrt_pipe.py b/src/ieee754/fpdiv/test/test_fprsqrt_pipe.py index 72e619b7..d8e47235 100644 --- a/src/ieee754/fpdiv/test/test_fprsqrt_pipe.py +++ b/src/ieee754/fpdiv/test/test_fprsqrt_pipe.py @@ -4,27 +4,31 @@ from ieee754.fpdiv.pipeline import (FPDIVMuxInOut,) from ieee754.fpcommon.test.fpmux import runfp +import unittest from sfpy import Float64, Float32, Float16 + def rsqrt(x): + # FIXME: switch to correct implementation (rounding once) return x.__class__(1.0) / x.sqrt() -def test_pipe_rsqrt_fp16(): - dut = FPDIVMuxInOut(16, 4) - runfp(dut, 16, "test_fprsqrt_pipe_fp16", Float16, rsqrt, - single_op=True, opcode=2, n_vals=100) -def test_pipe_rsqrt_fp32(): - dut = FPDIVMuxInOut(32, 4) - runfp(dut, 32, "test_fprsqrt_pipe_fp32", Float32, rsqrt, - single_op=True, opcode=2, n_vals=100) +class TestDivPipe(unittest.TestCase): + def test_pipe_rsqrt_fp16(self): + dut = FPDIVMuxInOut(16, 4) + runfp(dut, 16, "test_fprsqrt_pipe_fp16", Float16, rsqrt, + single_op=True, opcode=2, n_vals=100) + + def test_pipe_rsqrt_fp32(self): + dut = FPDIVMuxInOut(32, 4) + runfp(dut, 32, "test_fprsqrt_pipe_fp32", Float32, rsqrt, + single_op=True, opcode=2, n_vals=100) + + def test_pipe_rsqrt_fp64(self): + dut = FPDIVMuxInOut(64, 4) + runfp(dut, 64, "test_fprsqrt_pipe_fp64", Float64, rsqrt, + single_op=True, opcode=2, n_vals=100) -def test_pipe_rsqrt_fp64(): - dut = FPDIVMuxInOut(64, 4) - runfp(dut, 64, "test_fprsqrt_pipe_fp64", Float64, rsqrt, - single_op=True, opcode=2, n_vals=100) if __name__ == '__main__': - test_pipe_rsqrt_fp32() - test_pipe_rsqrt_fp16() - test_pipe_rsqrt_fp64() + unittest.main() diff --git a/src/ieee754/fpdiv/test/test_fpsqrt_pipe.py b/src/ieee754/fpdiv/test/test_fpsqrt_pipe.py index 38b1f360..e474ba86 100644 --- a/src/ieee754/fpdiv/test/test_fpsqrt_pipe.py +++ b/src/ieee754/fpdiv/test/test_fpsqrt_pipe.py @@ -4,27 +4,30 @@ from ieee754.fpdiv.pipeline import (FPDIVMuxInOut,) from ieee754.fpcommon.test.fpmux import runfp +import unittest from sfpy import Float64, Float32, Float16 + def sqrt(x): return x.sqrt() -def test_pipe_sqrt_fp16(): - dut = FPDIVMuxInOut(16, 4) - runfp(dut, 16, "test_fpsqrt_pipe_fp16", Float16, sqrt, - single_op=True, opcode=1, n_vals=100) -def test_pipe_sqrt_fp32(): - dut = FPDIVMuxInOut(32, 4) - runfp(dut, 32, "test_fpsqrt_pipe_fp32", Float32, sqrt, - single_op=True, opcode=1, n_vals=100) +class TestDivPipe(unittest.TestCase): + def test_pipe_sqrt_fp16(self): + dut = FPDIVMuxInOut(16, 4) + runfp(dut, 16, "test_fpsqrt_pipe_fp16", Float16, sqrt, + single_op=True, opcode=1, n_vals=100) + + def test_pipe_sqrt_fp32(self): + dut = FPDIVMuxInOut(32, 4) + runfp(dut, 32, "test_fpsqrt_pipe_fp32", Float32, sqrt, + single_op=True, opcode=1, n_vals=100) + + def test_pipe_sqrt_fp64(self): + dut = FPDIVMuxInOut(64, 4) + runfp(dut, 64, "test_fpsqrt_pipe_fp64", Float64, sqrt, + single_op=True, opcode=1, n_vals=100) -def test_pipe_sqrt_fp64(): - dut = FPDIVMuxInOut(64, 4) - runfp(dut, 64, "test_fpsqrt_pipe_fp64", Float64, sqrt, - single_op=True, opcode=1, n_vals=100) if __name__ == '__main__': - test_pipe_sqrt_fp16() - test_pipe_sqrt_fp32() - test_pipe_sqrt_fp64() + unittest.main() -- 2.30.2