2023-04-01 20:53:36 +03:00
|
|
|
import multiply as mlt
|
|
|
|
|
|
|
|
top_value = int("0b" + input("Top value (in binary): "), 2)
|
|
|
|
m = int(input("Method: "))
|
|
|
|
|
|
|
|
total_iterations = (top_value + 1) ** 2
|
|
|
|
print(f"Total test amount: {top_value + 1}^2 = {total_iterations}")
|
|
|
|
|
|
|
|
errors = []
|
|
|
|
|
|
|
|
for x in range(top_value):
|
|
|
|
for y in range(top_value):
|
|
|
|
n = max([len(bin(i)[2:]) for i in (x, y)])
|
|
|
|
expected_result = mlt.al(bin(x*y)[2:], 2*n)
|
|
|
|
|
|
|
|
_, r = mlt.multiply(n, x, y, m)
|
|
|
|
|
|
|
|
if r == expected_result:
|
|
|
|
print(f"{str(x*top_value+y).rjust(len(str(total_iterations)))}/{total_iterations}", end = "\r")
|
|
|
|
else:
|
|
|
|
errors.append([x, y, expected_result, r])
|
|
|
|
print(f"Failed at {x}*{y}; expected {expected_result} but got {r}!")
|
|
|
|
|
|
|
|
if len(errors) == 0:
|
|
|
|
print("Testing finished, no miscalculations detected.\nIt's safe to use!")
|
|
|
|
else:
|
2023-05-22 22:16:17 +03:00
|
|
|
print(f"Testing failed with {len(errors)} errors.")
|