From 961adfedd9adee86be6bb5984145bdfe8d6f8fe2 Mon Sep 17 00:00:00 2001 From: Jeroen van Rijn Date: Thu, 29 Jul 2021 21:33:45 +0200 Subject: [PATCH] big: Test negative inputs as well. --- core/math/big/test.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/core/math/big/test.py b/core/math/big/test.py index f325d7787..1700f42aa 100644 --- a/core/math/big/test.py +++ b/core/math/big/test.py @@ -171,7 +171,15 @@ def test_div_two(a = 0, b = 0, radix = 10, expected_error = E_None, expected_res print("Exception with arguments:", a, b, radix) return False if expected_result == None: - expected_result = a // b if b != 0 else None + # + # We don't round the division results, so if one component is negative, we're off by one. + # + if a < 0 and b > 0: + expected_result = int(-(abs(a) / b)) + elif b < 0 and a > 0: + expected_result = int(-(a / abs((b)))) + else: + expected_result = a // b if b != 0 else None return test("test_div_two", res, [sa_c, sb_c, radix], expected_error, expected_result) @@ -264,11 +272,13 @@ if __name__ == '__main__': TIMINGS = {} for i in range(ITERATIONS): - a = randint(0, 1 << BITS) + a = randint(-(1 << BITS), 1 << BITS) + b = randint(-(1 << BITS), 1 << BITS) if test_proc == test_div_two: # We've already tested division by zero above. - b = randint(1, 1 << BITS) + if b == 0: + b == 42 elif test_proc == test_log: # We've already tested log's domain errors. a = randint(1, 1 << BITS)