11package  org .opentripplanner .routing .algorithm .raptoradapter .transit .mappers ;
22
33import  static  org .junit .jupiter .api .Assertions .assertEquals ;
4+ import  static  org .junit .jupiter .api .Assertions .assertTrue ;
45
6+ import  java .time .Duration ;
7+ import  java .time .ZonedDateTime ;
58import  java .util .List ;
9+ import  org .junit .jupiter .api .Test ;
610import  org .junit .jupiter .params .ParameterizedTest ;
711import  org .junit .jupiter .params .provider .Arguments ;
812import  org .junit .jupiter .params .provider .MethodSource ;
13+ import  org .opentripplanner .raptor ._data .transit .TestAccessEgress ;
14+ import  org .opentripplanner .raptor ._data .transit .TestTripSchedule ;
15+ import  org .opentripplanner .raptor .api .model .RaptorAccessEgress ;
16+ import  org .opentripplanner .raptor .api .request .RaptorRequest ;
17+ import  org .opentripplanner .routing .api .request .PassThroughPoint ;
18+ import  org .opentripplanner .routing .api .request .RouteRequest ;
919import  org .opentripplanner .routing .api .request .framework .CostLinearFunction ;
20+ import  org .opentripplanner .transit .model ._data .TransitModelForTest ;
21+ import  org .opentripplanner .transit .model .site .StopLocation ;
1022
1123class  RaptorRequestMapperTest  {
1224
25+   private  static  final  TransitModelForTest  TEST_MODEL  = TransitModelForTest .of ();
26+   private  static  final  StopLocation  STOP_A  = TEST_MODEL .stop ("Stop:A" ).build ();
27+   private  static  final  List <RaptorAccessEgress > ACCESS  = List .of (TestAccessEgress .walk (12 , 45 ));
28+   private  static  final  List <RaptorAccessEgress > EGRESS  = List .of (TestAccessEgress .walk (144 , 54 ));
29+   private  static  final  Duration  D0s  = Duration .ofSeconds (0 );
30+ 
1331  private  static  final  CostLinearFunction  R1  = CostLinearFunction .of ("50 + 1.0x" );
1432  private  static  final  CostLinearFunction  R2  = CostLinearFunction .of ("0 + 1.5x" );
1533  private  static  final  CostLinearFunction  R3  = CostLinearFunction .of ("30 + 2.0x" );
@@ -33,4 +51,47 @@ void mapRelaxCost(CostLinearFunction input, int cost, int expected) {
3351    var  calcCost  = RaptorRequestMapper .mapRelaxCost (input );
3452    assertEquals (expected , calcCost .relax (cost ));
3553  }
54+ 
55+   @ Test 
56+   void  testPassThroughPoints () {
57+     var  req  = new  RouteRequest ();
58+ 
59+     req .setPassThroughPoints (List .of (new  PassThroughPoint (List .of (STOP_A ), "Via A" )));
60+ 
61+     var  result  = map (req );
62+ 
63+     assertTrue (result .multiCriteria ().hasPassThroughPoints ());
64+     assertEquals (
65+       "[(Via A, stops: "  + STOP_A .getIndex () + ")]" ,
66+       result .multiCriteria ().passThroughPoints ().toString ()
67+     );
68+   }
69+ 
70+   @ Test 
71+   void  testPassThroughPointsTurnTransitGroupPriorityOff () {
72+     var  req  = new  RouteRequest ();
73+ 
74+     // Set pass-through and relax transit-group-priority 
75+     req .setPassThroughPoints (List .of (new  PassThroughPoint (List .of (STOP_A ), "Via A" )));
76+     req .withPreferences (p  ->
77+       p .withTransit (t  -> t .withRelaxTransitGroupPriority (CostLinearFunction .of ("30m + 1.2t" )))
78+     );
79+ 
80+     var  result  = map (req );
81+ 
82+     //  transit-group-priority CANNOT be used with pass-through and is turned off... 
83+     assertTrue (result .multiCriteria ().transitPriorityCalculator ().isEmpty ());
84+   }
85+ 
86+   private  static  RaptorRequest <TestTripSchedule > map (RouteRequest  request ) {
87+     return  RaptorRequestMapper .mapRequest (
88+       request ,
89+       ZonedDateTime .now (),
90+       false ,
91+       ACCESS ,
92+       EGRESS ,
93+       D0s ,
94+       null 
95+     );
96+   }
3697}
0 commit comments