You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
AdventOfCode19/days/test_comp.py

86 lines
2.3 KiB

import unittest
import os
from . import OpcodeComputer
inputfile = os.path.join(os.path.dirname(__file__), "input/day9_input")
def test_addition():
com = OpcodeComputer(mem="1,0,0,0,99")
com.process_all()
assert list(com.memory.values()) == [2, 0, 0, 0, 99]
def test_multiplication():
com = OpcodeComputer(mem="2,3,0,3,99")
com.process_all()
assert list(com.memory.values()) == [2, 3, 0, 6, 99]
def test_multiplication2():
com = OpcodeComputer(mem="2,4,4,5,99,0")
com.process_all()
assert list(com.memory.values()) == [2, 4, 4, 5, 99, 9801]
def test_addition2():
com = OpcodeComputer(mem="1,1,1,4,99,5,6,0,99")
com.process_all()
assert list(com.memory.values()) == [30, 1, 1, 4, 2, 5, 6, 0, 99]
def test_position1():
com = OpcodeComputer(mem="3,9,8,9,10,9,4,9,99,-1,8")
res = list(com.process_op([8]))
assert res[0] == 1
def test_position2():
com = OpcodeComputer(mem="3,9,7,9,10,9,4,9,99,-1,8")
res = list(com.process_op([7]))
assert res[0] == 1
def test_immediate1():
com = OpcodeComputer(mem="3,3,1108,-1,8,3,4,3,99")
res = list(com.process_op([8]))
assert res[0] == 1
def test_immediate2():
com = OpcodeComputer(mem="3,3,1107,-1,8,3,4,3,99")
res = list(com.process_op([7]))
assert res[0] == 1
def test_jump_position():
com = OpcodeComputer(mem="3,12,6,12,15,1,13,14,13,4,13,99,-1,0,1,9")
res = list(com.process_op([0]))
assert res[0] == 0
def test_jump_immediate():
com = OpcodeComputer(mem="3,3,1105,-1,9,1101,0,0,12,4,12,99,1")
res = list(com.process_op([0]))
assert res[0] == 0
def test_rel_base_copy():
com = OpcodeComputer(mem="109,1,204,-1,1001,100,1,100,1008,100,16,101,\
1006,101,0,99")
res = list(com.process_op([]))
assert res == [109, 1, 204, -1, 1001, 100, 1, 100, 1008, 100, 16, 101,
1006, 101, 0, 99]
def test_rel_base_16digit():
com = OpcodeComputer(mem="1102,34915192,34915192,7,4,7,99,0")
res = list(com.process_op([]))
assert len(str(res[0])) == 16
def test_rel_base_large():
com = OpcodeComputer(mem="104,1125899906842624,99")
res = list(com.process_op([0]))
assert res[0] == 1125899906842624