fixed comparison logic for waypoints and added tests to help catch issue in the future

This commit is contained in:
Blake Harnden 2020-02-19 21:21:21 -08:00
parent 471f40a0bd
commit 8572e153f4
2 changed files with 21 additions and 4 deletions

View file

@ -570,10 +570,10 @@ class WayPoint:
return not self == other
def __lt__(self, other: "WayPoint") -> bool:
result = self.time < other.time
if result:
result = self.nodenum < other.nodenum
return result
if self.time == other.time:
return self.nodenum < other.nodenum
else:
return self.time < other.time
class WayPointMobility(WirelessModel):

View file

@ -0,0 +1,17 @@
import pytest
from core.location.mobility import WayPoint
class TestMobility:
@pytest.mark.parametrize(
"wp1, wp2, expected",
[
(WayPoint(10.0, 1, [0, 0], 1.0), WayPoint(1.0, 2, [0, 0], 1.0), False),
(WayPoint(1.0, 1, [0, 0], 1.0), WayPoint(10.0, 2, [0, 0], 1.0), True),
(WayPoint(1.0, 1, [0, 0], 1.0), WayPoint(1.0, 2, [0, 0], 1.0), True),
(WayPoint(1.0, 2, [0, 0], 1.0), WayPoint(1.0, 1, [0, 0], 1.0), False),
],
)
def test_waypoint_lessthan(self, wp1, wp2, expected):
assert (wp1 < wp2) == expected