Add Pixel.northeast/southwest properties
- the properties are needed for the drawing functionalitites
This commit is contained in:
parent
ca2ba0c9d5
commit
605ade4078
5 changed files with 96 additions and 2 deletions
|
|
@ -205,7 +205,7 @@ class TestGridification:
|
|||
@pytest.mark.db
|
||||
@pytest.mark.no_cover
|
||||
@pytest.mark.parametrize('side_length', [250, 500, 1_000, 2_000, 4_000, 8_000])
|
||||
def test_make_random_grids( # noqa:WPS211
|
||||
def test_make_random_grids( # noqa:WPS211,WPS218
|
||||
self, db_session, city, make_address, make_restaurant, make_order, side_length,
|
||||
):
|
||||
"""With 100 random `Address` objects, a grid must have ...
|
||||
|
|
@ -228,5 +228,12 @@ class TestGridification:
|
|||
assert isinstance(result, db.Grid)
|
||||
assert 1 <= len(result.pixels) <= n_pixels_x * n_pixels_y
|
||||
|
||||
# Sanity checks for `Pixel.southwest` and `Pixel.northeast`.
|
||||
for pixel in result.pixels:
|
||||
assert abs(pixel.southwest.x - pixel.n_x * side_length) < 2
|
||||
assert abs(pixel.southwest.y - pixel.n_y * side_length) < 2
|
||||
assert abs(pixel.northeast.x - (pixel.n_x + 1) * side_length) < 2
|
||||
assert abs(pixel.northeast.y - (pixel.n_y + 1) * side_length) < 2
|
||||
|
||||
db_session.add(result)
|
||||
db_session.commit()
|
||||
|
|
|
|||
|
|
@ -87,3 +87,31 @@ class TestProperties:
|
|||
result = pixel.area
|
||||
|
||||
assert result == 1.0
|
||||
|
||||
def test_northeast(self, pixel, city):
|
||||
"""Test `Pixel.northeast` property."""
|
||||
result = pixel.northeast
|
||||
|
||||
assert abs(result.x - pixel.side_length) < 2
|
||||
assert abs(result.y - pixel.side_length) < 2
|
||||
|
||||
def test_northeast_is_cached(self, pixel):
|
||||
"""Test `Pixel.northeast` property."""
|
||||
result1 = pixel.northeast
|
||||
result2 = pixel.northeast
|
||||
|
||||
assert result1 is result2
|
||||
|
||||
def test_southwest(self, pixel, city):
|
||||
"""Test `Pixel.southwest` property."""
|
||||
result = pixel.southwest
|
||||
|
||||
assert abs(result.x) < 2
|
||||
assert abs(result.y) < 2
|
||||
|
||||
def test_southwest_is_cached(self, pixel):
|
||||
"""Test `Pixel.southwest` property."""
|
||||
result1 = pixel.southwest
|
||||
result2 = pixel.southwest
|
||||
|
||||
assert result1 is result2
|
||||
|
|
|
|||
|
|
@ -140,6 +140,13 @@ class TestProperties:
|
|||
|
||||
assert result == ZONE
|
||||
|
||||
def test_zone_details(self, location):
|
||||
"""Test `Location.zone_details` property."""
|
||||
result = location.zone_details
|
||||
|
||||
zone, band = result
|
||||
assert ZONE == f'{zone}{band}'
|
||||
|
||||
|
||||
class TestRelateTo:
|
||||
"""Test the `Location.relate_to()` method and the `.x` and `.y` properties."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue