1
+ /*
2
+ * Licensed to GraphHopper GmbH under one or more contributor
3
+ * license agreements. See the NOTICE file distributed with this work for
4
+ * additional information regarding copyright ownership.
5
+ *
6
+ * GraphHopper GmbH licenses this file to you under the Apache License,
7
+ * Version 2.0 (the "License"); you may not use this file except in
8
+ * compliance with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ package com .graphhopper .routing .util ;
20
+
21
+ import com .graphhopper .reader .ReaderWay ;
22
+ import org .junit .jupiter .api .Test ;
23
+
24
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
25
+
26
+ class FerrySpeedCalculatorTest {
27
+
28
+ @ Test
29
+ void testSpeed () {
30
+ double speedFactor = 2 ;
31
+ double maxSpeed = 55 ;
32
+ double longSpeed = 30 ;
33
+ double shortSpeed = 20 ;
34
+ double unknownSpeed = 5 ;
35
+ FerrySpeedCalculator c = new FerrySpeedCalculator (speedFactor , maxSpeed , longSpeed , shortSpeed , unknownSpeed );
36
+
37
+ // no distance -> speed only depends on duration (distinguish between missing/short/long duration)
38
+ checkSpeed (c , null , null , unknownSpeed );
39
+ checkSpeed (c , "0" , null , unknownSpeed );
40
+ checkSpeed (c , "1800" , null , shortSpeed );
41
+ checkSpeed (c , "7200" , null , longSpeed );
42
+ // no duration -> speed depends on distance
43
+ checkSpeed (c , null , 100.0 , speedFactor / 2 );
44
+ checkSpeed (c , "0" , 100.0 , speedFactor / 2 );
45
+ checkSpeed (c , null , 1000.0 , unknownSpeed );
46
+ checkSpeed (c , "0" , 1000.0 , unknownSpeed );
47
+
48
+ // valid
49
+ checkSpeed (c , "3600" , 30000.0 , Math .round (30 / 1.4 ));
50
+ checkSpeed (c , "7200" , 30000.0 , Math .round (15 / 1.4 ));
51
+ // above max (capped to max)
52
+ checkSpeed (c , "3600" , 90000.0 , maxSpeed );
53
+ // below smallest storable non-zero value
54
+ checkSpeed (c , "7200" , 1000.0 , speedFactor / 2 );
55
+
56
+ // suspicious slow speed (still depends on distance)
57
+ checkSpeed (c , "180000" , 100.0 , speedFactor / 2 );
58
+ checkSpeed (c , "1800000" , 1000.0 , unknownSpeed );
59
+ }
60
+
61
+ private void checkSpeed (FerrySpeedCalculator calc , String duration , Double distance , double expected ) {
62
+ ReaderWay way = new ReaderWay (0L );
63
+ if (duration != null )
64
+ way .setTag ("duration:seconds" , duration );
65
+ if (distance != null )
66
+ way .setTag ("estimated_distance" , distance );
67
+ assertEquals (expected , calc .getSpeed (way ));
68
+ }
69
+
70
+ // ORS-GH MOD START
71
+ @ Test
72
+ void testMaxSpeedTag () {
73
+ double speedFactor = 2 ;
74
+ double maxSpeed = 55 ;
75
+ double longSpeed = 30 ;
76
+ double shortSpeed = 20 ;
77
+ double unknownSpeed = 5 ;
78
+ FerrySpeedCalculator c = new FerrySpeedCalculator (speedFactor , maxSpeed , longSpeed , shortSpeed , unknownSpeed );
79
+
80
+ ReaderWay way = new ReaderWay (0L );
81
+ way .setTag ("maxspeed" , "14" );
82
+ assertEquals (10 , c .getSpeed (way ));
83
+ }
84
+ // ORS-GH MOD END
85
+ }
0 commit comments