コード例 #1
0
def test_part2_jump_examples_with_input_0(mock_input, mock_print, programme):
    """All cases, input == 0 => expected of 0"""
    expected = 0

    part1.intcode(programme)

    mock_print.assert_called_once_with(expected)
コード例 #2
0
def test_input_output(mock_input, mock_print):
    program = ["3", "0", "4", "0", "99"]
    input_ = 1234
    mock_input.return_value = input_
    part1.intcode(program)
    mock_input.assert_called_once()
    mock_print.assert_called_once_with(input_)
コード例 #3
0
def test_part2_comparison_examples_with_input_above_8(mock_input, mock_print,
                                                      programme):
    """All cases, input > 8 => expected of 0"""
    expected = 0

    part1.intcode(programme)

    mock_print.assert_called_once_with(expected)
コード例 #4
0
def test_part2_input_above_8(mock_input, mock_print):
    programme = [
        "3",
        "21",
        "1008",
        "21",
        "8",
        "20",
        "1005",
        "20",
        "22",
        "107",
        "8",
        "21",
        "20",
        "1006",
        "20",
        "31",
        "1106",
        "0",
        "36",
        "98",
        "0",
        "0",
        "1002",
        "21",
        "125",
        "20",
        "4",
        "20",
        "1105",
        "1",
        "46",
        "104",
        "999",
        "1105",
        "1",
        "46",
        "1101",
        "1000",
        "1",
        "20",
        "4",
        "20",
        "1105",
        "1",
        "46",
        "98",
        "99",
    ]

    expected = 1001

    part1.intcode(programme)

    mock_print.assert_called_once_with(expected)
コード例 #5
0
def test_run_diagnostic(mock_input, mock_print):
    part1.intcode(get_input())
    # should get input once
    assert mock_input.call_count == 1
    # Every diagnostic except the last should be 0
    assert len(mock_print.call_args_list) > 1
    for call in mock_print.call_args_list[:-1]:
        assert call == mock.call(0) or call == mock.call("0")
    assert mock_print.call_args_list[-1] != mock.call(0)
    assert mock_print.call_args_list[-1] != mock.call("0")
コード例 #6
0
def test_negative_number():
    input_ = ["1101", "100", "-1", "4", "0"]

    expected = [1101, 100, -1, 4, 99]
    actual = part1.intcode(input_)

    assert actual == expected
コード例 #7
0
def test_case_1():
    input_program = [1, 0, 0, 0, 99]
    expected_output = [2, 0, 0, 0, 99]
    output = intcode(input_program)

    assert output == expected_output
コード例 #8
0
def test_case_5():
    input_program = [1, 1, 1, 3, 1202, 5, 6, 0, 99]
    with pytest.raises(RuntimeError):
        output = intcode(input_program)
コード例 #9
0
def test_case_4():
    input_program = [1, 1, 1, 4, 99, 5, 6, 0, 99]
    expected_output = [30, 1, 1, 4, 2, 5, 6, 0, 99]
    output = intcode(input_program)

    assert output == expected_output
コード例 #10
0
def test_case_3():
    input_program = [2, 4, 4, 5, 99, 0]
    expected_output = [2, 4, 4, 5, 99, 9801]
    output = intcode(input_program)

    assert output == expected_output
コード例 #11
0
def test_case_2():
    input_program = [2, 3, 0, 3, 99]
    expected_output = [2, 3, 0, 6, 99]
    output = intcode(input_program)

    assert output == expected_output
コード例 #12
0
from input_data import get_input
from part1 import intcode

if __name__ == "__main__":
    for noun in range(99):
        for verb in range(99):
            input_data = get_input()
            input_data[1] = noun
            input_data[2] = verb
            try:
                output_data = intcode(input_data)
            except:
                print(f"Error for noun: {noun}, verb: {verb}")
            if output_data[0] == 19690720:
                print(f"Noun: {noun}, Verb: {verb}, answer: {100*noun + verb}")
コード例 #13
0
def test_access_modes_simple():
    input_ = ["1002", "4", "3", "4", "33"]
    expected = [1002, 4, 3, 4, 99]
    end_state = part1.intcode(input_)
    assert end_state == expected
コード例 #14
0
def test_part2_comparison_examples_with_input_below_8(mock_input, mock_print,
                                                      programme, expected):
    """First and third cases expect 0 for input < 8, other cases expect 1"""
    part1.intcode(programme)

    mock_print.assert_called_once_with(expected)