예제 #1
0
    def test_get_address_to_store_next_instruction_result(self):
        intcode_program_instance = intcode_program([1, 0, 0, 0, 99])

        result = intcode_program_instance.get_address_to_store_next_instruction_result(
        )

        self.assertEqual(result, 0)
예제 #2
0
    def test_intcode_program1(self):
        intcode_program_instance = intcode_program([1, 0, 0, 0, 99])
        intcode_program_instance.execute_intcode_program()

        result = intcode_program_instance.get_current_memory_state()

        self.assertEqual(result, [2, 0, 0, 0, 99])
예제 #3
0
    def test_intcode_program3(self):
        intcode_program_instance = intcode_program([2, 4, 4, 5, 99, 0])
        intcode_program_instance.execute_intcode_program()

        result = intcode_program_instance.get_current_memory_state()

        self.assertEqual(result, [2, 4, 4, 5, 99, 9801])
예제 #4
0
    def test_replace_value_at_memory_address(self):
        intcode_program_instance = intcode_program([2, 3, 7])

        intcode_program_instance.replace_value_at_memory_address(0, 1)
        result = intcode_program_instance.get_current_memory_state()

        self.assertEqual(result, [1, 3, 7])
예제 #5
0
    def test_valid_next_opcode(self):
        intcode_program_instance = intcode_program([1, 3, 6, 7, 99])

        intcode_program_instance.set_next_instruction_pointer_and_opcode_value(
        )
        result = intcode_program_instance.get_opcode()

        self.assertEqual(result, 99)
예제 #6
0
    def test_find_noun_and_verb_that_produces_output_2(self):
        intcode_program_input = read_gravity_assist_program("Input/day2.txt")
        intcode_program_instance = intcode_program(intcode_program_input)

        result = intcode_program_instance.find_noun_and_verb_that_produces_output(
            19690720)

        self.assertEqual(result, 9820)
예제 #7
0
    def test_intcode_program4(self):
        intcode_program_instance = intcode_program(
            [1, 1, 1, 4, 99, 5, 6, 0, 99])
        intcode_program_instance.execute_intcode_program()

        result = intcode_program_instance.get_current_memory_state()

        self.assertEqual(result, [30, 1, 1, 4, 2, 5, 6, 0, 99])
예제 #8
0
    def test_gravity_assist_program(self):
        intcode_program_input = read_gravity_assist_program("Input/day2.txt")
        intcode_program_instance = intcode_program(intcode_program_input)
        intcode_program_instance.restore_gravity_assist_program()
        intcode_program_instance.execute_intcode_program()

        result = intcode_program_instance.get_current_memory_state()[0]

        self.assertEqual(result, 2782414)
예제 #9
0
    def test_intcode_program5(self):
        intcode_program_instance = intcode_program(
            [1, 9, 10, 3, 2, 3, 11, 0, 99, 30, 40, 50])
        intcode_program_instance.execute_intcode_program()

        result = intcode_program_instance.get_current_memory_state()

        self.assertEqual(result,
                         [3500, 9, 10, 70, 2, 3, 11, 0, 99, 30, 40, 50])
예제 #10
0
    def test_get_parameters_for_next_instruction(self):
        intcode_program_instance = intcode_program([1, 0, 0, 0, 99])

        result = intcode_program_instance.get_parameters_for_next_instruction()

        self.assertEqual(result, (1, 1))
예제 #11
0
    def test_next_opcode_index_error(self):
        intcode_program_instance = intcode_program([1, 3, 6])

        with self.assertRaises(IndexError):
            intcode_program_instance.set_next_instruction_pointer_and_opcode_value(
            )
예제 #12
0
    def test_invalid_next_opcode(self):
        intcode_program_instance = intcode_program([1, 3, 6, 7, 3])

        with self.assertRaises(ValueError):
            intcode_program_instance.set_next_instruction_pointer_and_opcode_value(
            )
예제 #13
0
    def test_get_initial_opcode(self):
        intcode_program_instance = intcode_program([1, 3, 6])

        result = intcode_program_instance.get_opcode()

        self.assertEqual(result, 1)
예제 #14
0
    def test_replace_value_at_memory_address_error(self):
        intcode_program_instance = intcode_program([1, 3, 7])

        with self.assertRaises(IndexError):
            intcode_program_instance.replace_value_at_memory_address(7, 1)
예제 #15
0
 def test_invalid_initial_opcode(self):
     with self.assertRaises(ValueError):
         intcode_program([7, 3, 7])