Skip to content

Commit

Permalink
add test for reachability thresholds, opentripplanner#2148.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwigway committed Oct 15, 2015
1 parent 5871d8e commit 040258d
Showing 1 changed file with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.opentripplanner.profile;

import junit.framework.TestCase;
import org.junit.Test;
import org.opentripplanner.graph_builder.module.FakeGraph;
import org.opentripplanner.routing.graph.Graph;

/**
* Test the propagated times store.
*/
public class PropagatedTimesStoreTest extends TestCase {
/**
* Test that changing the reachability threshold works (i.e. averages are computed properly when destinations are
* only reachable part of the time).
*/
@Test
public static void testReachability () throws Exception {
ProfileRequest pr = new ProfileRequest();
// old default: no restrictions o
pr.reachabilityThreshold = 0;

Graph g = new Graph();

PropagatedTimesStore pts = new PropagatedTimesStore(g, pr, 1);
// accessible one-third of the time
int[][] times = new int[][] {
new int[] { 1 },
new int[] { RaptorWorker.UNREACHED },
new int[] { RaptorWorker.UNREACHED }
};

pts.setFromArray(times, PropagatedTimesStore.ConfidenceCalculationMethod.MIN_MAX);

// it is reachable at least 0% of the time
assertEquals(1, pts.avgs[0]);

pr.reachabilityThreshold = 0.5f;
pts = new PropagatedTimesStore(g, pr, 1);
pts.setFromArray(times, PropagatedTimesStore.ConfidenceCalculationMethod.MIN_MAX);

// it is not reachable 50% of the time
assertEquals(RaptorWorker.UNREACHED, pts.avgs[0]);
}
}

0 comments on commit 040258d

Please sign in to comment.