working on goldschmidt_div_sqrt.py
[soc.git] / src / soc / fu / div / experiment / test / test_goldschmidt_div_sqrt.py
index b4c9da7fa492524ac5a360fac82fb0ced93ee5c9..fd07d6151a3e2fb187e36b17d41905a64f09c6e9 100644 (file)
@@ -25,18 +25,21 @@ class TestGoldschmidtDiv(FHDLTestCase):
     def tst(self, io_width):
         assert isinstance(io_width, int)
         params = GoldschmidtDivParams.get(io_width)
-        print(params)
-        for d in range(1, 1 << io_width):
-            for n in range(d << io_width):
-                expected = n // d
-                with self.subTest(io_width=io_width, n=hex(n), d=hex(d),
-                                  expected=hex(expected)):
-                    result = goldschmidt_div(n, d, params)
-                    self.assertEqual(result, expected, f"result={hex(result)}")
+        with self.subTest(params=str(params)):
+            for d in range(1, 1 << io_width):
+                for n in range(d << io_width):
+                    expected_q, expected_r = divmod(n, d)
+                    with self.subTest(n=hex(n), d=hex(d),
+                                      expected_q=hex(expected_q),
+                                      expected_r=hex(expected_r)):
+                        q, r = goldschmidt_div(n, d, params)
+                        with self.subTest(q=hex(q), r=hex(r)):
+                            self.assertEqual((q, r), (expected_q, expected_r))
 
     def test_1_through_5(self):
-        for width in range(1, 5 + 1):
-            self.tst(width)
+        for io_width in range(1, 5 + 1):
+            with self.subTest(io_width=io_width):
+                self.tst(io_width)
 
     def test_6(self):
         self.tst(6)