37 lines
855 B
Python
37 lines
855 B
Python
import itertools
|
|
from enum import Enum
|
|
|
|
|
|
class Operation(Enum):
|
|
SUB = 0
|
|
ADD = 1
|
|
|
|
def __str__(self):
|
|
if self == Operation.SUB:
|
|
return "[]"
|
|
elif self == Operation.ADD:
|
|
return "()"
|
|
else:
|
|
raise Exception("unreachable")
|
|
|
|
def __radd__(self, num):
|
|
if self == Operation.SUB:
|
|
return num - 1
|
|
elif self == Operation.ADD:
|
|
return num + 1
|
|
else:
|
|
raise Exception("unreachable")
|
|
|
|
|
|
track = set()
|
|
|
|
for i in range(13):
|
|
ops_iter = itertools.combinations([Operation.ADD] * i + [Operation.SUB] * i, i)
|
|
for ops in ops_iter:
|
|
correct = sum(ops)
|
|
track.add(f"""i = a{"".join(str(op) for op in ops)};
|
|
assert(i == {correct});""")
|
|
|
|
with open("tests", "w+") as out:
|
|
for test in sorted(track):
|
|
print(test, file=out)
|