refactor asserts

This commit is contained in:
2025-03-09 07:39:29 -05:00
parent 88b533c27b
commit 9fdf79842d
12 changed files with 84 additions and 64 deletions

View File

@@ -10,12 +10,14 @@ def secure_fisher_yates_shuffle(arr: list) -> list:
def generate_random_nonrepeating_list(list_len: int, min_val: int = 0, max_val: int = 2 ** 16) -> list[int]:
assert (max_val - min_val >= list_len)
if max_val - min_val < list_len:
raise ValueError("Range of values is less than the list length requested")
return secure_fisher_yates_shuffle(list(range(min_val, max_val)))[:list_len]
def xor_lists(l1: list[int], l2: list[int]):
assert len(l1) == len(l2)
if len(l1) != len(l2):
raise ValueError("Lists must be of equal length")
return [l2[i] ^ l1[i] for i in range(len(l1))]