def test_lt() -> None: ic = Intcomputer([1107, 2, 3, 9, 1107, 3, 2, 11, 104, 0, 104, 0, 99], 'test', Intcomputer.IN_INTERNAL_LIST, Intcomputer.OUT_INTERNAL_LIST) ic.run() assert ic.list_output() == 1 assert ic.list_output() == 0
def test_eq() -> None: ic = Intcomputer( list_to_dict([1108, 3, 3, 9, 1108, 3, 4, 11, 104, 0, 104, 0, 99]), 'test', Intcomputer.IN_INTERNAL_LIST, Intcomputer.OUT_INTERNAL_LIST) ic.run() assert ic.list_output() == 1 assert ic.list_output() == 0
def test_jit() -> None: ic = Intcomputer( list_to_dict( [105, 1, 6, 104, 0, 99, 105, 0, 12, 104, 1, 99, 104, 0, 99]), 'test', Intcomputer.IN_INTERNAL_LIST, Intcomputer.OUT_INTERNAL_LIST) ic.run() assert ic.list_output() == 1
def test_fifo() -> None: ic = Intcomputer([3, 9, 3, 10, 4, 9, 4, 10, 99, 0, 0]) ic.input(1) ic.input(2) ic.run() assert ic.output() == 1 assert ic.output() == 2
def test_pipe_in() -> None: ic = Intcomputer(list_to_dict([3, 1, 99]), 'test', Intcomputer.IN_PIPE) i, o = Pipe() ic.set_in_pipe_connection(i) o.send(1) ic.run() assert ic.ram[1] == 1
def test_fifo_internal_list() -> None: ic = Intcomputer(list_to_dict([3, 9, 3, 10, 4, 9, 4, 10, 99, 0, 0]), 'test', Intcomputer.IN_INTERNAL_LIST, Intcomputer.OUT_INTERNAL_LIST) ic.list_input(1) ic.list_input(2) ic.run() assert ic.list_output() == 1 assert ic.list_output() == 2
def test_extended_memory() -> None: intcode = list_to_dict([4, 888, 99]) intcode2 = list_to_dict([1101, 1, 1, 888, 4, 888, 99]) ic = Intcomputer(intcode, outputMethod=Intcomputer.OUT_INTERNAL_LIST) ic2 = Intcomputer(intcode2, outputMethod=Intcomputer.OUT_INTERNAL_LIST) ic.run() ic2.run() assert ic.list_output() == 0 assert ic.ram[888] == 0 assert ic2.list_output() == 2 assert ic2.ram[888] == 2
def test_jif() -> None: ic = Intcomputer( [1106, 0, 6, 104, 0, 99, 1106, 1, 12, 104, 1, 99, 104, 0, 99], 'test', Intcomputer.IN_INTERNAL_LIST, Intcomputer.OUT_INTERNAL_LIST) ic.run() assert ic.list_output() == 1
def test_internal_list_in() -> None: ic = Intcomputer(list_to_dict([3, 1, 99]), 'test', Intcomputer.IN_INTERNAL_LIST) ic.list_input(1) ic.run() assert ic.ram[1] == 1
def test_console_in(monkeypatch) -> None: monkeypatch.setattr('builtins.input', lambda x: '1') ic = Intcomputer(list_to_dict([3, 1, 99])) ic.run() assert ic.ram[1] == 1
def test_immediate_mul() -> None: ic = Intcomputer(list_to_dict([1102, 2, 2, 3, 99])) ic.run() assert ic.ram[3] == 4
def test_positional_mul() -> None: ic = Intcomputer(list_to_dict([2, 0, 0, 3, 99])) ic.run() assert ic.ram[3] == 4
def test_immediate_add() -> None: ic = Intcomputer(list_to_dict([1101, 1, 1, 3, 99])) ic.run() assert ic.ram[3] == 2
from intcomputer import Intcomputer with open("inputs.txt", "r+") as inputs: raw_intcode = ''.join(inputs.readlines()) intcode = [int(elt) for elt in raw_intcode.split(',')] intcom = Intcomputer(intcode) intcom.run() while(True): try: print("Output -->",intcom.output()) except StopIteration: print("Nothing to output") break
def test_halt() -> None: ic = Intcomputer(list_to_dict([99])) ic.run() assert ic.halt == True and ic.ptr == 0
def test_eq() -> None: ic = Intcomputer([1108, 3, 3, 9, 1108, 3, 4, 11, 104, 0, 104, 0, 99]) ic.run() assert ic.output() == 1 assert ic.output() == 0
def test_console_out(capsys) -> None: ic = Intcomputer(list_to_dict([4, 1, 99])) ic.run() assert capsys.readouterr().out == "Output --> 1\n"
def test_lt() -> None: ic = Intcomputer([1107, 2, 3, 9, 1107, 3, 2, 11, 104, 0, 104, 0, 99]) ic.run() assert ic.output() == 1 assert ic.output() == 0
def test_jif() -> None: ic = Intcomputer( [1106, 0, 6, 104, 0, 99, 1106, 1, 12, 104, 1, 99, 104, 0, 99]) ic.run() assert ic.output() == 1
def test_positional_add() -> None: ic = Intcomputer([1, 0, 0, 3, 99]) ic.run() assert ic.ram[3] == 2
def test_out() -> None: ic = Intcomputer([4, 1, 99]) ic.run() assert ic.output() == 1
def test_in() -> None: ic = Intcomputer([3, 1, 99]) ic.input(1) ic.run() assert ic.ram[1] == 1
def test_internal_list_out() -> None: ic = Intcomputer(list_to_dict([4, 1, 99]), outputMethod=Intcomputer.OUT_INTERNAL_LIST) ic.run() assert ic.list_output() == 1
def makeRun(ic: Intcomputer) -> None: ic.run()
def test_relative_simple_add() -> None: ic = Intcomputer(list_to_dict([109, 4, 2201, -1, -2, 7, 104, 0, 99]), outputMethod=Intcomputer.OUT_INTERNAL_LIST) ic.run() assert ic.list_output() == 2200
from typing import Dict from intcomputer import Intcomputer, list_to_dict with open("c:\\projects\\aoc2019\\day 9\\inputs.txt", "r") as inputs: intcode: Dict[int, int] = list_to_dict( [int(elt) for elt in inputs.readline().split(',')]) ic = Intcomputer(intcode, "BOOST", Intcomputer.IN_INTERNAL_LIST, Intcomputer.OUT_STDOUT) ic.list_input(1) ic.run()