Esempio n. 1
0
def test_route_empty_grid():
    grid = empty_grid(2, 2)
    result = escape_routes(grid)
    for row in 0, 1:
        for column in 0, 1:
            with pytest.raises(ValueError):
                result.route(row, column)
Esempio n. 2
0
def test_route_nonempty_grid():
    grid = empty_grid(2, 2)
    grid[0, 0] = 2
    result = escape_routes(grid)
    route = result.route(1, 0)  # this route exists
    route = list(route)  # asserts this can be converted
    assert isinstance(route[0], tuple)
    assert len(route[0]) == 2
    assert isinstance(route[0][0], int)
    assert isinstance(route[0][1], int)
Esempio n. 3
0
def escape_routes_(grid):
    print('GRID:')
    print(grid)
    print()
    result = escape_routes(grid)
    print('DISTANCES:')
    print(result.distances)
    print()
    print('DIRECTIONS:')
    print(result.directions)
    print()
    print('SAFE FACTOR:', result.safe_factor)
    return result
Esempio n. 4
0
def test_1D_array_not_possible():
    with pytest.raises(TypeError):
        escape_routes(numpy.zeros((1, ), dtype=int))
Esempio n. 5
0
def test_multiple_args_not_possible():
    with pytest.raises(TypeError):
        escape_routes(numpy.zeros((1, 1), dtype=int), None)
Esempio n. 6
0
def test_no_args_not_possible():
    with pytest.raises(TypeError):
        escape_routes()
Esempio n. 7
0
def test_route_more_arguments():
    grid = empty_grid(2, 2)
    result = escape_routes(grid)
    with pytest.raises(TypeError):
        result.route(1, 1, 1)
Esempio n. 8
0
def test_route_nonindex():
    grid = empty_grid(2, 2)
    result = escape_routes(grid)
    with pytest.raises(IndexError):
        result.route('spam', 'eggs')
Esempio n. 9
0
def test_route_outside():
    grid = empty_grid(2, 2)
    result = escape_routes(grid)
    with pytest.raises(IndexError):
        result.route(100, 100)
Esempio n. 10
0
def test_safe_factor_type_size_empty():
    grid = empty_grid(0, 0)
    result = escape_routes(grid)
    assert numpy.isnan(result.safe_factor)  # `nan == nan` is False
Esempio n. 11
0
def test_safe_factor_type_size():
    grid = empty_grid(4, 15)
    result = escape_routes(grid)
    assert isinstance(result.safe_factor, float)
    assert 0.0 <= result.safe_factor <= 1.0
Esempio n. 12
0
def test_directions_shape_type():
    grid = empty_grid(4, 15)
    result = escape_routes(grid)
    assert result.directions.shape == grid.shape
    assert isinstance(result.directions[0, 0], bytes)
    assert len(result.directions[0, 0]) == 1
Esempio n. 13
0
def test_nonarray_not_possible():
    with pytest.raises(TypeError):
        escape_routes([0, 0, 0])
Esempio n. 14
0
def test_float_array_not_possible():
    with pytest.raises(TypeError):
        escape_routes(numpy.zeros((1, 1), dtype=float))
Esempio n. 15
0
def test_disatnces_shape_type():
    grid = empty_grid(3, 7)
    result = escape_routes(grid)
    assert result.distances.shape == grid.shape
    assert isinstance(result.distances[0, 0], numpy.signedinteger)