Exemplo n.º 1
0
def get_program_output(program, n=None, v=None):
    program = [int(i) for i in program.split(",")]
    if n is not None:
        program[1] = n
    if v is not None:
        program[2] = v

    icr = IntCodeCPU(program)
    icr.run()

    return icr.peek(0)
Exemplo n.º 2
0
 def test_eq_is_not_equal(self):
     program = [8, 5, 6, 7, 99, 8, 5, 42]
     cpu = IntCodeCPU(program)
     cpu.run()
     self.assertEqual(0, cpu.peek(7))
Exemplo n.º 3
0
 def test_lt_is_lower(self):
     program = [7, 5, 6, 7, 99, 5, 8, 42]
     cpu = IntCodeCPU(program)
     cpu.run()
     self.assertEqual(1, cpu.peek(7))
Exemplo n.º 4
0
    def test_read_with_input(self):
        program = [3, 3, 99, 0]
        cpu = IntCodeCPU(program)
        cpu.run((42, ))

        self.assertEqual(42, cpu.peek(3))
Exemplo n.º 5
0
    def test_mul(self):
        program = [2, 5, 6, 7, 99, 5, 8, 0]
        cpu = IntCodeCPU(program)
        cpu.run()

        self.assertEqual(40, cpu.peek(7))
Exemplo n.º 6
0
    def test_add(self):
        program = [1, 5, 6, 7, 99, 5, 8, 0]
        cpu = IntCodeCPU(program)
        cpu.run()

        self.assertEqual(13, cpu.peek(7))