Beispiel #1
0
def test_bootcode_jmp():
    instance = BootCode(get_boot_code(EXAMPLE_BOOT_CODE_PATH))
    with patch("day_8.utils.BootCode.run") as mock_run:
        instance.jmp(1)
    assert instance.accumulator == 0
    assert instance.index == 1
    mock_run.assert_called()
Beispiel #2
0
def test_bootcode_run_fixed():
    instance = BootCode(get_boot_code(EXAMPLE_BOOT_CODE_PATH))
    instance.code[-2] = "nop", -4
    instance.run()
    assert instance.accumulator == 8
    assert instance.index == 9
    assert instance.terminated is True
Beispiel #3
0
def test_parse_code():
    expected = [
        ("nop", 0),
        ("acc", 1),
        ("jmp", 4),
        ("acc", 3),
        ("jmp", -3),
        ("acc", -99),
        ("acc", 1),
        ("jmp", -4),
        ("acc", 6),
    ]
    actual = parse_code(get_boot_code(EXAMPLE_BOOT_CODE_PATH))
    assert actual == expected
Beispiel #4
0
def test_get_boot_code():
    expected = [
        "nop +0",
        "acc +1",
        "jmp +4",
        "acc +3",
        "jmp -3",
        "acc -99",
        "acc +1",
        "jmp -4",
        "acc +6",
    ]
    actual = get_boot_code(EXAMPLE_BOOT_CODE_PATH)
    assert actual == expected
Beispiel #5
0
from typing import List

from day_8.utils import BootCode, get_boot_code


def get_accumulator(code: List[str]):
    """
    get the accumulator value at the point at which the same line is about to be repeated
    :param code: ordered lines of code
    :return: accumulator value
    """
    boot_code = BootCode(code)
    boot_code.run()
    return boot_code.accumulator


if __name__ == "__main__":
    print(get_accumulator(get_boot_code()))
Beispiel #6
0
def test_bootcode_run():
    instance = BootCode(get_boot_code(EXAMPLE_BOOT_CODE_PATH))
    instance.run()
    assert instance.accumulator == 5
    assert instance.index == 1
    assert instance.terminated is False
Beispiel #7
0
def test_bootcode_acc():
    instance = BootCode(get_boot_code(EXAMPLE_BOOT_CODE_PATH))
    with patch("day_8.utils.BootCode.run"):
        instance.acc(1)
    assert instance.accumulator == 1
    assert instance.index == 1
Beispiel #8
0
def test_get_accumulator():
    example_boot_code = get_boot_code(EXAMPLE_BOOT_CODE_PATH)
    assert get_accumulator(example_boot_code) == 5