]> jaekl.net Git - frank.git/commitdiff
Fix issue with inconsistent formatting of "GPS off" buses.
authorChris Jaekl <chris@ringo.jaekl.net>
Mon, 24 Aug 2015 12:53:18 +0000 (21:53 +0900)
committerChris Jaekl <chris@ringo.jaekl.net>
Mon, 24 Aug 2015 12:53:18 +0000 (21:53 +0900)
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
test/net/jaekl/frank/ScheduleTest.java

index 8cc4f846124a5a1b628c0d011e3f6069d80ff5d2..eb8cb2bce26cee168d800d2baef13770ff96c580 100644 (file)
@@ -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("    <TR CLASS=\"ghost\">");
@@ -125,7 +125,7 @@ public class Schedule {
                                remainArray.append(trip.getAdjTime());
                                remainCount++;
                                
-                               if (trip.getAdjAge() < 0) {
+                               if (isGhost) {
                                        pw.println("      <TD>" + trans(FrankBundle.GPS_OFF) + "</TD>");
                                }
                                else {
index 6c81937e720ef9f8f76a2530e88e356a8289e5f1..1e1a5176bb200a983ac3b5cc8dc50a801b3c13f4 100644 (file)
@@ -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("<TD>" + HURDMAN + "</TD>"));
                Assert.assertTrue(actual.contains("<TD><SPAN ID=\"in_2\">17m</SPAN></TD>"));
                
+               Assert.assertTrue(actual.contains("<TR CLASS=\"ghost\">"));
                Assert.assertTrue(actual.contains("<TD>4</TD>"));
                Assert.assertTrue(actual.contains("<TD>" + HURDMAN + "</TD>"));
                Assert.assertTrue(actual.contains("<TD><SPAN ID=\"in_3\">37m</SPAN></TD>"));
+               Assert.assertTrue(actual.contains("<TD>GPS off</TD>"));
        }
 }