Skip to content

Commit

Permalink
add test, fix linter
Browse files Browse the repository at this point in the history
  • Loading branch information
sjev committed Sep 3, 2024
1 parent a428c5d commit 6758ead
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/roxbot/pathgen/classes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import List, Tuple, Dict, Any
from dataclasses import dataclass, field
from dataclasses import dataclass
from rox_vectors import Vector, Line
from roxbot.gps.converters import latlon_to_enu, enu_to_latlon
from roxbot.gps.converters import enu_to_latlon

# Assuming GPS_REF is defined somewhere in the module
GPS_REF: Tuple[float, float] = (0.0, 0.0) # Example (latitude, longitude)
Expand All @@ -20,7 +20,7 @@ class Waypoint(Vector):

def __init__(self, xy: Tuple[float, float]) -> None:
super().__init__(xy[0], xy[1])
self.actions: List[Action] = field(default_factory=list)
self.actions: List[Action] = []

def to_latlon(self) -> Tuple[float, float]:
"""Convert to latitude and longitude."""
Expand Down
28 changes: 28 additions & 0 deletions tests/test_pathgen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import pytest
from rox_vectors import Vector
from roxbot.pathgen.generators import generate_square_path


def test_generate_square_path() -> None:
# Test case 1: Simple square
a = Vector(0, 0)
b = Vector(3, 0)
c = Vector(0, 3)

waypoints = generate_square_path(a, b, c)

assert len(waypoints) == 4, "Should return 4 waypoints"
assert waypoints[0] == a, "First waypoint should be A"
assert waypoints[1] == b, "Second waypoint should be B"
assert waypoints[3] == c, "Last waypoint should be C"

# Check if X forms a square
ab = waypoints[1] - waypoints[0]
bx = waypoints[2] - waypoints[1]
xc = waypoints[3] - waypoints[2]
ca = waypoints[0] - waypoints[3]

assert abs(ab) == pytest.approx(abs(bx)), "AB and BX should have equal length"
assert abs(bx) == pytest.approx(abs(xc)), "BX and XC should have equal length"
assert abs(xc) == pytest.approx(abs(ca)), "XC and CA should have equal length"
assert abs(ab.dot(bx)) < 1e-10, "AB and BX should be perpendicular"

0 comments on commit 6758ead

Please sign in to comment.