sw7 detect laps from coordinates
This commit is contained in:
1 parent
5d0aa9c876
commit
45921bfe17
14 files changed
+1121
No files matched your search
@@ -0,0 +1,57 @@
|
||||
import pytest
|
||||
|
||||
from lap_detection.api import Collection, Feature, Geometry, Coordinate
|
||||
import lap_detection.main as main
|
||||
|
||||
|
||||
# arrange
|
||||
@pytest.fixture
|
||||
def sample_collection():
|
||||
return Collection(
|
||||
"FeatureCollection",
|
||||
[
|
||||
Feature(
|
||||
"Feature",
|
||||
{},
|
||||
Geometry([[123.456, 654.321], [987.654, 101.010]], "LineString"),
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
# arrange
|
||||
@pytest.mark.parametrize(
|
||||
"path,expected_laps",
|
||||
[
|
||||
("src/lap_detection/data/usecase1.json", 3),
|
||||
("src/lap_detection/data/usecase2.json", 3),
|
||||
("src/lap_detection/data/usecase3.json", 0),
|
||||
("src/lap_detection/data/usecase4.json", 2),
|
||||
],
|
||||
)
|
||||
def test_main(path, expected_laps, capsys):
|
||||
# act
|
||||
main.main(path)
|
||||
|
||||
# assert
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out.strip() == f"Anzahl Runden: {expected_laps}"
|
||||
|
||||
|
||||
def test_check_invalid_path():
|
||||
# assert
|
||||
with pytest.raises(FileNotFoundError, match="invalid_path.json does not exist"):
|
||||
# act
|
||||
main._check_path("invalid_path.json")
|
||||
|
||||
|
||||
def test_build_coordinates(sample_collection):
|
||||
# act
|
||||
coordinates = main._build_coordinates(sample_collection)
|
||||
|
||||
# assert
|
||||
assert isinstance(coordinates, list)
|
||||
assert len(coordinates) == 2
|
||||
assert isinstance(coordinates[1], Coordinate)
|
||||
assert coordinates[1].lon == 987.654
|
||||
assert coordinates[1].lat == 101.010
|
||||
Reference in new issue
Block a user