Esempio n. 1
0
def test_position_step_1():
    position = Position(0, 0, ['##', '##'])
    position.step()
    assert (position.x, position.y) == (0, 1)
    position.step()
    assert (position.x, position.y) == (1, 1)
    position.step()
    assert (position.x, position.y) == (1, 0)
Esempio n. 2
0
def test_position_right_no_segment_right():
    position = Position(0, 0, ['#.', '##'])
    assert position.right() is False
Esempio n. 3
0
def test_position_right_ok():
    position = Position(0, 0, ['##', '..'])
    assert position.right() is True
Esempio n. 4
0
def test_position_down_ok():
    position = Position(0, 0, ['#', '#'])
    assert position.down() is True
Esempio n. 5
0
def test_position_right_already_end():
    position = Position(0, 0, ['#', '#'])
    assert position.right() is False
Esempio n. 6
0
def test_position_down_no_segment_below():
    position = Position(0, 0, ['#', '.'])
    assert position.down() is False
Esempio n. 7
0
def test_position_down_already_visited():
    position = Position(0, 0, ['#', '#'])
    position.prev_x, position.prev_y = 0, 1
    assert position.down() is False
Esempio n. 8
0
def test_position_up_ok():
    position = Position(0, 1, ['#', '#'])
    assert position.up() is True
Esempio n. 9
0
def test_position_down_already_bottom():
    position = Position(0, 1, ['.', '#'])
    assert position.down() is False
Esempio n. 10
0
def test_position_up_already_visited():
    position = Position(0, 1, ['#', '#'])
    position.prev_x, position.prev_y = 0, 0
    assert position.up() is False
Esempio n. 11
0
def test_position_up_no_segment_above():
    position = Position(0, 1, ['.', '#'])
    assert position.up() is False
Esempio n. 12
0
def test_position_up_already_top():
    position = Position(0, 0, ['#', '.'])
    assert position.up() is False
Esempio n. 13
0
def test_start_position(grid, starts):
    expected = [Position(*start, grid=grid) for start in starts]
    assert start_positions(grid) == expected
Esempio n. 14
0
    expected = [Position(*start, grid=grid) for start in starts]
    assert start_positions(grid) == expected


@pytest.mark.parametrize('grid,total', [
    (['...', '..#'], 1),
    (['###', '###'], 6),
    (['.#.', '.#.'], 2),
    (['.', '#'], 1),
])
def test_count_segments(grid, total):
    assert count_segments(grid) == total


@pytest.mark.parametrize('position,expected', [
    (Position(2, 1, ['#', '.']), (2, 1)),
    (Position(1, 2, ['#', '.']), (1, 2)),
])
def test_position_init(position, expected):
    assert (position.x, position.y) == expected
    assert (position.prev_x, position.prev_y) == expected
    assert position.grid == ['#', '.']


def test_position_up_already_top():
    position = Position(0, 0, ['#', '.'])
    assert position.up() is False


def test_position_up_no_segment_above():
    position = Position(0, 1, ['.', '#'])