Browse Source

big: Test negative inputs as well.

Jeroen van Rijn 4 years ago
parent
commit
961adfedd9
1 changed files with 13 additions and 3 deletions
  1. 13 3
      core/math/big/test.py

+ 13 - 3
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)
 		print("Exception with arguments:", a, b, radix)
 		return False
 		return False
 	if expected_result == None:
 	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)
 	return test("test_div_two", res, [sa_c, sb_c, radix], expected_error, expected_result)
 
 
 
 
@@ -264,11 +272,13 @@ if __name__ == '__main__':
 			TIMINGS    = {}
 			TIMINGS    = {}
 
 
 			for i in range(ITERATIONS):
 			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:
 				if test_proc == test_div_two:
 					# We've already tested division by zero above.
 					# We've already tested division by zero above.
-					b = randint(1, 1 << BITS)
+					if b == 0:
+						b == 42
 				elif test_proc == test_log:
 				elif test_proc == test_log:
 					# We've already tested log's domain errors.
 					# We've already tested log's domain errors.
 					a = randint(1, 1 << BITS)
 					a = randint(1, 1 << BITS)