|
| 1 | +# -------------------------------- Input data ---------------------------------------- # |
| 2 | +import os, pathfinding |
| 3 | + |
| 4 | +from complex_utils import * |
| 5 | +from IntCode import * |
| 6 | + |
| 7 | +test_data = {} |
| 8 | + |
| 9 | +test = 1 |
| 10 | +test_data[test] = { |
| 11 | + "input": """109,1,204,-1,1001,100,1,100,1008,100,16,101,1006,101,0,99""", |
| 12 | + "expected": [ |
| 13 | + "109,1,204,-1,1001,100,1,100,1008,100,16,101,1006,101,0,99", |
| 14 | + "Unknown", |
| 15 | + ], |
| 16 | +} |
| 17 | + |
| 18 | +test = "real" |
| 19 | +input_file = os.path.join( |
| 20 | + os.path.dirname(__file__), |
| 21 | + "Inputs", |
| 22 | + os.path.basename(__file__).replace(".py", ".txt"), |
| 23 | +) |
| 24 | +test_data[test] = { |
| 25 | + "input": open(input_file, "r+").read().strip(), |
| 26 | + "expected": ["3380552333", "78831"], |
| 27 | +} |
| 28 | + |
| 29 | +# -------------------------------- Control program execution ------------------------- # |
| 30 | + |
| 31 | +case_to_test = "real" |
| 32 | +part_to_test = 2 |
| 33 | + |
| 34 | +# -------------------------------- Initialize some variables ------------------------- # |
| 35 | + |
| 36 | +puzzle_input = test_data[case_to_test]["input"] |
| 37 | +puzzle_expected_result = test_data[case_to_test]["expected"][part_to_test - 1] |
| 38 | +puzzle_actual_result = "Unknown" |
| 39 | + |
| 40 | + |
| 41 | +# -------------------------------- Actual code execution ----------------------------- # |
| 42 | + |
| 43 | +computer = IntCode(puzzle_input) |
| 44 | +computer.add_input(part_to_test) |
| 45 | +computer.run() |
| 46 | +if len(computer.outputs) == 1: |
| 47 | + puzzle_actual_result = computer.outputs[0] |
| 48 | +else: |
| 49 | + puzzle_actual_result = "Errors on opcodes : " + ",".join(map(str, computer.outputs)) |
| 50 | + |
| 51 | + |
| 52 | +# -------------------------------- Outputs / results --------------------------------- # |
| 53 | + |
| 54 | +print("Expected result : " + str(puzzle_expected_result)) |
| 55 | +print("Actual result : " + str(puzzle_actual_result)) |
0 commit comments