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.
66 lines
1.6 KiB
66 lines
1.6 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 com.memory == [2, 0, 0, 0, 99]
|
|
|
|
|
|
def test_multiplication():
|
|
com = OpcodeComputer(mem="2,3,0,3,99")
|
|
com.process_all()
|
|
assert com.memory == [2, 3, 0, 6, 99]
|
|
|
|
|
|
def test_multiplication2():
|
|
com = OpcodeComputer(mem="2,4,4,5,99,0")
|
|
com.process_all()
|
|
assert com.memory == [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 com.memory == [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'
|
|
|