aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorJeroen van Rijn <Kelimion@users.noreply.github.com>2021-07-29 21:33:45 +0200
committerJeroen van Rijn <Kelimion@users.noreply.github.com>2021-08-11 20:59:52 +0200
commit961adfedd9adee86be6bb5984145bdfe8d6f8fe2 (patch)
treecae570a539320346d440b564c33f1c48085866b1 /core
parent385b9c99229f09a6d7a45fd143747e1135331f94 (diff)
big: Test negative inputs as well.
Diffstat (limited to 'core')
-rw-r--r--core/math/big/test.py16
1 files 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)