Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Jan 21, 2024
1 parent 1182afd commit 0e529c7
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public LuceneIndex(TransitService transitService) {
stopCluster.coordinate().lat(),
stopCluster.coordinate().lon(),
stopCluster.modes(),
stopCluster.agencies()
stopCluster.agencyIds()
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ record LuceneStopCluster(
String name,
StopCluster.Coordinate coordinate,
Collection<String> modes,
Collection<String> agencies
Collection<String> agencyIds
) {}
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,9 @@ Iterable<LuceneStopCluster> generateStopClusters(

LuceneStopCluster map(StopLocationsGroup g) {
var modes = transitService.getModesOfStopLocationsGroup(g).stream().map(Enum::name).toList();
var agencies = g
.getChildStops()
var agencies = transitService
.getAgenciesForStopLocationsGroup(g)
.stream()
.flatMap(s -> transitService.getAgenciesForStopLocation(s).stream())
.distinct()
.map(s -> s.getId().toString())
.toList();
return new LuceneStopCluster(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,16 @@ public List<Agency> getAgenciesForStopLocation(StopLocation stop) {
return getRoutesForStop(stop).stream().map(Route::getAgency).distinct().toList();
}

@Override
public List<Agency> getAgenciesForStopLocationsGroup(StopLocationsGroup group) {
return group
.getChildStops()
.stream()
.flatMap(sl -> getAgenciesForStopLocation(sl).stream())
.distinct()
.toList();
}

/**
* For each pattern visiting this {@link StopLocation} return its {@link TransitMode}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ List<TripTimeOnDate> stopTimesForPatternAtStop(
*/
List<TransitMode> getModesOfStopLocation(StopLocation stop);

/**
* Iterates over all child stops, the routes that visit this stop and return a de-duplicated list
* of their agencies.
*/
List<Agency> getAgenciesForStopLocationsGroup(StopLocationsGroup group);

/**
* Iterates over all routes that visit this stop location and return a de-duplicated list
* of their agencies.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ static void setup() {
.build();

var transitModel = new TransitModel(stopModel, new Deduplicator());
transitModel.addTripPattern(RAIL_PATTERN.getId(), RAIL_PATTERN);
transitModel.index();

service =
new DefaultTransitService(transitModel) {
Expand Down Expand Up @@ -74,4 +76,11 @@ void stationModes() {
var modes = service.getModesOfStopLocationsGroup(STATION);
assertEquals(List.of(RAIL, FERRY, TRAM), modes);
}

@Test
void stopAgencies() {
var stop = RAIL_PATTERN.getStopPattern().getStop(0);
var agencies = service.getAgenciesForStopLocation(stop);
assertEquals("[Agency{F:A1 Agency Test}]", agencies.toString());
}
}

0 comments on commit 0e529c7

Please sign in to comment.