From 2dcf5c21337e4b12e56c3520828edfc062ce7338 Mon Sep 17 00:00:00 2001 From: Chris Jaekl Date: Mon, 24 Aug 2015 21:53:18 +0900 Subject: [PATCH] Fix issue with inconsistent formatting of "GPS off" buses. OC Transpo usually reports a bus with no GPS data as having a "GPS last read" time of (-1) minutes ago. But sometimes it reports it as (-2), for reasons that aren't clear (at least, not to me). The code was applying an "== (-1)" test in one spot, but a "< 0" test in another; inconsistency is not good, nor is repeating a conditional test unnecessarily. --- prod/net/jaekl/frank/Schedule.java | 4 ++-- test/net/jaekl/frank/ScheduleTest.java | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/prod/net/jaekl/frank/Schedule.java b/prod/net/jaekl/frank/Schedule.java index 8cc4f84..eb8cb2b 100644 --- a/prod/net/jaekl/frank/Schedule.java +++ b/prod/net/jaekl/frank/Schedule.java @@ -107,7 +107,7 @@ public class Schedule { Route route = stopInfo.getRoute(routeIdx); for (int tripIdx = 0; tripIdx < route.getNumTrips(); ++tripIdx) { Trip trip = route.getTrip(tripIdx); - boolean isGhost = ((-1) == trip.getAdjAge()); + boolean isGhost = (trip.getAdjAge() < 0); if (isGhost) { // GPS is off. This bus may not exist. pw.println(" "); @@ -125,7 +125,7 @@ public class Schedule { remainArray.append(trip.getAdjTime()); remainCount++; - if (trip.getAdjAge() < 0) { + if (isGhost) { pw.println(" " + trans(FrankBundle.GPS_OFF) + ""); } else { diff --git a/test/net/jaekl/frank/ScheduleTest.java b/test/net/jaekl/frank/ScheduleTest.java index 6c81937..1e1a517 100644 --- a/test/net/jaekl/frank/ScheduleTest.java +++ b/test/net/jaekl/frank/ScheduleTest.java @@ -136,6 +136,7 @@ public class ScheduleTest { trip = new TripMock(queryDate); trip.mock_setDest(HURDMAN); trip.mock_setAdjTime(37); + trip.mock_setAdjAge(-2); route.mock_addTrip(trip); rsm.mock_addRoute(route); @@ -176,8 +177,10 @@ public class ScheduleTest { Assert.assertTrue(actual.contains("" + HURDMAN + "")); Assert.assertTrue(actual.contains("17m")); + Assert.assertTrue(actual.contains("")); Assert.assertTrue(actual.contains("4")); Assert.assertTrue(actual.contains("" + HURDMAN + "")); Assert.assertTrue(actual.contains("37m")); + Assert.assertTrue(actual.contains("GPS off")); } } -- 2.39.2