예제 #1
0
    def test_should_fix_an_infinity_loop(self):
        # given
        instructions = [
            "jmp +0",
            "acc +1",
            "jmp +4",
            "acc +3",
            "jmp -3",
            "acc -99",
            "acc +1",
            "jmp -4",
            "acc +6",
        ]

        # when
        run_console(instructions)
예제 #2
0
    def test_should_return_1941_for_first_exercise(self):
        # given
        file_reader = FileReader('./input')
        instructions = file_reader.to_str_list()

        # when
        accumulator = run_console(instructions)['accumulator']

        # then
        assert accumulator == 1941
예제 #3
0
    def test_accumulator_adds_up_1(self):
        # given
        instructions = [
            "acc +1"
        ]

        # when
        trace = run_console(instructions)

        # then
        assert trace["accumulator"] == 1
예제 #4
0
    def test_nope_does_not_add_anything(self):
        # given
        code = [
            "nop +0",
        ]

        # when
        trace = run_console(code)

        # then
        assert trace["accumulator"] == 0
예제 #5
0
    def test_multiple_accumulator_adds_up(self):
        # given
        instructions = [
            "acc +2",
            "acc +5"
        ]

        # when
        trace = run_console(instructions)

        # then
        assert trace["accumulator"] == 7
예제 #6
0
    def test_jmp_1_goes_to_next_instruction(self):
        # given
        instructions = [
            "jmp +2",
            "acc +1",
            "acc +2",
        ]

        # when
        trace = run_console(instructions)

        # then
        assert trace["accumulator"] == 2
예제 #7
0
    def test_should_stop_on_infinity_loop(self):
        # given
        instructions = [
            "nop +0",
            "jmp +2",
            "acc +1",
            "jmp -2",
        ]

        # when
        trace = run_console(instructions)

        # then
        assert trace["has_failed"] is True