|
1 | 1 | """Tests for the OpenSky Library.""" |
2 | | - |
| 2 | +import pytest |
| 3 | +from _pytest.python_api import approx |
3 | 4 |
|
4 | 5 | from python_opensky import ( |
| 6 | + BoundingBox, |
5 | 7 | OpenSky, |
6 | 8 | ) |
7 | 9 |
|
| 10 | +PRECISION = 0.01 |
| 11 | + |
8 | 12 |
|
9 | | -async def test_calculating_bounding_box() -> None: |
| 13 | +@pytest.mark.parametrize( |
| 14 | + ("latitude", "longitude", "radius", "bounding_box"), |
| 15 | + [ |
| 16 | + ( |
| 17 | + 0.0, |
| 18 | + 0.0, |
| 19 | + 111120, |
| 20 | + BoundingBox( |
| 21 | + min_latitude=-1.0, |
| 22 | + max_latitude=1.0, |
| 23 | + min_longitude=-1.0, |
| 24 | + max_longitude=1.0, |
| 25 | + ), |
| 26 | + ), |
| 27 | + ( |
| 28 | + 360.0, |
| 29 | + 0.0, |
| 30 | + 111120, |
| 31 | + BoundingBox( |
| 32 | + min_latitude=-1.0, |
| 33 | + max_latitude=1.0, |
| 34 | + min_longitude=-1.0, |
| 35 | + max_longitude=1.0, |
| 36 | + ), |
| 37 | + ), |
| 38 | + ( |
| 39 | + 0.0, |
| 40 | + 45.0, |
| 41 | + 111120, |
| 42 | + BoundingBox( |
| 43 | + min_latitude=-1.0, |
| 44 | + max_latitude=1.0, |
| 45 | + min_longitude=44.0, |
| 46 | + max_longitude=46.0, |
| 47 | + ), |
| 48 | + ), |
| 49 | + ( |
| 50 | + 0.0, |
| 51 | + 90.0, |
| 52 | + 111120, |
| 53 | + BoundingBox( |
| 54 | + min_latitude=-1.0, |
| 55 | + max_latitude=1.0, |
| 56 | + min_longitude=89.0, |
| 57 | + max_longitude=91.0, |
| 58 | + ), |
| 59 | + ), |
| 60 | + ], |
| 61 | +) |
| 62 | +async def test_calculating_bounding_box( |
| 63 | + latitude: float, |
| 64 | + longitude: float, |
| 65 | + radius: float, |
| 66 | + bounding_box: BoundingBox, |
| 67 | +) -> None: |
10 | 68 | """Test calculating bounding box.""" |
11 | | - bounding_box = OpenSky.get_bounding_box(0.0, 0.0, 25000) |
12 | | - assert bounding_box.min_latitude == -0.22609235747829648 |
13 | | - assert bounding_box.max_latitude == 0.22609235747829648 |
14 | | - assert bounding_box.min_longitude == -0.22457882102988042 |
15 | | - assert bounding_box.max_longitude == 0.22457882102988042 |
| 69 | + res_bounding_box = OpenSky.get_bounding_box(latitude, longitude, radius) |
| 70 | + assert res_bounding_box.min_latitude == approx(bounding_box.min_latitude, PRECISION) |
| 71 | + assert res_bounding_box.max_latitude == approx(bounding_box.max_latitude, PRECISION) |
| 72 | + assert res_bounding_box.min_longitude == approx( |
| 73 | + bounding_box.min_longitude, |
| 74 | + PRECISION, |
| 75 | + ) |
| 76 | + assert res_bounding_box.max_longitude == approx( |
| 77 | + bounding_box.max_longitude, |
| 78 | + PRECISION, |
| 79 | + ) |
16 | 80 |
|
17 | 81 |
|
18 | 82 | async def test_calculating_direction() -> None: |
|
0 commit comments