18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-20 19:44:58 +01:00

Merge remote-tracking branch 'origin/master' into test/parser-utilities-ladderlogic-coverage

This commit is contained in:
jerrrrycho
2026-11-11 21:44:30 +01:00
252 changed files with 109115 additions and 12956 deletions

View File

@@ -21,6 +21,17 @@ add_executable(${UNIT_TESTS_NAME}
invariants.cpp
figures.cpp
engine_stubs.cpp
editor_stubs.cpp
# the geometry of the lines the track editor designs, standing on its own
"${CMAKE_SOURCE_DIR}/editor/editorAlignment.cpp"
# and the heights of the tracks laid
"${CMAKE_SOURCE_DIR}/editor/editorGroundFollow.cpp"
"${CMAKE_SOURCE_DIR}/editor/editorProfile.cpp"
# and the switches laid into the curves
"${CMAKE_SOURCE_DIR}/editor/editorSwitchCurve.cpp"
# and the fouling points of the switches, widened in the curves as the gauge is
"${CMAKE_SOURCE_DIR}/editor/editorGauge.cpp"
"${CMAKE_SOURCE_DIR}/editor/editorFouling.cpp"
${UNIT_TEST_CASES})
# the core library brings the game's build settings along

View File

@@ -0,0 +1,420 @@
# the last stretch of the ground of a line as the fit onto the terrain model has it: chainage, height, tolerance, reach (all m).
# A viaduct at 80..120 with no model on it, the line held over the track below at 89..100; a level field past it up to the loose end
0.13 80.0098 0.15 0.15
1.11 80.0015 0.15 0.15
2.08 80.0439 0.15 0.15
3.05 80.0147 0.15 0.15
4.03 80.0276 0.15 0.15
5 80.0198 0.15 0.15
5.98 80.0325 0.15 0.15
6.95 80.0354 0.15 0.15
7.93 80.037 0.15 0.15
8.78 80.0731 0.15 0.15
9.63 80.0286 0.15 0.15
10.24 80.0603 0.15 0.15
10.85 80.0809 0.15 0.15
11.72 80.058 0.15 0.15
12.59 80.0617 0.15 0.15
13.46 80.0658 0.15 0.15
14.37 80.0807 0.15 0.15
15.28 80.106 0.15 0.15
16.19 80.0841 0.15 0.15
17.11 80.1022 0.15 0.15
18.02 80.0831 0.15 0.15
18.93 80.1051 0.15 0.15
19.84 80.1197 0.15 0.15
20.76 80.1041 0.15 0.15
21.68 80.1111 0.15 0.15
22.6 80.1129 0.15 0.15
23.52 80.1422 0.15 0.15
24.44 80.109 0.15 0.15
25.36 80.0932 0.15 0.15
26.28 80.1164 0.15 0.15
27.2 80.1181 0.15 0.15
28.12 80.135 0.15 0.15
29.03 80.1202 0.15 0.15
29.95 80.1463 0.15 0.15
30.87 80.1427 0.15 0.15
31.87 80.168 0.15 0.15
32.87 80.1317 0.15 0.15
33.87 80.1506 0.15 0.15
34.87 80.142 0.15 0.15
35.87 80.1834 0.15 0.15
36.87 80.1599 0.15 0.15
37.87 80.1599 0.15 0.15
38.87 80.1644 0.15 0.15
39.87 80.1772 0.15 0.15
40.87 80.1904 0.15 0.15
41.86 80.1682 0.15 0.15
42.85 80.1858 0.15 0.15
43.84 80.158 0.15 0.15
44.83 80.1605 0.15 0.15
45.82 80.1783 0.15 0.15
46.81 80.2093 0.15 0.15
47.8 80.1863 0.15 0.15
48.78 80.2119 0.15 0.15
49.77 80.1858 0.15 0.15
50.76 80.2059 0.15 0.15
51.75 80.2138 0.15 0.15
52.74 80.2015 0.15 0.15
53.73 80.2047 0.15 0.15
54.72 80.2141 0.15 0.15
55.71 80.1827 0.15 0.15
56.7 80.2171 0.15 0.15
57.69 80.1903 0.15 0.15
58.67 80.2235 0.15 0.15
59.66 80.1961 0.15 0.15
60.65 80.1834 0.15 0.15
61.64 80.1877 0.15 0.15
62.63 80.212 0.15 0.15
63.62 80.2247 0.15 0.15
64.61 80.2446 0.15 0.15
65.6 80.195 0.15 0.15
66.59 80.2567 0.15 0.15
67.58 80.2717 0.15 0.15
68.56 80.258 0.15 0.15
69.55 80.271 0.15 0.15
70.54 80.2573 0.15 0.15
71.53 80.2506 0.15 0.15
72.52 80.2993 0.15 0.15
73.51 80.2726 0.15 0.15
74.5 80.2649 0.15 0.15
75.49 80.2581 0.15 0.15
76.48 80.2659 0.15 0.15
77.47 80.2806 0.15 0.15
78.45 79.8139 0.15 0.15
79.44 79.2243 0.15 0.15
80.43 nan 0.15 0.15
81.41 nan 0.15 0.15
82.4 nan 0.15 0.15
83.39 nan 0.15 0.15
84.37 nan 0.15 0.15
85.36 nan 0.15 0.15
86.34 nan 0.15 0.15
87.33 nan 0.15 0.15
88.33 nan 0.15 0.15
89.32 nan 0.15 0.15
89.32 79.1589 0.02 30
90.31 nan 0.15 0.15
90.31 79.16 0.02 30
91.3 nan 0.15 0.15
91.3 79.1611 0.02 30
92.3 nan 0.15 0.15
92.3 79.1622 0.02 30
93.29 nan 0.15 0.15
93.29 79.1634 0.02 30
94.28 nan 0.15 0.15
94.28 79.1645 0.02 30
95.27 nan 0.15 0.15
95.27 79.1656 0.02 30
96.27 nan 0.15 0.15
96.27 79.1667 0.02 30
97.26 nan 0.15 0.15
97.26 79.1678 0.02 30
98.25 nan 0.15 0.15
98.25 79.1689 0.02 30
99.24 nan 0.15 0.15
99.24 79.17 0.02 30
100.23 nan 0.15 0.15
100.23 79.1711 0.02 30
101.23 nan 0.15 0.15
102.22 nan 0.15 0.15
103.21 nan 0.15 0.15
104.2 nan 0.15 0.15
105.19 nan 0.15 0.15
106.19 nan 0.15 0.15
107.11 nan 0.15 0.15
108.03 nan 0.15 0.15
108.95 nan 0.15 0.15
109.87 nan 0.15 0.15
110.79 nan 0.15 0.15
111.05 nan 0.15 0.15
111.32 nan 0.15 0.15
111.48 nan 0.15 0.15
111.63 nan 0.15 0.15
112.19 nan 0.15 0.15
112.74 nan 0.15 0.15
113.2 nan 0.15 0.15
113.66 nan 0.15 0.15
114.5 nan 0.15 0.15
115.35 nan 0.15 0.15
115.97 nan 0.15 0.15
116.59 nan 0.15 0.15
116.72 nan 0.15 0.15
116.86 nan 0.15 0.15
117.17 nan 0.15 0.15
117.48 nan 0.15 0.15
118.16 nan 0.15 0.15
118.85 nan 0.15 0.15
119.54 nan 0.15 0.15
120.11 79.5999 0.15 0.15
120.67 79.8142 0.15 0.15
120.97 79.9073 0.15 0.15
121.26 80.0019 0.15 0.15
121.43 80.0558 0.15 0.15
121.59 80.1101 0.15 0.15
122.55 80.2962 0.15 0.15
123.5 80.3937 0.15 0.15
124.46 80.3862 0.15 0.15
125.42 80.4118 0.15 0.15
126.38 80.409 0.15 0.15
127.33 80.3708 0.15 0.15
128.29 80.3634 0.15 0.15
129.22 80.3619 0.15 0.15
130.15 80.345 0.15 0.15
131.09 80.355 0.15 0.15
132.02 80.3542 0.15 0.15
132.95 80.3499 0.15 0.15
133.45 80.345 0.15 0.15
133.96 80.3526 0.15 0.15
134.75 80.2781 0.15 0.15
135.55 80.2671 0.15 0.15
136.35 80.2619 0.15 0.15
137.29 80.3038 0.15 0.15
138.24 80.3516 0.15 0.15
139.18 80.3255 0.15 0.15
140.13 80.3078 0.15 0.15
141.07 80.3296 0.15 0.15
142.01 80.3411 0.15 0.15
142.96 80.3127 0.15 0.15
143.9 80.3474 0.15 0.15
144.85 80.335 0.15 0.15
145.79 80.3042 0.15 0.15
146.76 80.2855 0.15 0.15
147.73 80.3033 0.15 0.15
148.71 80.3381 0.15 0.15
149.68 80.3272 0.15 0.15
150.65 80.3059 0.15 0.15
151.62 80.2809 0.15 0.15
152.59 80.2728 0.15 0.15
153.57 80.2876 0.15 0.15
154.54 80.1599 0.15 0.15
155.51 78.8547 0.15 0.15
156.48 nan 0.15 0.15
157.46 nan 0.15 0.15
158.43 nan 0.15 0.15
159.4 nan 0.15 0.15
160.37 nan 0.15 0.15
161.34 nan 0.15 0.15
161.56 79.2239 0.15 0.15
161.78 79.5581 0.15 0.15
162.54 80.1315 0.15 0.15
163.29 80.2649 0.15 0.15
164.29 80.2722 0.15 0.15
165.28 80.2736 0.15 0.15
166.28 80.2655 0.15 0.15
167.28 80.2369 0.15 0.15
168.28 80.2283 0.15 0.15
169.27 80.2201 0.15 0.15
170.27 80.2191 0.15 0.15
171.27 80.2315 0.15 0.15
172.27 80.2518 0.15 0.15
173.27 80.2673 0.15 0.15
174.26 80.2422 0.15 0.15
175.21 80.2376 0.15 0.15
176.16 80.236 0.15 0.15
177.11 80.2071 0.15 0.15
178.05 80.2064 0.15 0.15
179 80.2092 0.15 0.15
179.95 80.2443 0.15 0.15
180.89 80.2233 0.15 0.15
181.84 80.2156 0.15 0.15
182.79 80.2071 0.15 0.15
183.74 80.1883 0.15 0.15
184.65 80.2062 0.15 0.15
185.56 80.2256 0.15 0.15
186.47 80.2001 0.15 0.15
187.38 80.1912 0.15 0.15
188.29 80.1444 0.15 0.15
189.2 80.1761 0.15 0.15
190.11 80.1691 0.15 0.15
191.02 80.1941 0.15 0.15
191.99 80.1732 0.15 0.15
192.96 80.1946 0.15 0.15
193.93 80.2007 0.15 0.15
194.9 80.1481 0.15 0.15
195.87 80.1769 0.15 0.15
196.85 80.1768 0.15 0.15
197.82 80.1736 0.15 0.15
198.79 80.1739 0.15 0.15
199.76 80.1801 0.15 0.15
200.73 80.1761 0.15 0.15
201.7 80.1857 0.15 0.15
202.54 80.1641 0.15 0.15
203.37 80.1818 0.15 0.15
204.21 80.1742 0.15 0.15
205.05 80.1618 0.15 0.15
205.81 80.1514 0.15 0.15
206.58 80.17 0.15 0.15
207.35 80.191 0.15 0.15
208.11 80.1837 0.15 0.15
209.08 80.152 0.15 0.15
210.05 80.1375 0.15 0.15
211.02 80.1722 0.15 0.15
211.74 80.1588 0.15 0.15
212.45 80.1509 0.15 0.15
213.17 80.14 0.15 0.15
213.55 80.1407 0.15 0.15
213.93 80.1426 0.15 0.15
214.89 80.1492 0.15 0.15
215.85 80.1584 0.15 0.15
216.8 80.1439 0.15 0.15
217.76 80.1628 0.15 0.15
218.72 80.1517 0.15 0.15
219.68 80.1559 0.15 0.15
220.64 80.1394 0.15 0.15
221.6 80.1287 0.15 0.15
222.44 80.1592 0.15 0.15
223.27 80.1546 0.15 0.15
224.11 80.1672 0.15 0.15
224.94 80.1622 0.15 0.15
225.77 80.1195 0.15 0.15
226.61 80.1597 0.15 0.15
227.59 80.1549 0.15 0.15
228.58 80.1613 0.15 0.15
229.56 80.1691 0.15 0.15
230.55 80.1578 0.15 0.15
231.53 80.1294 0.15 0.15
232.52 80.1273 0.15 0.15
233.5 80.127 0.15 0.15
234.49 80.1099 0.15 0.15
235.19 80.1399 0.15 0.15
235.9 80.108 0.15 0.15
236.6 80.1275 0.15 0.15
237.17 80.1106 0.15 0.15
237.74 80.1461 0.15 0.15
238.69 80.1346 0.15 0.15
239.64 80.1183 0.15 0.15
240.58 80.1181 0.15 0.15
241.53 80.1248 0.15 0.15
242.48 80.15 0.15 0.15
243.43 80.1453 0.15 0.15
244.37 80.101 0.15 0.15
245.31 80.1168 0.15 0.15
246.25 80.1505 0.15 0.15
247.2 80.1199 0.15 0.15
248.14 80.147 0.15 0.15
249.08 80.1376 0.15 0.15
249.29 80.145 0.15 0.15
249.49 80.1453 0.15 0.15
250.42 80.1298 0.15 0.15
251.36 80.1248 0.15 0.15
252.29 80.1278 0.15 0.15
253.23 80.1393 0.15 0.15
254.16 80.1187 0.15 0.15
255.09 80.1332 0.15 0.15
256.03 80.1087 0.15 0.15
256.96 80.1142 0.15 0.15
257.89 80.1294 0.15 0.15
258.83 80.1382 0.15 0.15
259.76 80.1507 0.15 0.15
260.71 80.132 0.15 0.15
261.65 80.1527 0.15 0.15
262.6 80.1261 0.15 0.15
263.54 80.1385 0.15 0.15
264.49 80.1426 0.15 0.15
265.49 80.1432 0.15 0.15
266.49 80.1116 0.15 0.15
267.49 80.1318 0.15 0.15
268.49 80.1014 0.15 0.15
269.49 80.0957 0.15 0.15
270.49 80.117 0.15 0.15
271.49 80.138 0.15 0.15
272.49 80.1022 0.15 0.15
273.49 80.1407 0.15 0.15
274.49 80.1295 0.15 0.15
275.49 80.0953 0.15 0.15
276.49 80.0998 0.15 0.15
277.49 80.121 0.15 0.15
278.49 80.1027 0.15 0.15
279.49 80.1303 0.15 0.15
280.48 80.1142 0.15 0.15
281.48 80.122 0.15 0.15
282.47 80.1135 0.15 0.15
283.46 80.1005 0.15 0.15
284.45 80.0902 0.15 0.15
285.45 80.0823 0.15 0.15
286.44 80.0986 0.15 0.15
287.43 80.0902 0.15 0.15
288.43 80.0673 0.15 0.15
289.42 80.098 0.15 0.15
290.41 80.1072 0.15 0.15
291.41 80.0789 0.15 0.15
292.4 80.0933 0.15 0.15
293.39 80.0876 0.15 0.15
294.39 80.0735 0.15 0.15
295.38 80.0595 0.15 0.15
296.37 80.0521 0.15 0.15
297.37 80.0726 0.15 0.15
298.36 80.0685 0.15 0.15
299.35 80.093 0.15 0.15
300.35 80.0585 0.15 0.15
301.34 80.0404 0.15 0.15
302.33 80.059 0.15 0.15
303.33 80.0668 0.15 0.15
304.32 80.0617 0.15 0.15
305.31 80.0651 0.15 0.15
306.31 80.0445 0.15 0.15
307.3 80.0336 0.15 0.15
308.3 80.0458 0.15 0.15
309.29 80.0393 0.15 0.15
310.28 80.0142 0.15 0.15
311.28 80.0282 0.15 0.15
312.27 80.0181 0.15 0.15
313.26 79.995 0.15 0.15
314.25 80.0225 0.15 0.15
315.25 79.996 0.15 0.15
316.24 79.9981 0.15 0.15
317.23 80.0058 0.15 0.15
318.23 80.0087 0.15 0.15
319.22 79.9911 0.15 0.15
320.21 79.9839 0.15 0.15
321.21 80.0101 0.15 0.15
322.21 79.9765 0.15 0.15
323.21 79.9878 0.15 0.15
324.2 79.9784 0.15 0.15
325.2 80 0.15 0.15
326.2 79.9763 0.15 0.15
327.19 79.9631 0.15 0.15
328.19 79.98 0.15 0.15
329.19 79.9492 0.15 0.15
330.19 79.926 0.15 0.15
331.18 79.9357 0.15 0.15
332.18 79.9425 0.15 0.15
333.18 79.9195 0.15 0.15
334.17 79.9519 0.15 0.15
335.17 79.9423 0.15 0.15
336.17 79.9189 0.15 0.15
337.16 79.9041 0.15 0.15
338.16 79.9282 0.15 0.15
339.16 79.9244 0.15 0.15
340.16 79.9136 0.15 0.15
341.15 79.9174 0.15 0.15
342.15 79.9046 0.15 0.15
343.15 79.9095 0.15 0.15
344.14 79.8998 0.15 0.15
345.14 79.9607 0.15 0.15
346.14 79.9022 0.15 0.15
347.14 79.9167 0.15 0.15
348.13 79.904 0.15 0.15
349.13 79.9172 0.15 0.15
350.13 79.8972 0.15 0.15
351.12 79.9275 0.15 0.15
352.12 79.931 0.15 0.15
353.12 79.8963 0.15 0.15
354.12 79.8947 0.15 0.15
355.11 79.9034 0.15 0.15
356.11 79.9246 0.15 0.15
357.11 79.8982 0.15 0.15
358.1 79.9215 0.15 0.15
359.1 79.9138 0.15 0.15
360.1 79.9222 0.15 0.15
361.1 79.9026 0.15 0.15
362.09 79.9095 0.15 0.15
363.09 79.9326 0.15 0.15
364.09 79.8904 0.15 0.15
365.08 79.9064 0.15 0.15
366.08 79.9456 0.15 0.15
367.08 79.9383 0.15 0.15
368.08 79.935 0.15 0.15
369.07 79.9335 0.15 0.15

View File

@@ -0,0 +1,358 @@
# the tracks of z93_1 .. editor_track_321 on lk357 after the grade lines were shared, as profiledump writes them: S chainage height grade track model, P the design laid anew, C the ends joined, Z the switches, L the speed and the norms
S 0.0000 62.7964 -0.0026
S 0.9007 62.7940 -0.0026
S 1.8014 62.7917 -0.0026
S 2.7021 62.7893 -0.0026
S 3.6028 62.7869 -0.0026
S 4.5035 62.7846 -0.0026
S 5.0832 62.7831 -0.0026
S 5.6629 62.7816 -0.0026
S 6.5509 62.7793 -0.0026
S 7.4388 62.7770 -0.0026
S 8.3461 62.7745 -0.0028
S 9.2534 62.7720 -0.0028
S 10.1607 62.7695 -0.0028
S 11.0680 62.7670 -0.0028
S 11.9752 62.7645 -0.0028
S 12.8825 62.7620 -0.0028
S 13.7898 62.7595 -0.0028
S 14.7590 62.7567 -0.0028
S 15.7282 62.7540 -0.0028
S 16.6974 62.7512 -0.0028
S 17.6666 62.7485 -0.0028
S 18.6359 62.7458 -0.0028
S 19.6051 62.7430 -0.0028
S 20.5743 62.7403 -0.0028
S 21.5435 62.7375 -0.0028
S 22.5127 62.7348 -0.0028
S 23.4819 62.7320 -0.0028
S 24.4511 62.7293 -0.0028
S 25.4204 62.7266 -0.0028
S 26.3896 62.7238 -0.0028
S 27.3588 62.7211 -0.0028
S 28.3280 62.7183 -0.0028
S 29.2972 62.7156 -0.0028
S 30.2664 62.7128 -0.0028
S 31.2356 62.7101 -0.0028
S 32.2049 62.7074 -0.0028
S 33.1741 62.7046 -0.0028
S 34.1433 62.7019 -0.0028
S 35.1125 62.6991 -0.0028
S 36.0817 62.6964 -0.0028
S 37.0509 62.6936 -0.0028
S 38.0201 62.6909 -0.0028
S 38.9894 62.6882 -0.0028
S 39.9586 62.6854 -0.0028
S 40.9278 62.6827 -0.0028
S 41.7994 62.6799 -0.0032
S 42.6711 62.6771 -0.0032
S 43.5428 62.6744 -0.0032
S 44.4144 62.6716 -0.0032
S 44.8026 62.6703 -0.0035
S 45.1908 62.6689 -0.0035
S 46.1327 62.6654 -0.0037
S 47.0747 62.6618 -0.0037
S 48.0166 62.6583 -0.0037
S 48.9586 62.6548 -0.0037
S 49.3364 62.6533 -0.0040
S 49.7142 62.6518 -0.0040
S 50.0199 62.6505 -0.0042
S 50.3256 62.6492 -0.0042
S 50.8050 62.6471 -0.0044
S 51.2844 62.6450 -0.0044
S 51.4381 62.6442 -0.0049
S 51.5919 62.6435 -0.0049
S 52.5462 62.6382 -0.0056
S 53.5005 62.6328 -0.0058
S 54.4548 62.6271 -0.0061
S 55.4092 62.6212 -0.0063
S 56.3635 62.6151 -0.0065
S 57.3179 62.6088 -0.0068
S 58.2722 62.6022 -0.0070
S 59.2265 62.5954 -0.0072
S 60.1809 62.5884 -0.0075
S 60.5880 62.5853 -0.0077
S 60.9952 62.5821 -0.0078
S 61.1243 62.5811 -0.0080
S 61.2533 62.5801 -0.0080
S 61.7266 62.5762 -0.0083
S 62.1999 62.5722 -0.0084
S 62.4313 62.5703 -0.0085
S 62.6628 62.5683 -0.0085
S 63.5741 62.5605 -0.0086
S 64.4854 62.5526 -0.0086
S 65.3966 62.5448 -0.0086
S 66.3079 62.5369 -0.0086
S 67.2192 62.5291 -0.0086
S 68.1304 62.5212 -0.0086
S 69.0416 62.5133 -0.0086
S 69.9528 62.5055 -0.0086
S 70.8640 62.4976 -0.0086
S 71.7751 62.4897 -0.0086
S 72.6862 62.4819 -0.0086
S 73.6718 62.4735 -0.0085
S 74.6573 62.4651 -0.0085
S 75.6429 62.4567 -0.0085
S 76.6285 62.4484 -0.0085
S 77.6141 62.4400 -0.0085
S 78.5998 62.4316 -0.0085
S 79.5854 62.4233 -0.0085
S 80.5711 62.4149 -0.0085
S 81.5568 62.4065 -0.0085
S 82.5425 62.3981 -0.0085
S 83.5283 62.3898 -0.0085
S 84.5140 62.3814 -0.0085
S 85.4997 62.3730 -0.0085
S 86.4855 62.3646 -0.0085
S 87.4712 62.3563 -0.0085
S 88.4570 62.3479 -0.0085
S 89.4427 62.3395 -0.0085
S 90.4285 62.3311 -0.0085
S 91.4143 62.3228 -0.0085
S 92.4000 62.3144 -0.0085
S 93.3857 62.3060 -0.0085
S 94.3715 62.2976 -0.0085
S 95.3572 62.2893 -0.0085
S 96.3429 62.2809 -0.0085
S 97.3286 62.2725 -0.0085
S 98.3142 62.2641 -0.0085
S 99.2999 62.2558 -0.0085
S 100.2855 62.2474 -0.0085
S 101.2711 62.2390 -0.0085
S 102.2567 62.2306 -0.0085
S 103.2423 62.2223 -0.0085
S 104.2278 62.2139 -0.0085
S 104.9860 62.2079 -0.0079
S 105.7443 62.2019 -0.0079
S 106.5025 62.1959 -0.0079
S 107.4717 62.1885 -0.0076
S 108.4410 62.1811 -0.0076
S 109.4102 62.1737 -0.0076
S 110.3794 62.1663 -0.0076
S 111.3486 62.1589 -0.0076
S 112.3178 62.1515 -0.0076
S 113.2870 62.1441 -0.0076
S 114.2562 62.1367 -0.0076
S 115.2255 62.1293 -0.0076
S 116.1947 62.1219 -0.0076
S 117.1639 62.1145 -0.0076
S 118.1331 62.1071 -0.0076
S 119.1023 62.0997 -0.0076
S 120.0715 62.0923 -0.0076
S 121.0407 62.0849 -0.0076
S 122.0100 62.0775 -0.0076
S 122.9792 62.0701 -0.0076
S 123.9484 62.0627 -0.0076
S 124.9176 62.0553 -0.0076
S 125.8868 62.0479 -0.0076
S 126.8560 62.0405 -0.0076
S 127.8252 62.0331 -0.0076
S 128.7945 62.0257 -0.0076
S 129.7637 62.0183 -0.0076
S 130.7329 62.0109 -0.0076
S 131.7021 62.0035 -0.0076
S 132.6713 61.9961 -0.0076
S 133.6405 61.9887 -0.0076
S 133.9514 61.9866 -0.0067
S 134.2622 61.9845 -0.0067
S 135.2318 61.9783 -0.0064
S 136.2013 61.9721 -0.0064
S 137.1709 61.9659 -0.0064
S 138.1404 61.9597 -0.0064
S 139.1100 61.9534 -0.0064
S 140.0796 61.9472 -0.0064
S 141.0491 61.9410 -0.0064
S 142.0187 61.9348 -0.0064
S 142.9882 61.9286 -0.0064
S 143.9578 61.9223 -0.0064
S 144.9274 61.9161 -0.0064
S 145.8969 61.9099 -0.0064
S 146.8665 61.9037 -0.0064
S 147.8360 61.8975 -0.0064
S 148.8056 61.8913 -0.0064
S 149.7752 61.8850 -0.0064
S 150.7531 61.8790 -0.0062
S 151.7310 61.8730 -0.0062
S 152.7089 61.8670 -0.0062
S 153.6868 61.8610 -0.0062
S 154.6647 61.8549 -0.0062
S 155.6426 61.8489 -0.0062
S 156.6205 61.8429 -0.0062
S 157.5984 61.8369 -0.0062
S 158.5763 61.8309 -0.0062
S 159.5542 61.8249 -0.0062
S 160.5322 61.8188 -0.0062
S 161.5101 61.8128 -0.0062
S 162.4880 61.8068 -0.0062
S 163.4659 61.8008 -0.0062
S 164.4438 61.7948 -0.0062
S 165.4217 61.7888 -0.0062
S 166.3996 61.7827 -0.0062
S 167.3775 61.7767 -0.0062
S 168.3554 61.7707 -0.0062
S 169.3333 61.7647 -0.0062
S 170.3112 61.7587 -0.0062
S 171.2892 61.7526 -0.0062
S 172.2671 61.7466 -0.0062
S 173.2450 61.7406 -0.0062
S 174.2229 61.7346 -0.0062
S 175.2008 61.7286 -0.0062
S 176.1787 61.7226 -0.0062
S 177.1566 61.7165 -0.0062
S 178.1345 61.7105 -0.0062
S 179.1124 61.7045 -0.0062
S 180.0903 61.6985 -0.0062
S 181.0541 61.6927 -0.0060
S 182.0179 61.6870 -0.0060
S 182.9817 61.6812 -0.0060
S 183.9455 61.6754 -0.0060
S 184.9093 61.6697 -0.0060
S 185.8731 61.6639 -0.0060
S 186.7574 61.6588 -0.0058
S 187.6417 61.6536 -0.0058
S 188.5259 61.6485 -0.0058
S 189.4102 61.6433 -0.0058
S 190.2944 61.6382 -0.0058
S 190.4833 61.6371 -0.0056
S 190.6723 61.6361 -0.0056
S 190.8468 61.6351 -0.0053
S 191.0213 61.6342 -0.0053
S 191.9427 61.6297 -0.0047
S 192.8640 61.6255 -0.0045
S 193.7853 61.6214 -0.0043
S 194.7066 61.6176 -0.0041
S 195.6669 61.6140 -0.0037
S 196.6271 61.6105 -0.0034
S 197.5873 61.6074 -0.0032
S 198.5475 61.6044 -0.0030
S 199.5077 61.6017 -0.0027
S 200.4679 61.5992 -0.0025
S 201.4281 61.5969 -0.0022
S 202.3883 61.5949 -0.0020
S 203.3485 61.5931 -0.0018
S 204.3086 61.5915 -0.0015
S 205.2688 61.5902 -0.0013
S 206.2580 61.5892 -0.0009
S 207.2471 61.5884 -0.0007
S 208.2363 61.5879 -0.0004
S 209.2255 61.5876 -0.0002
S 210.2147 61.5876 0.0001
S 211.2038 61.5878 0.0003
S 212.1930 61.5882 0.0006
S 213.1822 61.5889 0.0008
S 214.1714 61.5898 0.0011
S 215.1606 61.5910 0.0013
S 216.1499 61.5924 0.0016
S 217.1391 61.5941 0.0018
S 218.1283 61.5960 0.0021
S 219.1176 61.5982 0.0023
S 220.1069 61.6006 0.0026
S 221.0962 61.6033 0.0028
S 222.0855 61.6061 0.0030
S 223.0748 61.6093 0.0033
S 224.0641 61.6127 0.0035
S 225.0535 61.6163 0.0038
S 225.2278 61.6170 0.0040
S 225.4020 61.6177 0.0040
S 225.6376 61.6187 0.0043
S 225.8731 61.6197 0.0043
S 226.7710 61.6238 0.0047
S 227.6689 61.6281 0.0049
S 228.5668 61.6325 0.0051
S 229.4647 61.6372 0.0053
S 230.3626 61.6421 0.0056
S 231.0092 61.6458 0.0056
S 231.6559 61.6494 0.0056
S 232.6438 61.6550 0.0057
S 233.6318 61.6607 0.0057
S 234.6198 61.6663 0.0057
S 235.6078 61.6720 0.0057
S 236.5958 61.6776 0.0057
S 237.5838 61.6832 0.0057
S 238.5718 61.6889 0.0057
S 239.5598 61.6945 0.0057
S 240.5477 61.7002 0.0057
S 241.5357 61.7058 0.0057
S 242.5237 61.7114 0.0057
S 243.5105 61.7171 0.0058
S 244.4973 61.7228 0.0058
S 245.4842 61.7285 0.0058
S 246.4710 61.7342 0.0058
S 247.4578 61.7399 0.0058
S 248.4446 61.7456 0.0058
S 249.4314 61.7513 0.0058
S 250.4182 61.7570 0.0058
S 251.4050 61.7627 0.0058
S 252.3918 61.7684 0.0058
S 253.3786 61.7741 0.0058
S 254.3655 61.7798 0.0058
S 255.3523 61.7855 0.0058
S 256.3391 61.7911 0.0058
S 257.3259 61.7968 0.0058
S 258.3127 61.8025 0.0058
S 259.2995 61.8082 0.0058
S 260.2863 61.8139 0.0058
S 261.2731 61.8196 0.0058
S 262.2599 61.8253 0.0058
S 263.2468 61.8310 0.0058
S 264.2336 61.8367 0.0058
S 265.2204 61.8424 0.0058
S 266.2072 61.8481 0.0058
S 267.1940 61.8538 0.0058
S 268.1808 61.8595 0.0058
S 269.1676 61.8652 0.0058
S 270.1544 61.8709 0.0058
S 271.1412 61.8766 0.0058
S 272.1281 61.8822 0.0058
S 273.1149 61.8879 0.0058
S 274.1017 61.8936 0.0058
S 275.0885 61.8993 0.0058
S 276.0753 61.9050 0.0058
S 277.0621 61.9107 0.0058
S 278.0489 61.9164 0.0058
S 279.0357 61.9221 0.0058
S 280.0226 61.9278 0.0058
S 281.0094 61.9335 0.0058
S 281.9962 61.9392 0.0058
S 282.9830 61.9449 0.0058
S 283.9698 61.9506 0.0058
S 284.9566 61.9563 0.0058
S 285.9434 61.9620 0.0058
S 286.9302 61.9677 0.0058
S 287.9170 61.9734 0.0058
S 288.9039 61.9790 0.0058
S 289.8907 61.9847 0.0058
S 290.8775 61.9904 0.0058
S 291.8643 61.9961 0.0058
S 292.8511 62.0018 0.0058
S 293.8379 62.0075 0.0058
S 294.8247 62.0132 0.0058
S 295.8115 62.0189 0.0058
S 296.7983 62.0246 0.0058
S 297.7852 62.0303 0.0058
S 298.7720 62.0360 0.0058
S 299.7588 62.0417 0.0058
S 300.7456 62.0474 0.0058
S 301.7324 62.0531 0.0058
S 302.7192 62.0588 0.0058
S 303.7060 62.0645 0.0058
S 304.6928 62.0701 0.0058
S 305.6796 62.0758 0.0058
S 306.6665 62.0815 0.0058
P 0.0000 62.7964 0.0000
P 4.9462 62.7826 4000.0000
P 53.0757 62.6501 4000.0000
P 195.3333 61.4371 4000.0000
P 306.6665 62.0817 0.0000
C 306.6665 1 62.7964 -0.0028 0 62.0815 0.0000
Z 0.0000 4.5035
Z 4.5035 5.6629
Z 5.6629 7.4388
Z 13.7898 40.9278
Z 40.9278 44.4144
Z 44.4144 45.1908
Z 45.1908 48.8505
Z 106.5025 133.6405
Z 133.6405 134.2622
Z 134.2622 141.0804
L 100.0000 6.0000 0.0000 0.4000 2000.0000 2.0000 0.0000 0.0050 1 1

View File

@@ -0,0 +1,13 @@
// stand-ins for the parts of the engine which the code of the editor under test reaches for: the translations give the English
// messages back as they are
#include "stdafx.h"
#include "utilities/translation.h"
locale Translations;
const char *locale::lookup_c(const char *msg, bool) { return msg; }
const std::string &locale::lookup_s(const std::string &msg, bool) { return msg; }
const char *locale::lookup_n(const char *singular, const char *plural, long long n) { return n == 1 ? singular : plural; }

View File

@@ -74,7 +74,7 @@ void node_layers::instance_begin(std::string const &, source_span const &) { //
// basic_node has no key function for the Itanium C++ ABI (tooltip() is declared plain but defined inline), so
// GCC and Clang emit its vtable wherever scenenode.h is used, here too, and the vtable wants radius_().
// the same as the game's, in scene/scenenode.cpp
float basic_node::radius_() {
float basic_node::radius_() const {
return 0.f;
}

File diff suppressed because it is too large Load Diff

88
tests/unit/test_area.cpp Normal file
View File

@@ -0,0 +1,88 @@
#include "stdafx.h"
#include "doctest.h"
#include "editor/editorGeometry.hpp"
#include <algorithm>
#include <cstdlib>
#include <set>
#include <utility>
#include <vector>
namespace {
std::set<std::pair<int, int>> squares(std::vector<glm::dvec2> const &Polygon, double const Size) {
auto const found{geometry::squares_in(Polygon, Size)};
return {found.begin(), found.end()};
}
} // namespace
TEST_CASE("download area: the tiles a triangle touches") {
// x + y < 1000: the squares of 256 m whose corner nearest the origin lies inside
auto const found{squares({{0.0, 0.0}, {1000.0, 0.0}, {0.0, 1000.0}}, 256.0)};
std::set<std::pair<int, int>> expected;
for (int x = 0; x < 4; ++x)
for (int y = 0; x + y < 4; ++y)
expected.emplace(x, y);
CHECK(found == expected);
}
TEST_CASE("download area: the tiles of a concave polygon leave out the ones in its notch") {
// an L, 300 m wide, its arms 1000 m long
auto const found{squares({{0.0, 0.0}, {1000.0, 0.0}, {1000.0, 300.0}, {300.0, 300.0}, {300.0, 1000.0}, {0.0, 1000.0}}, 256.0)};
std::set<std::pair<int, int>> expected;
for (int x = 0; x < 4; ++x)
expected.insert({{x, 0}, {x, 1}});
for (int y = 2; y < 4; ++y)
expected.insert({{0, y}, {1, y}});
CHECK(found == expected);
CHECK(found.count({2, 2}) == 0);
}
TEST_CASE("download area: a thin band along a line touches the tiles it crosses, none further") {
// 4 m wide along the diagonal, from (10, 10) to (2000, 2000)
auto const found{squares({{10.0, 8.0}, {2000.0, 1998.0}, {2000.0, 2002.0}, {10.0, 12.0}}, 256.0)};
for (int i = 0; i < 8; ++i)
CHECK(found.count({i, i}) == 1);
CHECK(std::none_of(found.begin(), found.end(), [](std::pair<int, int> const &Key) { return std::abs(Key.first - Key.second) > 1; }));
}
TEST_CASE("download area: a polygon inside one tile, or around a corner of four") {
CHECK(squares({{10.0, 10.0}, {20.0, 10.0}, {20.0, 20.0}, {10.0, 20.0}}, 256.0) == std::set<std::pair<int, int>>{{0, 0}});
CHECK(squares({{250.0, 250.0}, {262.0, 250.0}, {262.0, 262.0}, {250.0, 262.0}}, 256.0) == std::set<std::pair<int, int>>{{0, 0}, {1, 0}, {0, 1}, {1, 1}});
// in the grid of the coordinates of Poland, about 500 km from its origin
auto const distant{squares({{500100.0, 600100.0}, {500200.0, 600100.0}, {500200.0, 600200.0}}, 256.0)};
CHECK(distant == std::set<std::pair<int, int>>{{1953, 2344}});
}
TEST_CASE("download area: a point inside or outside, a square of no size") {
std::vector<glm::dvec2> const triangle{{0.0, 0.0}, {100.0, 0.0}, {0.0, 100.0}};
CHECK(geometry::square_touches(triangle, 10.0, 10.0, 0.0));
CHECK_FALSE(geometry::square_touches(triangle, 80.0, 80.0, 0.0));
// a square holding the whole polygon touches it, with no corner of its inside
CHECK(geometry::square_touches(triangle, -50.0, -50.0, 300.0));
// fewer than three points: no area
CHECK(geometry::squares_in({{0.0, 0.0}, {100.0, 100.0}}, 256.0).empty());
}
TEST_CASE("download area: its size, whichever way round it's drawn") {
std::vector<glm::dvec2> square{{0.0, 0.0}, {2000.0, 0.0}, {2000.0, 2000.0}, {0.0, 2000.0}};
CHECK(geometry::polygon_area(square) == doctest::Approx(4.0e6));
std::reverse(square.begin(), square.end());
CHECK(geometry::polygon_area(square) == doctest::Approx(4.0e6));
// the L of 300 m, its arms 1000 m long
CHECK(geometry::polygon_area({{0.0, 0.0}, {1000.0, 0.0}, {1000.0, 300.0}, {300.0, 300.0}, {300.0, 1000.0}, {0.0, 1000.0}}) == doctest::Approx(510000.0));
CHECK(geometry::polygon_area({{0.0, 0.0}, {100.0, 100.0}}) == 0.0);
}
TEST_CASE("download area: edges crossing each other, as when the corners are clicked out of order") {
// the corners of a square clicked across: a bow tie
CHECK(geometry::polygon_crosses_itself({{0.0, 0.0}, {1000.0, 1000.0}, {1000.0, 0.0}, {0.0, 1000.0}}));
CHECK_FALSE(geometry::polygon_crosses_itself({{0.0, 0.0}, {1000.0, 0.0}, {1000.0, 1000.0}, {0.0, 1000.0}}));
// a concave polygon isn't a crossing one
CHECK_FALSE(geometry::polygon_crosses_itself({{0.0, 0.0}, {1000.0, 0.0}, {1000.0, 300.0}, {300.0, 300.0}, {300.0, 1000.0}, {0.0, 1000.0}}));
// a triangle can't cross itself
CHECK_FALSE(geometry::polygon_crosses_itself({{0.0, 0.0}, {1000.0, 0.0}, {0.0, 1000.0}}));
// the last edge, back to the first point, across the first one
CHECK(geometry::polygon_crosses_itself({{0.0, 0.0}, {1000.0, 0.0}, {1000.0, 1000.0}, {500.0, -500.0}}));
}

View File

@@ -0,0 +1,565 @@
#include "stdafx.h"
#include "doctest.h"
#include "McZapkie/MOVER.h"
#include "McZapkie/hamulce.h"
#include "vehicle.h"
#include "vehicle/brakesetting.h"
#include "vehicle/Driver.h"
// the brake settings the AI wagon inspector (TController::AutoRewident) chooses for a train, by the
// brake instruction Cw-1 (Mw56) §18 and §19 (eu07/maszyna#350)
namespace {
using brake_setting::train_setting;
constexpr int G{bdelay_G};
constexpr int P{bdelay_P};
constexpr int R{bdelay_R};
constexpr int M{bdelay_M};
// how the AI runs the consist the inspector looks at: as a train (Obey_train or Bank), or shunting it
constexpr bool as_train{true};
constexpr bool shunting{false};
// whether the train stands, as AutoRewident() tells the inspector
constexpr bool standstill{true};
constexpr bool moving{false};
brake_setting::vehicle locomotive(int const Delays = G | P | R) {
return {Delays, true, 17.0, 80000.0};
}
// a freight wagon of the given length [m] and mass [t]
brake_setting::vehicle freight_wagon(double const Length = 15.0, double const Tonnes = 80.0) {
return {G | P, false, Length, Tonnes * 1000.0};
}
brake_setting::vehicle passenger_car(int const Delays = P | R) {
return {Delays, false, 24.5, 45000.0};
}
std::vector<brake_setting::vehicle> train(brake_setting::vehicle const &Locomotive, int const Count, brake_setting::vehicle const &Wagon) {
std::vector<brake_setting::vehicle> consist{Locomotive};
consist.insert(consist.end(), Count, Wagon);
return consist;
}
} // namespace
TEST_CASE("brake setting: a freight train runs on P only up to 500 m and 1300 t of wagons (Cw-1 §19.2)") {
// 25 wagons of 20 m and 52 t: 500 m and 1300 t exactly, the limits included
CHECK(brake_setting::choose_train_setting(train(locomotive(), 25, freight_wagon(20.0, 52.0))) == train_setting::freight_gp);
// one metre longer
CHECK(brake_setting::choose_train_setting(train(locomotive(), 25, freight_wagon(20.04, 52.0))) == train_setting::freight_g);
// one tonne heavier
CHECK(brake_setting::choose_train_setting(train(locomotive(), 25, freight_wagon(20.0, 52.04))) == train_setting::freight_g);
}
TEST_CASE("brake setting: the locomotives don't count into the length and mass of a freight train's wagons") {
// 300 m and 600 t of wagons behind two locomotives of 80 t: all the wagons on P (Cw-1 §19.3a)
auto consist{train(locomotive(), 20, freight_wagon(15.0, 30.0))};
consist.insert(consist.begin(), locomotive());
CHECK(brake_setting::choose_train_setting(consist) == train_setting::freight_p);
auto const settings{brake_setting::choose(consist, as_train)};
CHECK(settings[0] == G);
CHECK(settings[1] == G);
for (std::size_t i = 2; i < settings.size(); ++i) {
CAPTURE(i);
CHECK(settings[i] == P);
}
// a wagon more makes it the long locomotive setting (Cw-1 §19.3b)
consist.emplace_back(freight_wagon(15.0, 30.0));
CHECK(brake_setting::choose_train_setting(consist) == train_setting::freight_gp);
}
TEST_CASE("brake setting: the locomotive and the first five wagons on G, the rest on P (Cw-1 §19.3b)") {
auto const consist{train(locomotive(), 12, freight_wagon(15.0, 60.0))};
REQUIRE(brake_setting::choose_train_setting(consist) == train_setting::freight_gp);
auto const settings{brake_setting::choose(consist, as_train)};
REQUIRE(settings.size() == consist.size());
for (std::size_t i = 0; i < settings.size(); ++i) {
CAPTURE(i);
CHECK(settings[i] == (i <= 5 ? G : P));
}
}
TEST_CASE("brake setting: a locomotive in the middle of the train doesn't put five more wagons on G") {
auto consist{train(locomotive(), 8, freight_wagon(15.0, 60.0))};
consist.emplace_back(locomotive());
consist.insert(consist.end(), 8, freight_wagon(15.0, 60.0));
REQUIRE(brake_setting::choose_train_setting(consist) == train_setting::freight_gp);
auto const settings{brake_setting::choose(consist, as_train)};
CHECK(settings[1] == G);
CHECK(settings[5] == G);
CHECK(settings[6] == P);
CHECK(settings[9] == G); // the locomotive
CHECK(settings[10] == P);
// the inspector of the earlier releases started counting anew at it
auto const legacy{brake_setting::choose_legacy(consist)};
CHECK(legacy[10] == G);
CHECK(legacy[14] == G);
CHECK(legacy[15] == P);
}
TEST_CASE("brake setting: a heavy freight train runs on G, a wagon without G has its brake cut out (Cw-1 §19.9)") {
auto consist{train(locomotive(), 30, freight_wagon(15.0, 80.0))};
consist.emplace_back(passenger_car(P));
consist.emplace_back(passenger_car());
REQUIRE(brake_setting::choose_train_setting(consist) == train_setting::freight_g);
auto const settings{brake_setting::choose(consist, as_train)};
for (std::size_t i = 0; i + 2 < settings.size(); ++i) {
CAPTURE(i);
CHECK(settings[i] == G);
}
CHECK(settings[settings.size() - 2] == brake_setting::cut_out);
CHECK(settings.back() == brake_setting::cut_out);
// the inspector of the earlier releases put them on P
auto const legacy{brake_setting::choose_legacy(consist)};
CHECK(legacy[settings.size() - 2] == P);
CHECK(legacy.back() == P);
}
TEST_CASE("brake setting: in a train on G a locomotive and the vehicle it's driven from keep a working brake") {
auto consist{train(locomotive(P | R), 30, freight_wagon(15.0, 80.0))};
// a dead locomotive without G at the end, and a car which tells no settings at all
consist.emplace_back(locomotive(P | R));
consist.emplace_back(0, false, 20.0, 40000.0);
REQUIRE(brake_setting::choose_train_setting(consist) == train_setting::freight_g);
auto settings{brake_setting::choose(consist, as_train)};
CHECK(settings.front() == P);
CHECK(settings[settings.size() - 2] == P);
CHECK(settings.back() == 0);
// a control car without G, the train driven from it, pushed by the locomotive at the rear
brake_setting::vehicle controlcar{P | R, false, 24.5, 45000.0};
controlcar.driven = true;
consist.front() = controlcar;
consist.back() = locomotive();
settings = brake_setting::choose(consist, as_train);
CHECK(settings.front() == P);
CHECK(settings.back() == G);
}
TEST_CASE("brake setting: in the long locomotive setting a vehicle without G brakes on P, not cut out (Cw-1 §19.3b)") {
// the train runs on P, so §19.9 doesn't apply to it, among the first five wagons kept on G or behind them
auto consist{train(locomotive(), 2, freight_wagon(15.0, 60.0))};
consist.emplace_back(passenger_car());
consist.insert(consist.end(), 8, freight_wagon(15.0, 60.0));
consist.emplace_back(passenger_car());
REQUIRE(brake_setting::choose_train_setting(consist) == train_setting::freight_gp);
auto const settings{brake_setting::choose(consist, as_train)};
CHECK(settings[2] == G);
CHECK(settings[3] == P);
CHECK(settings[4] == G);
CHECK(settings[6] == P);
CHECK(settings.back() == P);
}
TEST_CASE("brake setting: a heavy consist being shunted has nothing cut out, a wagon without G brakes on P") {
// §19.9 is about trains: the same consist the AI shunts rather than runs as a train
auto consist{train(locomotive(), 30, freight_wagon(15.0, 80.0))};
consist.emplace_back(passenger_car(P));
consist.emplace_back(passenger_car());
REQUIRE(brake_setting::choose_train_setting(consist) == train_setting::freight_g);
auto const settings{brake_setting::choose(consist, shunting)};
for (std::size_t i = 0; i + 2 < settings.size(); ++i) {
CAPTURE(i);
CHECK(settings[i] == G);
}
CHECK(settings[settings.size() - 2] == P);
CHECK(settings.back() == P);
// as a train they're cut out
CHECK(brake_setting::choose(consist, as_train).back() == brake_setting::cut_out);
}
TEST_CASE("brake setting: a car with its brake cut out counts as one on P in a passenger train (Cw-1 §18.3)") {
auto consist{train(locomotive(), 5, passenger_car())};
consist.insert(consist.end(), 3, passenger_car(P));
REQUIRE(brake_setting::choose_train_setting(consist) == train_setting::passenger_r);
// one car with R cut out makes four on P
consist[1].cut_out = true;
CHECK(brake_setting::choose_train_setting(consist) == train_setting::passenger_p);
// with fewer P-only cars, three on P and four on R still run on R
consist.pop_back();
CHECK(brake_setting::choose_train_setting(consist) == train_setting::passenger_r);
// a cut out brake changes nothing about a train being a passenger or a freight one
auto freight{train(locomotive(), 4, freight_wagon())};
freight.emplace_back(passenger_car());
freight.back().cut_out = true;
CHECK(brake_setting::choose_train_setting(freight) == train_setting::freight_p);
}
namespace {
// a passenger car with P and R, with the KE distributor of the test wagon
test::definition passenger_car_definition() {
return test::definition::load("wagon").set("Cntrl", "BrakeDelays", "PR");
}
// charges the brake of the vehicle from a brake pipe at 5 bar, then makes a full service application
void charge_and_apply(test::vehicle &Vehicle) {
Vehicle.hold_brake_pipe(5.0);
Vehicle.run(90.0);
Vehicle.hold_brake_pipe(3.5);
Vehicle.run(20.0);
}
// the inspector at work on a heavy train on G with the vehicle at its end, as AutoRewident() does it, the AI
// running it as a train or shunting it, standing or on the run
int inspect_heavy_train(test::vehicle &Vehicle, bool const Train = as_train, bool const Standstill = standstill) {
auto consist{train(locomotive(), 30, freight_wagon(15.0, 80.0))};
consist.emplace_back(brake_setting::describe(Vehicle.mover(), false));
auto const setting{brake_setting::choose(consist, Train).back()};
brake_setting::apply(Vehicle.mover(), setting, Standstill);
return setting;
}
// the same on a light train, which runs on P
int inspect_light_train(test::vehicle &Vehicle) {
auto consist{train(locomotive(), 4, freight_wagon())};
consist.emplace_back(brake_setting::describe(Vehicle.mover(), false));
auto const setting{brake_setting::choose(consist, as_train).back()};
brake_setting::apply(Vehicle.mover(), setting, standstill);
return setting;
}
// the inspector at work on a whole heavy train on G, the vehicles at its end, the way AutoRewident() goes through
// the train. tells whether it left a cut-out for the next standstill, as AutoRewident() notes for reinspect_brakes()
bool inspection_pending(std::vector<test::vehicle *> const &Vehicles, bool const Train, bool const Standstill) {
auto consist{train(locomotive(), 30, freight_wagon(15.0, 80.0))};
for (auto *vehicle : Vehicles) {
consist.emplace_back(brake_setting::describe(vehicle->mover(), false));
}
auto const settings{brake_setting::choose(consist, Train)};
auto setting{settings.end() - static_cast<std::ptrdiff_t>(Vehicles.size())};
auto pending{false};
for (auto *vehicle : Vehicles) {
if (brake_setting::apply(vehicle->mover(), *setting++, Standstill)) {
pending = true;
}
}
return pending;
}
} // namespace
TEST_CASE("brake setting: the inspector cuts the brake out in a train on G and puts it back in a train on P") {
test::vehicle car{passenger_car_definition()};
charge_and_apply(car);
REQUIRE(car->BrakePress > 1.0);
// made up into a heavy train on G: the brake is cut out and released
REQUIRE(inspect_heavy_train(car) == brake_setting::cut_out);
CHECK(brake_setting::is_cut_out(car.mover()));
CHECK(car->BrakeCutOutByInspector);
car.run(30.0);
CHECK(car->BrakePress < 0.1);
// and it stays off whatever the brake pipe does
car.hold_brake_pipe(5.0);
car.run(60.0);
car.hold_brake_pipe(3.5);
car.run(20.0);
CHECK(car->BrakePress < 0.1);
car.hold_brake_pipe(0.0);
car.run(20.0);
CHECK(car->BrakePress < 0.1);
// to the inspector looking at the train again it's a car like any other, and the train needs it cut out still
CHECK(false == brake_setting::describe(car.mover(), false).cut_out);
REQUIRE(inspect_heavy_train(car) == brake_setting::cut_out);
CHECK(car->BrakeCutOutByInspector);
// made up into a light train: the brake is back on P, charges and brakes again
CHECK(inspect_light_train(car) == P);
CHECK(false == brake_setting::is_cut_out(car.mover()));
CHECK(false == car->BrakeCutOutByInspector);
CHECK(car->BrakeDelayFlag == P);
// the reservoirs emptied when it was cut out take some five minutes to charge from the brake pipe
car.hold_brake_pipe(5.0);
car.run(300.0);
CHECK(car->Hamulec->GetBRP() > 4.9);
charge_and_apply(car);
CHECK(car->BrakePress > 1.0);
}
TEST_CASE("brake setting: the inspector never puts back a brake cut out for another reason") {
test::vehicle car{passenger_car_definition()};
charge_and_apply(car);
// cut out the way the scenery's '0' does it
car->Hamulec->ForceEmptiness();
car->Hamulec->SetBrakeStatus(car->Hamulec->GetBrakeStatus() | b_dmg);
CHECK(brake_setting::describe(car.mover(), false).cut_out);
// a train on G wants it cut out anyway: it isn't the inspector's to put back
CHECK(inspect_heavy_train(car) == brake_setting::cut_out);
CHECK(false == car->BrakeCutOutByInspector);
// a train on P would want it working: it stays cut out
CHECK(inspect_light_train(car) == P);
CHECK(brake_setting::is_cut_out(car.mover()));
charge_and_apply(car);
CHECK(car->BrakePress < 0.1);
// a brake the inspector cut out, which someone else puts back and cuts out again, is theirs from then on
test::vehicle other{passenger_car_definition()};
REQUIRE(inspect_heavy_train(other) == brake_setting::cut_out);
other->Hamulec->SetBrakeStatus(other->Hamulec->GetBrakeStatus() & ~b_dmg);
CHECK(inspect_heavy_train(other) == brake_setting::cut_out); // the inspector cuts it out again, and it's its own again
CHECK(other->BrakeCutOutByInspector);
other->Hamulec->SetBrakeStatus(other->Hamulec->GetBrakeStatus() & ~b_dmg);
CHECK(inspect_light_train(other) == P);
CHECK(false == other->BrakeCutOutByInspector);
other->Hamulec->SetBrakeStatus(other->Hamulec->GetBrakeStatus() | b_dmg);
CHECK(inspect_light_train(other) == P);
CHECK(brake_setting::is_cut_out(other.mover()));
}
TEST_CASE("brake setting: shunting puts back a brake the inspector cut out, and cuts none out") {
test::vehicle car{passenger_car_definition()};
charge_and_apply(car);
// shunted in a heavy consist: nothing is cut out, the car is on P and brakes
CHECK(inspect_heavy_train(car, shunting) == P);
CHECK(false == brake_setting::is_cut_out(car.mover()));
CHECK(car->BrakeDelayFlag == P);
CHECK(car->BrakePress > 1.0);
// cut out when the consist became a train, then shunted again (e.g. left in a yard): the brake is back
REQUIRE(inspect_heavy_train(car) == brake_setting::cut_out);
REQUIRE(car->BrakeCutOutByInspector);
CHECK(inspect_heavy_train(car, shunting) == P);
CHECK(false == brake_setting::is_cut_out(car.mover()));
CHECK(false == car->BrakeCutOutByInspector);
car.hold_brake_pipe(5.0);
car.run(300.0);
charge_and_apply(car);
CHECK(car->BrakePress > 1.0);
// a brake cut out for a reason of its own stays cut out in shunting too
test::vehicle other{passenger_car_definition()};
other->Hamulec->SetBrakeStatus(other->Hamulec->GetBrakeStatus() | b_dmg);
CHECK(inspect_heavy_train(other, shunting) == P);
CHECK(brake_setting::is_cut_out(other.mover()));
}
TEST_CASE("brake setting: the inspector doesn't cut a brake out on the run, it waits for a standstill") {
test::vehicle car{passenger_car_definition()};
charge_and_apply(car);
REQUIRE(car->BrakePress > 1.0);
// the train checked on the run (the order changed mid-run): the car keeps its brake and its setting
auto const setting{car->BrakeDelayFlag};
CHECK(inspect_heavy_train(car, as_train, moving) == brake_setting::cut_out);
CHECK(false == brake_setting::is_cut_out(car.mover()));
CHECK(false == car->BrakeCutOutByInspector);
CHECK(car->BrakeDelayFlag == setting);
car.run(5.0);
CHECK(car->BrakePress > 1.0);
// the next check, standing, cuts it out
CHECK(inspect_heavy_train(car) == brake_setting::cut_out);
CHECK(brake_setting::is_cut_out(car.mover()));
CHECK(car->BrakeCutOutByInspector);
// a brake cut out already stays cut out on the run, and one put back on the run is back
CHECK(inspect_heavy_train(car, as_train, moving) == brake_setting::cut_out);
CHECK(car->BrakeCutOutByInspector);
CHECK(inspect_heavy_train(car, shunting, moving) == P);
CHECK(false == brake_setting::is_cut_out(car.mover()));
CHECK(false == car->BrakeCutOutByInspector);
}
TEST_CASE("brake setting: a cut-out skipped on the run is reported, and done at the next inspection standing") {
// a train formed by coupling: the AI looks at it as the buffers meet, above 1 km/h. two cars without G and
// a freight wagon at the end of a heavy train on G
test::vehicle first{passenger_car_definition()};
test::vehicle second{passenger_car_definition()};
test::vehicle wagon{test::definition::load("wagon").set("Cntrl", "BrakeDelays", "GP")};
std::vector<test::vehicle *> const vehicles{&first, &second, &wagon};
for (auto *vehicle : vehicles) {
charge_and_apply(*vehicle);
}
auto const setting{first->BrakeDelayFlag};
// moving: nothing is cut out, and the inspector tells it has to come back
CHECK(inspection_pending(vehicles, as_train, brake_setting::at_standstill(3.0)));
for (auto *vehicle : vehicles) {
CHECK(false == brake_setting::is_cut_out(vehicle->mover()));
CHECK(false == vehicle->mover().BrakeCutOutByInspector);
}
CHECK(first->BrakeDelayFlag == setting);
CHECK(wagon->BrakeDelayFlag == G);
// still moving: still pending
CHECK(inspection_pending(vehicles, as_train, moving));
// the train stands (its brake pipe charging after the coupling): the cars get cut out, nothing is left
CHECK(false == inspection_pending(vehicles, as_train, brake_setting::at_standstill(0.0)));
CHECK(brake_setting::is_cut_out(first.mover()));
CHECK(first->BrakeCutOutByInspector);
CHECK(brake_setting::is_cut_out(second.mover()));
CHECK(second->BrakeCutOutByInspector);
CHECK(false == brake_setting::is_cut_out(wagon.mover()));
// and nothing is pending when the train moves off
CHECK(false == inspection_pending(vehicles, as_train, moving));
CHECK(brake_setting::is_cut_out(first.mover()));
}
TEST_CASE("brake setting: an inspection on the run with nothing to cut out leaves nothing pending") {
// a wagon with G in a heavy train on G
test::vehicle wagon{test::definition::load("wagon").set("Cntrl", "BrakeDelays", "GP")};
CHECK(false == inspection_pending({&wagon}, as_train, moving));
CHECK(wagon->BrakeDelayFlag == G);
// a car without G in a consist being shunted: it keeps its brake, on P
test::vehicle car{passenger_car_definition()};
CHECK(false == inspection_pending({&car}, shunting, moving));
CHECK(false == brake_setting::is_cut_out(car.mover()));
// a car whose brake is cut out already, for a reason of its own or by the inspector
test::vehicle damaged{passenger_car_definition()};
damaged->Hamulec->SetBrakeStatus(damaged->Hamulec->GetBrakeStatus() | b_dmg);
CHECK(false == inspection_pending({&damaged}, as_train, moving));
CHECK(false == damaged->BrakeCutOutByInspector);
test::vehicle done{passenger_car_definition()};
REQUIRE(false == inspection_pending({&done}, as_train, standstill));
REQUIRE(done->BrakeCutOutByInspector);
CHECK(false == inspection_pending({&done}, as_train, moving));
// a brake put back on the run (the train became a consist being shunted) leaves nothing either
CHECK(false == inspection_pending({&done}, shunting, moving));
CHECK(false == brake_setting::is_cut_out(done.mover()));
// a single vehicle's apply() tells the same
test::vehicle single{passenger_car_definition()};
CHECK(brake_setting::apply(single.mover(), brake_setting::cut_out, moving));
CHECK(false == brake_setting::apply(single.mover(), P, moving));
CHECK(false == brake_setting::apply(single.mover(), 0, moving));
CHECK(false == brake_setting::apply(single.mover(), brake_setting::cut_out, standstill));
CHECK(false == brake_setting::apply(single.mover(), brake_setting::cut_out, moving));
}
TEST_CASE("brake setting: a train creeping to a stop counts as standing, one on the run or coupling doesn't") {
// the AI looks at the train at a W4 and when it switches from shunting to the train run below 1 km/h: the
// inspector takes those for a standstill. it couples faster than that (it drives onto the standing cut at up
// to 4 km/h and looks at the new train at the first buffer contact), so the brakes to cut out then wait for
// the look the AI takes once the train stands (the test above)
CHECK(brake_setting::at_standstill(0.0));
CHECK(brake_setting::at_standstill(0.04));
CHECK(brake_setting::at_standstill(0.9));
CHECK(brake_setting::at_standstill(-0.9));
CHECK(false == brake_setting::at_standstill(EU07_AI_MOVEMENT));
CHECK(false == brake_setting::at_standstill(30.0));
// checked at 0.9 km/h: the brake is cut out
test::vehicle creeping{passenger_car_definition()};
charge_and_apply(creeping);
CHECK(inspect_heavy_train(creeping, as_train, brake_setting::at_standstill(0.9)) == brake_setting::cut_out);
CHECK(brake_setting::is_cut_out(creeping.mover()));
CHECK(creeping->BrakeCutOutByInspector);
// checked at 30 km/h: the car keeps its brake
test::vehicle running{passenger_car_definition()};
charge_and_apply(running);
CHECK(inspect_heavy_train(running, as_train, brake_setting::at_standstill(30.0)) == brake_setting::cut_out);
CHECK(false == brake_setting::is_cut_out(running.mover()));
CHECK(false == running->BrakeCutOutByInspector);
running.run(5.0);
CHECK(running->BrakePress > 1.0);
}
TEST_CASE("brake setting: a bank engine's run counts as a train, shunting doesn't") {
CHECK(brake_setting::runs_as_train(Obey_train));
CHECK(brake_setting::runs_as_train(Bank));
CHECK(brake_setting::runs_as_train(Obey_train | Connect));
CHECK(false == brake_setting::runs_as_train(Shunt));
CHECK(false == brake_setting::runs_as_train(Loose_shunt));
CHECK(false == brake_setting::runs_as_train(Connect));
CHECK(false == brake_setting::runs_as_train(Wait_for_orders));
// a heavy consist on G banked: the wagon without G has its brake cut out, as in a train
test::vehicle car{passenger_car_definition()};
charge_and_apply(car);
CHECK(inspect_heavy_train(car, brake_setting::runs_as_train(Bank)) == brake_setting::cut_out);
CHECK(brake_setting::is_cut_out(car.mover()));
// shunted: it's back on P
CHECK(inspect_heavy_train(car, brake_setting::runs_as_train(Shunt)) == P);
CHECK(false == brake_setting::is_cut_out(car.mover()));
}
TEST_CASE("brake setting: R+Mg brakes as hard as R at speed, the rapid stage of an LSt kept") {
// the inspector sets R+Mg (Cw-1 §18.2), the bits of R and Mg together: the valves test the bit of R, not
// the whole setting, so the high stage of R at speed stays on with Mg. the EU07's LSt given an Mg here
auto const definition{test::definition::fiz("4e_v1/4e").set("Cntrl", "BrakeDelays", "GPR+Mg")};
auto const service = [&](int const Setting) {
test::reseed_random();
test::vehicle real{definition, 160.0};
real->DecManualBrakeLevel(ManualBrakePosNo);
real->BrakeDelaySwitch(Setting); // false when already set
REQUIRE(real->BrakeDelayFlag == Setting);
real.hold_brake_pipe(5.0);
real.run(60.0);
real.hold_brake_pipe(3.5);
real.run(10.0);
REQUIRE(real->Vel > 100.0);
return real->BrakePress;
};
auto const rapid{service(R)};
CHECK(service(R | M) == doctest::Approx(rapid).epsilon(0.01));
// and P has no high stage
CHECK(service(P) < rapid - 1.0);
}
TEST_CASE("brake setting: a vehicle without the setting the train needs gets the other one of G and P") {
// a light freight train with a wagon which has G only
auto consist{train(locomotive(), 4, freight_wagon(15.0, 20.0))};
consist.emplace_back(G, false, 15.0, 20000.0);
REQUIRE(brake_setting::choose_train_setting(consist) == train_setting::freight_p);
CHECK(brake_setting::choose(consist, as_train).back() == G);
// and a vehicle with neither is left alone
consist.emplace_back(R, false, 15.0, 20000.0);
CHECK(brake_setting::choose(consist, as_train).back() == 0);
}
TEST_CASE("brake setting: a passenger train on R carries at most three cars on P, fewer than those on R (Cw-1 §18.3)") {
auto consist{train(locomotive(), 4, passenger_car())};
consist.insert(consist.end(), 3, passenger_car(P));
CHECK(brake_setting::choose_train_setting(consist) == train_setting::passenger_r);
auto const settings{brake_setting::choose(consist, as_train)};
CHECK(settings[0] == R);
CHECK(settings[1] == R);
CHECK(settings.back() == P);
// as many cars on P as on R: all on P
consist.emplace_back(passenger_car(P));
CHECK(brake_setting::choose_train_setting(consist) == train_setting::passenger_p);
for (auto const setting : brake_setting::choose(consist, as_train)) {
CHECK(setting == P);
}
// the inspector of the earlier releases kept such a train on R
CHECK(brake_setting::choose_legacy(consist)[1] == R);
// four cars on P are too many even with more on R
consist.insert(consist.end(), 6, passenger_car());
CHECK(brake_setting::choose_train_setting(consist) == train_setting::passenger_p);
}
TEST_CASE("brake setting: freight wagons in a passenger train on R count as cars on P (Cw-1 §18.4)") {
auto consist{train(locomotive(), 6, passenger_car())};
consist.emplace_back(freight_wagon());
REQUIRE(brake_setting::choose_train_setting(consist) == train_setting::passenger_r);
CHECK(brake_setting::choose(consist, as_train).back() == P);
}
TEST_CASE("brake setting: cars with a magnetic rail brake run on R+Mg in a train on R (Cw-1 §18.2)") {
auto consist{train(locomotive(G | P | R | M), 3, passenger_car(P | R | M))};
consist.emplace_back(passenger_car());
REQUIRE(brake_setting::choose_train_setting(consist) == train_setting::passenger_r);
auto const settings{brake_setting::choose(consist, as_train)};
CHECK(settings[0] == R); // the locomotive stays on R
CHECK(settings[1] == (R | M));
CHECK(settings.back() == R);
}
TEST_CASE("brake setting: a light engine runs on R where it has it") {
std::vector<brake_setting::vehicle> const consist{locomotive(), locomotive(G | P)};
CHECK(brake_setting::choose_train_setting(consist) == train_setting::light_engine);
auto const settings{brake_setting::choose(consist, as_train)};
CHECK(settings[0] == R);
CHECK(settings[1] == P);
}
TEST_CASE("brake setting: the inspector of the earlier releases counted the locomotives into the train's mass") {
// 300 m and 600 t of wagons: P by Cw-1, the long locomotive setting before
auto const consist{train(locomotive(), 20, freight_wagon(15.0, 30.0))};
CHECK(brake_setting::choose(consist, as_train)[1] == P);
CHECK(brake_setting::choose_legacy(consist)[1] == G);
CHECK(brake_setting::choose_legacy(consist)[6] == P);
}

115
tests/unit/test_fouling.cpp Normal file
View File

@@ -0,0 +1,115 @@
#include "stdafx.h"
#include "doctest.h"
#include "editor/editorFouling.hpp"
#include "editor/editorGauge.hpp"
#include <cmath>
#include <vector>
namespace {
// the axis from the origin along z, a point each metre; Radius 0 straight, else a curve towards +x (Radius > 0) or -x
std::vector<glm::dvec3> axis(double const Radius, double const Slope = 0.0, double const Length = 150.0) {
std::vector<glm::dvec3> points;
auto const metres{static_cast<int>(std::floor(Length + 1e-9))};
for (int metre = 0; metre <= metres; ++metre) {
auto const s{static_cast<double>(metre)};
if (Radius == 0.0) {
auto const along{s / std::sqrt(1.0 + Slope * Slope)};
points.emplace_back(along * Slope, 0.0, along);
}
else {
auto const r{std::abs(Radius)};
auto const side{Radius > 0.0 ? 1.0 : -1.0};
points.emplace_back(side * r * (1.0 - std::cos(s / r)), 0.0, r * std::sin(s / r));
}
}
return points;
}
} // namespace
TEST_CASE("the widening of the gauge from the radius is that of table 1 of the standard, none from 250 m up") {
CHECK(gauge::curve_widening(200.0, true) == doctest::Approx(50.0 / 200.0 - 0.185));
CHECK(gauge::curve_widening(200.0, false) == doctest::Approx(60.0 / 200.0 - 0.225));
CHECK(gauge::curve_widening(180.0, false) == doctest::Approx(60.0 / 180.0 - 0.225));
CHECK(gauge::curve_widening(250.0, true) == 0.0);
CHECK(gauge::curve_widening(300.0, false) == 0.0);
CHECK(gauge::curve_widening(0.0, false) == 0.0);
// the table ends at 150 m: the sharper curves get its value there
CHECK(gauge::curve_widening(40.0, true) == doctest::Approx(50.0 / 150.0 - 0.185));
CHECK(gauge::curve_widening(100.0, false) == doctest::Approx(60.0 / 150.0 - 0.225));
}
TEST_CASE("a straight branch at 1:9 off a straight track fouls it where the axes are 3.50 m apart") {
fouling::place place;
REQUIRE(fouling::find(axis(0.0), axis(0.0, 1.0 / 9.0), fouling::kNominal, place));
CHECK(place.spacing == doctest::Approx(3.5));
CHECK(place.main.z == doctest::Approx(31.5).epsilon(0.002));
CHECK(place.branch.x == doctest::Approx(3.5).epsilon(0.002));
}
TEST_CASE("a branch in a curve of 300 m fouls at 3.50 m, the gauge including the curve") {
fouling::place place;
REQUIRE(fouling::find(axis(0.0), axis(300.0), fouling::kNominal, place));
CHECK(place.spacing == doctest::Approx(3.5));
CHECK(place.main.z == doctest::Approx(std::sqrt(300.0 * 300.0 - 296.5 * 296.5)).epsilon(0.002));
}
TEST_CASE("a branch in a curve under 250 m fouls farther: the widening on the outer side of its curve is added") {
// the straight track lies on the outer side of the curve of the branch
fouling::place place;
REQUIRE(fouling::find(axis(0.0), axis(200.0), fouling::kNominal, place));
auto const wanted{3.5 + 60.0 / 200.0 - 0.225};
CHECK(place.spacing == doctest::Approx(wanted).epsilon(0.001));
CHECK(place.branch.x == doctest::Approx(wanted).epsilon(0.002));
CHECK(place.main.z == doctest::Approx(std::sqrt(200.0 * 200.0 - (200.0 - wanted) * (200.0 - wanted))).epsilon(0.002));
}
TEST_CASE("both tracks in curves under 250 m: the widenings of both are summed, each on the side of the other track") {
// the branch curves sharper, inside the curve of the main track: on the inner side of the main track, which lies on the outer
// side of the branch
fouling::place place;
REQUIRE(fouling::find(axis(200.0), axis(180.0), fouling::kNominal, place));
auto const wanted{3.5 + (50.0 / 200.0 - 0.185) + (60.0 / 180.0 - 0.225)};
CHECK(place.spacing == doctest::Approx(wanted).epsilon(0.001));
// the branch there that far from the axis of the main track, the circle about (200, 0)
auto const off{200.0 - std::hypot(place.branch.x - 200.0, place.branch.z)};
CHECK(off == doctest::Approx(wanted).epsilon(0.003));
}
TEST_CASE("the cars of a track on a cant lean towards the other track when its lower rail is on that side, at any radius") {
// the curves of axis() turn to the right of the way they run, towards +x: the cant of a curve lowers its right rail,
// negative as widening_at takes it; positive the other way round
std::vector<double> const cant(200, -0.1);
std::vector<double> const against(200, 0.1);
auto const lean{0.1 * fouling::kLeanHeight / 1.5};
CHECK(fouling::kLeanHeight == doctest::Approx(3.25));
CHECK(gauge::cant_widening(-0.1, fouling::kLeanHeight) == doctest::Approx(lean));
fouling::place place;
// the branch inside the curve of the main track, on its inner side: the main track on the cant leans towards it
REQUIRE(fouling::find(axis(200.0), axis(180.0), fouling::kNominal, place, cant, {}));
CHECK(place.spacing == doctest::Approx(3.5 + (50.0 / 200.0 - 0.185) + lean + (60.0 / 180.0 - 0.225)).epsilon(0.001));
CHECK(place.cant == doctest::Approx(lean).epsilon(0.001));
// the branch on the cant leans away from the main track, on the outer side of its curve: nothing for it
REQUIRE(fouling::find(axis(0.0), axis(200.0), fouling::kNominal, place, {}, cant));
CHECK(place.spacing == doctest::Approx(3.5 + 60.0 / 200.0 - 0.225).epsilon(0.001));
CHECK(place.cant == doctest::Approx(0.0));
// a branch on a cant against its curve leans towards the main track on the outer side of the curve: the lean counts
REQUIRE(fouling::find(axis(0.0), axis(200.0), fouling::kNominal, place, {}, against));
CHECK(place.spacing == doctest::Approx(3.5 + 60.0 / 200.0 - 0.225 + lean).epsilon(0.001));
CHECK(place.cant == doctest::Approx(lean).epsilon(0.001));
// from 250 m up no widening from the radius, but the cars lean on the cant all the same
REQUIRE(fouling::find(axis(300.0), axis(260.0), fouling::kNominal, place, cant, {}));
CHECK(place.spacing == doctest::Approx(3.5 + lean).epsilon(0.001));
// and on the straight: a straight track on a cant leaning towards a straight branch
std::vector<double> const left(200, 0.1);
REQUIRE(fouling::find(axis(0.0), axis(0.0, -1.0 / 9.0), fouling::kNominal, place, left, {}));
CHECK(place.spacing == doctest::Approx(3.5 + lean).epsilon(0.001));
}
TEST_CASE("a straight branch off a track curving away from it: the widening on the outer side of the curve of the main track") {
fouling::place place;
REQUIRE(fouling::find(axis(-200.0), axis(0.0, 1.0 / 9.0), fouling::kNominal, place));
CHECK(place.spacing == doctest::Approx(3.5 + 60.0 / 200.0 - 0.225).epsilon(0.001));
}

129
tests/unit/test_geotiff.cpp Normal file
View File

@@ -0,0 +1,129 @@
#include "stdafx.h"
#include "doctest.h"
#include "editor/editorGeoTiff.hpp"
#include <algorithm>
#include <cstdint>
#include <cstring>
#include <vector>
namespace {
struct raster {
int width{0};
int height{0};
std::vector<float> heights;
double pixel{0.0};
double east{0.0};
double north{0.0};
};
float constexpr missing{-1001.f};
// a GeoTIFF like the one of the terrain model service: little-endian, one band of floats, Rows rows a strip, Strips of them
// listed, the pixel of 1 m, the north-west corner at 1000, 2000. The height of a pixel is its row * 10 + its column
std::vector<std::uint8_t> geotiff(int const Width, int const Height, std::uint32_t const Rows, std::uint32_t const Strips) {
std::vector<std::uint8_t> out;
auto const put16 = [&](std::uint32_t const Value) {
for (int i = 0; i < 2; ++i)
out.push_back(static_cast<std::uint8_t>(Value >> (8 * i)));
};
auto const put32 = [&](std::uint32_t const Value) {
for (int i = 0; i < 4; ++i)
out.push_back(static_cast<std::uint8_t>(Value >> (8 * i)));
};
auto const put64 = [&](double const Value) {
std::uint64_t bits;
std::memcpy(&bits, &Value, sizeof(bits));
for (int i = 0; i < 8; ++i)
out.push_back(static_cast<std::uint8_t>(bits >> (8 * i)));
};
std::uint32_t constexpr count{9};
std::uint32_t constexpr ifd{8};
std::uint32_t const offsets{ifd + 2 + count * 12 + 4};
std::uint32_t const scale{offsets + 4 * Strips};
std::uint32_t const tie{scale + 3 * 8};
std::uint32_t const pixels{tie + 6 * 8};
auto const rows{std::min<std::uint32_t>(Rows, Height)};
out.push_back('I');
out.push_back('I');
put16(42);
put32(ifd);
put16(count);
auto const entry = [&](std::uint32_t const Tag, std::uint32_t const Type, std::uint32_t const Count, std::uint32_t const Value) {
put16(Tag);
put16(Type);
put32(Count);
put32(Value);
};
entry(256, 4, 1, Width);
entry(257, 4, 1, Height);
entry(258, 3, 1, 32);
entry(259, 3, 1, 1);
entry(273, 4, Strips, Strips == 1 ? pixels : offsets);
entry(278, 4, 1, Rows);
entry(339, 3, 1, 3);
entry(33550, 12, 3, scale);
entry(33922, 12, 6, tie);
put32(0);
for (std::uint32_t strip = 0; strip < Strips; ++strip)
put32(pixels + strip * rows * Width * 4);
for (double const value : {1.0, 1.0, 0.0})
put64(value);
for (double const value : {0.0, 0.0, 0.0, 1000.0, 2000.0, 0.0})
put64(value);
for (int row = 0; row < Height; ++row)
for (int column = 0; column < Width; ++column) {
float const height{static_cast<float>(row * 10 + column)};
std::uint32_t bits;
std::memcpy(&bits, &height, sizeof(bits));
put32(bits);
}
return out;
}
} // namespace
TEST_CASE("terrain model: a GeoTIFF of the service read whole") {
auto const data{geotiff(5, 7, 2, 4)};
raster square;
REQUIRE(editor_geotiff::read(data, square, missing));
CHECK(square.width == 5);
CHECK(square.height == 7);
REQUIRE(square.heights.size() == 35);
CHECK(square.heights[0] == 0.f);
CHECK(square.heights[2 * 5 + 3] == 23.f);
CHECK(square.heights[6 * 5 + 4] == 64.f); // in the last strip, of one row
CHECK(square.pixel == 1.0);
CHECK(square.east == 1000.0);
CHECK(square.north == 2000.0);
}
TEST_CASE("terrain model: the rows all in one strip") {
raster square;
REQUIRE(editor_geotiff::read(geotiff(5, 7, 0xffffffffu, 1), square, missing));
CHECK(square.heights[6 * 5 + 4] == 64.f);
}
TEST_CASE("terrain model: a GeoTIFF cut short isn't read, its missing pixels would be heights of 0 m") {
auto data{geotiff(5, 7, 2, 4)};
raster square;
SUBCASE("by a byte") {
data.pop_back();
CHECK_FALSE(editor_geotiff::read(data, square, missing));
}
SUBCASE("by its last strip") {
data.resize(data.size() - 5 * 4);
CHECK_FALSE(editor_geotiff::read(data, square, missing));
}
SUBCASE("to the half of its pixels") {
data.resize(data.size() - 5 * 7 * 2);
CHECK_FALSE(editor_geotiff::read(data, square, missing));
}
CHECK(square.heights.empty());
}
TEST_CASE("terrain model: a GeoTIFF listing fewer strips than its rows need isn't read") {
raster square;
CHECK_FALSE(editor_geotiff::read(geotiff(5, 7, 2, 3), square, missing));
}

View File

@@ -0,0 +1,163 @@
#include "stdafx.h"
#include "doctest.h"
#include "editor/editorProfile.hpp"
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <limits>
#include <sstream>
#include <string>
namespace {
struct ground_of_line {
std::vector<double> chainages, heights, tolerances, reaches;
};
ground_of_line read_ground(std::string const &Name) {
ground_of_line result;
std::ifstream file{std::string{EU07_UNIT_TESTS_DATA} + "/" + Name};
for (std::string row; std::getline(file, row);) {
if (row.empty() || row.front() == '#')
continue;
std::istringstream values{row};
std::string chainage, height, tolerance, reach;
values >> chainage >> height >> tolerance >> reach;
result.chainages.push_back(std::strtod(chainage.c_str(), nullptr));
result.heights.push_back(std::strtod(height.c_str(), nullptr));
result.tolerances.push_back(std::strtod(tolerance.c_str(), nullptr));
result.reaches.push_back(std::strtod(reach.c_str(), nullptr));
}
return result;
}
// the real ground of a line, which the fit took under a field past a viaduct
ground_of_line past_viaduct() {
return read_ground("fit_past_viaduct.txt");
}
// a route of the editor as the selftest profiledump writes it: the tracks sampled, the ends joined, the switches, the norms
struct route_dump {
ground_of_line ground;
profile::context context;
profile::line settings;
};
route_dump read_route(std::string const &Name) {
route_dump result;
std::ifstream file{std::string{EU07_UNIT_TESTS_DATA} + "/" + Name};
for (std::string row; std::getline(file, row);) {
std::istringstream values{row};
std::string kind;
values >> kind;
auto &context{result.context};
if (kind == "S") {
double chainage{0.0}, height{0.0};
values >> chainage >> height;
result.ground.chainages.push_back(chainage);
result.ground.heights.push_back(height);
}
else if (kind == "C")
values >> context.length >> context.start_joined >> context.start_elevation >> context.start_grade >> context.end_joined >> context.end_elevation >> context.end_grade;
else if (kind == "Z") {
profile::context::zone zone;
values >> zone.from >> zone.to;
context.switches.push_back(zone);
}
else if (kind == "H") {
profile::context::zone zone;
values >> zone.from >> zone.to;
context.humps.push_back(zone);
}
else if (kind == "F") {
std::pair<double, double> fixed;
values >> fixed.first >> fixed.second;
context.fixed.push_back(fixed);
}
else if (kind == "L") {
auto &line{result.settings};
values >> line.speed >> line.norms.grade_max >> line.norms.grade_switch_max >> line.norms.radius_factor >> line.norms.radius_min >> line.norms.curve_threshold >> line.norms.element_min >> line.norms.fixed_tolerance >> line.join_start >> line.join_end;
}
}
return result;
}
// the tracks of a line moved by the grade lines shared: a design laid anew onto them, as profile_refit_stored lays it
profile::line refit(ground_of_line const &Ground, profile::context const &Context = {}, profile::line const &Settings = {}) {
auto context{Context};
if (context.length <= 0.0)
context.length = Ground.chainages.back();
std::vector<double> const tolerances(Ground.chainages.size(), 0.005);
std::vector<double> const reaches(Ground.chainages.size(), 100.0);
profile::ground_fit options;
options.tolerance = 0.01;
options.grade_max = 50.0;
options.humps = profile::humps(Ground.chainages, Ground.heights, context, options.tolerance);
options.hump_radius = 300.0;
return profile::fit_ground(Ground.chainages, Ground.heights, context, Settings, options, tolerances, reaches);
}
double worst_departure(profile::line const &Line, ground_of_line const &Ground) {
double worst{0.0};
for (std::size_t i = 0; i < Ground.chainages.size(); ++i)
worst = std::max(worst, std::abs(profile::elevation(Line, Ground.chainages[i]) - Ground.heights[i]));
return worst;
}
profile::line fit(ground_of_line const &Ground) {
profile::context context;
context.length = Ground.chainages.back();
profile::ground_fit options;
options.tolerance = 0.15;
options.grade_max = std::numeric_limits<double>::max();
options.follow_length = 60.0;
options.follow_height = 4.0;
options.follow_steepest = 100.0;
options.follow_tolerance = 0.05;
return profile::fit_ground(Ground.chainages, Ground.heights, context, profile::line{}, options, Ground.tolerances, Ground.reaches);
}
} // namespace
TEST_CASE("ground fit: a line held down on a viaduct comes back to the field before its loose end") {
auto const ground{past_viaduct()};
REQUIRE(ground.chainages.size() > 300);
auto const line{fit(ground)};
REQUIRE(line.points.size() >= 2);
auto const end{ground.chainages.back()};
// the field lies at 79.9 to 80.2: no going on under it at the grade the line took on the viaduct
CHECK(profile::elevation(line, end) > 79.5);
CHECK(profile::elevation(line, end - 100.0) > 79.5);
}
TEST_CASE("ground fit: the same off a loose start") {
auto ground{past_viaduct()};
REQUIRE(ground.chainages.size() > 300);
auto const end{ground.chainages.back()};
for (auto &chainage : ground.chainages)
chainage = end - chainage;
std::reverse(ground.chainages.begin(), ground.chainages.end());
std::reverse(ground.heights.begin(), ground.heights.end());
std::reverse(ground.tolerances.begin(), ground.tolerances.end());
std::reverse(ground.reaches.begin(), ground.reaches.end());
auto const line{fit(ground)};
REQUIRE(line.points.size() >= 2);
CHECK(profile::elevation(line, 0.0) > 79.5);
CHECK(profile::elevation(line, 100.0) > 79.5);
}
TEST_CASE("ground fit: a design laid anew onto tracks bending gently into a sag keeps to them") {
// the tracks go from -6.6 to +5.8 per mille over some 100 m, as a curve of about 8 km: curves of the 4 km the norms ask for
// follow it only two or more of them, a straight between
auto const route{read_route("refit_sag.txt")};
auto const &ground{route.ground};
REQUIRE(ground.chainages.size() > 300);
REQUIRE(false == route.context.switches.empty());
auto const line{refit(ground, route.context, route.settings)};
REQUIRE(line.points.size() >= 2);
CHECK(worst_departure(line, ground) < 0.015);
// with nothing told of the route as well
CHECK(worst_departure(refit(ground), ground) < 0.015);
}

View File

@@ -0,0 +1,42 @@
#include "stdafx.h"
#include "doctest.h"
#include "editor/editorGroundFollow.hpp"
#include <cmath>
#include <limits>
namespace {
segment_data straight(double const From, double const To) {
segment_data piece;
piece.points[segment_data::point::start] = {From, 0.0, 0.0};
piece.points[segment_data::point::end] = {To, 0.0, 0.0};
return piece;
}
} // namespace
TEST_CASE("heights: from point to point the tracks meet at one height where a point is clicked just past a joint") {
// three tracks of 40 m, the grade breaking 3 m past the first joint and 2 m short of the second one, steeply
std::vector<segment_data> pieces{straight(0.0, 40.0), straight(40.0, 80.0), straight(80.0, 120.0)};
auto const unknown{std::numeric_limits<double>::quiet_NaN()};
ground_follow::follow_points(pieces, {{43.0, -5.0, 0.0}, {78.0, 3.0, 0.0}}, {0.0, unknown, 0.0, unknown});
REQUIRE(pieces.size() >= 3);
for (std::size_t i = 0; i + 1 < pieces.size(); ++i)
CHECK(pieces[i].points[segment_data::point::end].y == doctest::Approx(pieces[i + 1].points[segment_data::point::start].y).epsilon(1e-9));
CHECK(pieces.front().points[segment_data::point::start].y == doctest::Approx(0.0));
CHECK(pieces.back().points[segment_data::point::end].y == doctest::Approx(0.0));
}
TEST_CASE("heights: with no point between the ends the grade is even from one end to the other") {
std::vector<segment_data> pieces{straight(0.0, 50.0), straight(50.0, 100.0)};
auto const unknown{std::numeric_limits<double>::quiet_NaN()};
ground_follow::follow_points(pieces, {}, {10.0, unknown, 12.0, unknown});
REQUIRE(pieces.size() == 2);
CHECK(pieces[0].points[segment_data::point::end].y == doctest::Approx(11.0));
CHECK(pieces[1].points[segment_data::point::start].y == doctest::Approx(11.0));
}

View File

@@ -0,0 +1,534 @@
#include "stdafx.h"
#include "doctest.h"
#include "vehicle.h"
#include "utilities/Globals.h"
#include "vehicle/odometer.h"
#include <filesystem>
#include <fstream>
#include <sstream>
// the odometer of a vehicle, kept between the sessions (eu07/maszyna#72): one state the cab's counters and the
// python screens show, saved in one store, taking over the states the python screens kept in their own files
namespace {
odometer::reading started(double const Km, odometer::origin const Source = odometer::origin::saved) {
odometer::reading reading;
reading.begin(Km, Source);
return reading;
}
odometer::reading run(double const Km, double const Metres) {
auto reading{started(Km)};
reading.run(Metres);
return reading;
}
// a directory of its own for a test, removed afterwards. it's made in the working directory of the tests (the build
// directory), not in the shared temporary one
struct scratch_directory {
std::filesystem::path path;
explicit scratch_directory(std::string const &Name) : path{std::filesystem::current_path() / ("eu07_unit_" + Name)} {
std::filesystem::remove_all(path);
std::filesystem::create_directories(path);
}
scratch_directory(scratch_directory const &) = delete;
scratch_directory &operator=(scratch_directory const &) = delete;
~scratch_directory() {
std::error_code error;
std::filesystem::remove_all(path, error);
}
};
void write_file(std::filesystem::path const &Path, std::string const &Content) {
std::filesystem::create_directories(Path.parent_path());
std::ofstream{Path, std::ios::binary} << Content;
}
} // namespace
TEST_CASE("odometer: a vehicle counts the distance it runs either way, as the session's counter does") {
for (auto const velocity : {40.0, -40.0}) {
CAPTURE(velocity);
test::vehicle vehicle{test::definition::load("wagon"), velocity};
vehicle->Odometer.begin(123456.0, odometer::origin::saved);
vehicle.run(10.0);
CHECK(vehicle->DistCounter > 0.05);
CHECK(vehicle->Odometer.km - 123456.0 == doctest::Approx(vehicle->DistCounter));
CHECK(vehicle->Odometer.start == 123456.0);
CHECK(vehicle->Odometer.moved());
}
}
TEST_CASE("odometer: the store reads back what it writes") {
odometer::store store;
store.record("EN76-012a", run(1361539.4283, 1000.0));
store.record("loco with spaces", run(42.0, 500.0));
CHECK(store.modified());
std::stringstream file;
store.write(file);
odometer::store read;
CHECK(read.read(file) == 2);
CHECK(read.find("EN76-012a").value() == doctest::Approx(1361540.4283));
CHECK(read.find("loco with spaces").value() == doctest::Approx(42.5));
CHECK_FALSE(read.find("EN76-012").has_value());
CHECK_FALSE(read.modified());
}
TEST_CASE("odometer: the store skips the comments and the malformed lines") {
std::stringstream file{"# comment\r\n"
"100.5 good\r\n"
"\n"
"nonsense\n"
"abc name\n"
"-5 negative\n"
"nan notanumber\n"
"7 \n"
"200\ttabbed\n"};
odometer::store store;
CHECK(store.read(file) == 2);
CHECK(store.find("good").value() == 100.5);
CHECK(store.find("tabbed").value() == 200.0);
CHECK(store.size() == 2);
}
TEST_CASE("odometer: a vehicle gets in the store once it has run, then it's kept up to date") {
odometer::store store;
SUBCASE("a vehicle which only stood doesn't get in") {
store.record("standing", started(5000.0, odometer::origin::guessed));
CHECK_FALSE(store.find("standing").has_value());
CHECK_FALSE(store.modified());
}
SUBCASE("one which ran does") {
store.record("running", run(5000.0, 250.0));
CHECK(store.find("running").value() == doctest::Approx(5000.25));
CHECK(store.modified());
}
SUBCASE("one already in the store follows its state, and an unchanged one doesn't make the store modified") {
std::stringstream file{"300 known\n"};
store.read(file);
store.record("known", started(300.0));
CHECK_FALSE(store.modified());
store.record("known", run(300.0, 1000.0));
CHECK(store.find("known").value() == doctest::Approx(301.0));
CHECK(store.modified());
store.saved();
CHECK_FALSE(store.modified());
}
SUBCASE("a nameless vehicle doesn't") {
store.record("", run(1.0, 1000.0));
CHECK(store.size() == 0);
}
}
TEST_CASE("odometer: the state the python screens kept is read") {
auto const legacy = [](std::string const &Content) {
std::stringstream file{Content};
return odometer::read_legacy(file);
};
// written as python's str() of a float
CHECK(legacy("1361539.4283109533").value() == doctest::Approx(1361539.4283109533));
CHECK(legacy("170650.0\n").value() == 170650.0);
CHECK(legacy(" 5000 ").value() == 5000.0);
CHECK_FALSE(legacy("").has_value());
CHECK_FALSE(legacy("12 km").has_value());
CHECK_FALSE(legacy("inf").has_value());
}
TEST_CASE("odometer: the state starts from the store, else the python screens' file, else a guess") {
scratch_directory directory{"odometer_legacy"};
// the python screens dropped the last letter of the vehicle name: the units of the EN76 shared the file
write_file(directory.path / "kilometry" / "EN76-012_przebieg.txt", "1361539.5");
std::stringstream file{"2000 EN76-012b\n"};
odometer::store store;
store.read(file);
auto const saved{odometer::starting_state(store, "EN76-012b", directory.path)};
CHECK(saved.source == odometer::origin::saved);
CHECK(saved.km == 2000.0);
auto const legacy{odometer::starting_state(store, "EN76-012a", directory.path)};
CHECK(legacy.source == odometer::origin::legacy);
CHECK(legacy.km == 1361539.5);
CHECK(legacy.start == legacy.km);
auto const guessed{odometer::starting_state(store, "SM42-001", directory.path)};
CHECK(guessed.source == odometer::origin::guessed);
CHECK(guessed.km == odometer::guessed_state("SM42-001"));
CHECK_FALSE(guessed.moved());
// an unreadable legacy file is no state
write_file(directory.path / "kilometry" / "ET22-100_przebieg.txt", "");
CHECK(odometer::starting_state(store, "ET22-100a", directory.path).source == odometer::origin::guessed);
}
TEST_CASE("odometer: a guessed state is the same for the same vehicle, in range") {
for (auto const *name : {"", "a", "EN57-1001ra", "ET22-100", "SM42-001"}) {
CAPTURE(name);
auto const state{odometer::guessed_state(name)};
CHECK(state == odometer::guessed_state(name));
CHECK(state >= 10000.0);
CHECK(state < 500000.0);
}
CHECK(odometer::guessed_state("ET22-100") != odometer::guessed_state("ET22-101"));
}
TEST_CASE("odometer: the cab's counter offset replaces only a guessed state, the distance run kept") {
CHECK(odometer::counter_seed(101532.f, 1.f).value() == 101532.0);
CHECK(odometer::counter_seed(1015320.f, 10.f).value() == doctest::Approx(101532.0));
CHECK_FALSE(odometer::counter_seed(0.f, 1.f).has_value());
CHECK_FALSE(odometer::counter_seed(100.f, 0.f).has_value());
CHECK_FALSE(odometer::counter_seed(-100.f, 1.f).has_value());
SUBCASE("guessed") {
auto reading{started(33333.0, odometer::origin::guessed)};
reading.run(2000.0);
reading.seed(101532.0);
CHECK(reading.source == odometer::origin::counter);
CHECK(reading.start == 101532.0);
CHECK(reading.km == doctest::Approx(101534.0));
// the next cab load doesn't seed it again
reading.seed(5.0);
CHECK(reading.start == 101532.0);
}
for (auto const source : {odometer::origin::saved, odometer::origin::legacy}) {
CAPTURE(static_cast<int>(source));
auto reading{started(777.0, source)};
reading.seed(101532.0);
CHECK(reading.km == 777.0);
CHECK(reading.source == source);
}
}
TEST_CASE("odometer: a state counted from a made up one is saved as such, the cab's counter still replaces it") {
scratch_directory directory{"odometer_guessed"};
auto const guess{odometer::guessed_state("EU07-424")};
// the vehicle runs 30 km with no cab loaded (the AI's, loose stock)
odometer::store first;
auto ai{odometer::starting_state(first, "EU07-424", directory.path)};
REQUIRE(ai.source == odometer::origin::guessed);
ai.run(30000.0);
first.record("EU07-424", ai);
std::stringstream file;
first.write(file);
CHECK(file.str().find("\n~") != std::string::npos);
odometer::store second;
REQUIRE(second.read(file) == 1);
CHECK(second.guessed("EU07-424"));
CHECK(second.find("EU07-424").value() == doctest::Approx(guess + 30.0));
auto player{odometer::starting_state(second, "EU07-424", directory.path)};
CHECK(player.source == odometer::origin::guessed);
CHECK(player.km == doctest::Approx(guess + 30.0));
SUBCASE("a cab whose counter has an offset loads it: the offset replaces the made up state, the 30 km kept") {
player.run(2000.0);
player.seed(101532.0);
CHECK(player.source == odometer::origin::counter);
CHECK(player.start == doctest::Approx(101562.0));
CHECK(player.km == doctest::Approx(101564.0));
// recorded as known, also when the counter shows less than the made up state did
second.record("EU07-424", player);
CHECK_FALSE(second.guessed("EU07-424"));
CHECK(second.find("EU07-424").value() == doctest::Approx(101564.0));
odometer::reading low;
low.begin(10.0, odometer::origin::counter);
odometer::store replaced;
std::stringstream guessedfile{"~400000 SM42-001\n"};
replaced.read(guessedfile);
replaced.record("SM42-001", low);
CHECK(replaced.find("SM42-001").value() == 10.0);
CHECK_FALSE(replaced.guessed("SM42-001"));
CHECK(replaced.modified());
}
SUBCASE("it runs with no cab again: it stays guessed") {
player.run(1000.0);
second.record("EU07-424", player);
CHECK(second.guessed("EU07-424"));
CHECK(second.find("EU07-424").value() == doctest::Approx(guess + 31.0));
}
}
TEST_CASE("odometer: the store reads the marker of a made up state, and skips it malformed") {
std::stringstream file{"~300 guessed one\n"
"~ nothing\n"
"~abc name\n"
"~-5 negative\n"
"~~5 twice\n"
"400 known\n"};
odometer::store store;
CHECK(store.read(file) == 2);
CHECK(store.find("guessed one").value() == 300.0);
CHECK(store.guessed("guessed one"));
CHECK_FALSE(store.guessed("known"));
CHECK_FALSE(store.guessed("missing"));
}
TEST_CASE("odometer: a recorded state is replaced only by a newer one") {
std::stringstream file{"500 known\n~600 guessed\n"};
odometer::store store;
store.read(file);
// a vehicle of this simulation counting from less than another simulation saved meanwhile
store.record("known", run(400.0, 50000.0));
CHECK(store.find("known").value() == 500.0);
CHECK_FALSE(store.modified());
// a larger one does, also when the vehicle hasn't run in this session
store.record("known", run(900.0, 0.0));
CHECK(store.find("known").value() == 900.0);
CHECK(store.modified());
// a guessed state doesn't replace a known one, even a larger one
odometer::reading guessed;
guessed.begin(5000.0, odometer::origin::guessed);
guessed.run(1000.0);
store.record("known", guessed);
CHECK(store.find("known").value() == 900.0);
CHECK_FALSE(store.guessed("known"));
// a larger guessed one replaces a guessed one
store.record("guessed", guessed);
CHECK(store.find("guessed").value() == doctest::Approx(5001.0));
CHECK(store.guessed("guessed"));
}
TEST_CASE("odometer: two simulations saving one file keep each other's states") {
scratch_directory directory{"odometer_merge"};
auto const path{directory.path / "eu07_odometers.txt"};
write_file(path, "1000 shared\n~20000 both guessed\n50 untouched\n");
auto const load = [&path]() {
odometer::store store;
std::ifstream input{path, std::ios::binary};
store.read(input);
return store;
};
auto first{load()};
auto second{load()};
auto const guessed = [](double const Km, double const Metres) {
odometer::reading reading;
reading.begin(Km, odometer::origin::guessed);
reading.run(Metres);
return reading;
};
// both run the shared vehicle, as two multiplayer simulations of the same train do, the first one further
first.record("shared", run(1000.0, 5000.0));
first.record("first only", run(70.0, 1000.0));
first.record("both guessed", guessed(20000.0, 3000.0));
second.record("shared", run(1000.0, 2000.0));
second.record("second only", run(80.0, 1000.0));
second.record("both guessed", guessed(20000.0, 1000.0));
REQUIRE(odometer::save(first, path));
CHECK_FALSE(first.modified());
REQUIRE(odometer::save(second, path));
auto const saved{load()};
CHECK(saved.size() == 5);
// the larger state of the shared vehicle, not the sum of the two: they counted the same run
CHECK(saved.find("shared").value() == doctest::Approx(1005.0));
CHECK(saved.find("first only").value() == doctest::Approx(71.0));
CHECK(saved.find("second only").value() == doctest::Approx(81.0));
CHECK(saved.find("both guessed").value() == doctest::Approx(20003.0));
CHECK(saved.guessed("both guessed"));
CHECK(saved.find("untouched").value() == 50.0);
// the second one now knows the states the first one saved, for the vehicles it loads later
CHECK(second.find("first only").value() == doctest::Approx(71.0));
SUBCASE("a known state saved by one replaces a guessed one of the other") {
odometer::reading seeded;
seeded.begin(100.0, odometer::origin::counter);
first.record("both guessed", seeded);
REQUIRE(odometer::save(first, path));
second.record("both guessed", guessed(20003.0, 5000.0));
REQUIRE(odometer::save(second, path));
auto const after{load()};
CHECK(after.find("both guessed").value() == 100.0);
CHECK_FALSE(after.guessed("both guessed"));
CHECK(after.find("second only").value() == doctest::Approx(81.0));
}
SUBCASE("nothing but the file is left in the directory") {
std::size_t files{0};
for (auto const &entry : std::filesystem::directory_iterator{directory.path}) {
CAPTURE(entry.path().string());
CHECK(entry.path().filename() == path.filename());
++files;
}
CHECK(files == 1);
}
SUBCASE("a store with nothing recorded since doesn't write") {
write_file(path, "1 replaced by hand\n");
REQUIRE(odometer::save(second, path));
CHECK(load().size() == 1);
}
}
TEST_CASE("odometer: a test run neither reads nor saves the player's store") {
if (false == Global.test.enabled)
CHECK(odometer::persistent());
// the autotests (--test) run the vehicles of the player's game, their runs aren't the player's
struct test_mode {
bool const was{Global.test.enabled};
test_mode() { Global.test.enabled = true; }
test_mode(test_mode const &) = delete;
test_mode &operator=(test_mode const &) = delete;
~test_mode() { Global.test.enabled = was; }
} const testmode;
// stops before the player's file is touched, if the gate is gone
REQUIRE_FALSE(odometer::persistent());
auto &states{odometer::states()};
states.record("tested", run(1000.0, 5000.0));
CHECK(states.find("tested").value() == doctest::Approx(1005.0));
CHECK(odometer::save());
// a save to the file would have cleared it
CHECK(states.modified());
}
TEST_CASE("odometer: the vehicles with a driver's cab are the ones with the driver's brake valve") {
// the definitions of the game: a locomotive, cab cars of units, a motor car of a unit without a cab, the wagons
struct expected {
char const *path;
bool cab;
};
for (auto const &[path, cab] : {expected{"4e_v1/4e", true}, expected{"sm42_v1/6d1", true}, expected{"en57_v1/5bgb", true},
expected{"21xm_v1/214ma", true}, expected{"impuls_v1/31we-a_pr", true},
expected{"ed72_v1/6bs-sa", false}, expected{"impuls_v1/31we-b_pr", false},
expected{"11xa_v2/93a", false}, expected{"bdhpumn_v3/bdhpumn", false},
expected{"430w_v2/430w", false}}) {
CAPTURE(path);
test::vehicle vehicle{test::definition::fiz(path)};
CHECK(vehicle->HasDriverCab() == cab);
}
test::vehicle wagon{test::definition::load("wagon")};
CHECK_FALSE(wagon->HasDriverCab());
test::vehicle locomotive{test::definition::load("wagon").set("Cntrl", "BrakeHandle", "FV4a")};
CHECK(locomotive->HasDriverCab());
}
TEST_CASE("odometer: only the vehicles with a driver's cab are recorded") {
odometer::store store;
SUBCASE("a wagon which ran doesn't get in") {
odometer::record(store, "wagon", false, run(5000.0, 1000.0));
CHECK_FALSE(store.find("wagon").has_value());
CHECK_FALSE(store.modified());
}
SUBCASE("a locomotive the AI ran before any cab loaded it gets in with its made up state, still replaceable") {
odometer::reading ai;
ai.begin(odometer::guessed_state("ET22-100"), odometer::origin::guessed);
ai.run(2000.0);
odometer::record(store, "ET22-100", true, ai);
CHECK(store.find("ET22-100").value() == doctest::Approx(ai.km));
CHECK(store.guessed("ET22-100"));
CHECK(store.modified());
}
SUBCASE("the state of a wagon already in the file stays as it was, and is written back") {
std::stringstream file{"300 old wagon\n"};
store.read(file);
odometer::record(store, "old wagon", false, run(300.0, 1000.0));
CHECK(store.find("old wagon").value() == 300.0);
CHECK_FALSE(store.modified());
std::stringstream written;
store.write(written);
odometer::store read;
CHECK(read.read(written) == 1);
CHECK(read.find("old wagon").value() == 300.0);
}
}
TEST_CASE("odometer: a vehicle driven without a driver's brake valve is recorded once a cab shows its odometer") {
// the draisines (DL2, DR2) have a cab and no BrakeHandle, so their type doesn't tell of the cab; the cab of the
// DL2 has a counter with an offset of 85
auto const definition{test::definition::fiz("dr2_v1/dr2")};
test::vehicle draisine{definition};
REQUIRE_FALSE(draisine->HasDriverCab());
scratch_directory directory{"odometer_cab_without_brake_valve"};
auto const file{directory.path / "eu07_odometers.txt"};
std::string const name{"DL2-001"};
// the state a vehicle of the name starts a session with, nothing kept by the python screens
auto const start = [&](odometer::store const &States) { return odometer::starting_state(States, name, directory.path, directory.path); };
odometer::store store;
draisine->Odometer = start(store);
REQUIRE(draisine->Odometer.source == odometer::origin::guessed);
SUBCASE("run by the AI, no cab loaded and no counter bound, it isn't recorded") {
draisine->Odometer.run(1500.0);
CHECK_FALSE(odometer::kept(draisine->HasDriverCab(), draisine->Odometer));
odometer::record(store, name, draisine->HasDriverCab(), draisine->Odometer);
CHECK_FALSE(store.find(name).has_value());
CHECK_FALSE(store.modified());
}
SUBCASE("its state seeded by the cab's counter is saved, read back, and counted on in the next session") {
// the cab loads: the counter seeds the state (TTrain, distcounter:)
draisine->Odometer.seed(odometer::counter_seed(85.f, 1.f).value());
REQUIRE(draisine->Odometer.source == odometer::origin::counter);
draisine->Odometer.run(2500.0);
CHECK(odometer::kept(draisine->HasDriverCab(), draisine->Odometer));
odometer::record(store, name, draisine->HasDriverCab(), draisine->Odometer);
CHECK(store.find(name).value() == doctest::Approx(87.5));
CHECK_FALSE(store.guessed(name));
REQUIRE(odometer::save(store, file));
// the next session: the vehicle starts from the saved state, not from the offset of the counter
odometer::store next;
{
std::ifstream input{file, std::ios::binary};
CHECK(next.read(input) == 1);
}
test::vehicle again{definition};
again->Odometer = start(next);
CHECK(again->Odometer.km == doctest::Approx(87.5));
CHECK(again->Odometer.source == odometer::origin::saved);
// the cab loads again: the counter has nothing to seed, a saved state isn't the counter's any more. the
// counter bound to the vehicle is what tells of its cab now
again->Odometer.seed(odometer::counter_seed(85.f, 1.f).value());
CHECK(again->Odometer.km == doctest::Approx(87.5));
CHECK(again->Odometer.source == odometer::origin::saved);
again->Odometer.shown = true;
again->Odometer.run(1000.0);
CHECK(odometer::kept(again->HasDriverCab(), again->Odometer));
odometer::record(next, name, again->HasDriverCab(), again->Odometer);
CHECK(next.find(name).value() == doctest::Approx(88.5));
CHECK(next.modified());
REQUIRE(odometer::save(next, file));
// a session the AI runs it in, with no cab loaded: the saved state stays as it is
test::vehicle ai{definition};
ai->Odometer = start(next);
CHECK(ai->Odometer.km == doctest::Approx(88.5));
ai->Odometer.run(4000.0);
odometer::record(next, name, ai->HasDriverCab(), ai->Odometer);
CHECK(next.find(name).value() == doctest::Approx(88.5));
CHECK_FALSE(next.modified());
}
SUBCASE("its cab loaded for a player, with no counter in it, it's recorded with its made up state") {
draisine->Odometer.shown = true;
draisine->Odometer.run(1500.0);
odometer::record(store, name, draisine->HasDriverCab(), draisine->Odometer);
CHECK(store.find(name).value() == doctest::Approx(draisine->Odometer.km));
CHECK(store.guessed(name));
}
SUBCASE("a state the session starts with doesn't carry the cab of an earlier one") {
draisine->Odometer.shown = true;
draisine->Odometer = start(store);
CHECK_FALSE(draisine->Odometer.shown);
}
}
TEST_CASE("odometer: the files of both kinds of python screens are read, by the name each used") {
scratch_directory directory{"odometer_legacy_screens"};
auto const vehicles{directory.path / "dynamic" / "elf_v1"};
auto const scripts{directory.path / "scripts"};
// the renderers of the units, next to the .mmd: state['name'][:-1], the cab cars of a unit share the file
write_file(vehicles / "kilometry" / "EN76-022_przebieg.txt", "250000.5");
CHECK(odometer::legacy_state(vehicles, "EN76-022a", scripts).value() == 250000.5);
CHECK(odometer::legacy_state(vehicles, "EN76-022d", scripts).value() == 250000.5);
// the shared screens of scripts/ (koliber_*): the whole name
write_file(scripts / "kilometry" / "EU07-424_przebieg.txt", "123456.0");
CHECK(odometer::legacy_state(vehicles, "EU07-424", scripts).value() == 123456.0);
auto const started{odometer::starting_state(odometer::store{}, "EU07-424", vehicles, scripts)};
CHECK(started.source == odometer::origin::legacy);
CHECK(started.km == 123456.0);
// neither
CHECK_FALSE(odometer::legacy_state(vehicles, "EU07-425", scripts).has_value());
CHECK_FALSE(odometer::legacy_state(vehicles, "", scripts).has_value());
}

View File

@@ -0,0 +1,246 @@
#include "stdafx.h"
#include "doctest.h"
#include "editor/editorSwitchCurve.hpp"
#include <algorithm>
#include <cmath>
#include <string>
namespace {
// a line every half metre: a straight, a transition curve from it to the arc of the radius, with a straight cant ramp along it, and
// the arc, each of the lengths given
std::vector<switch_curve::track_point> line(double const Straight, double const Transition, double const Arc, double const Radius, double const Cant) {
std::vector<switch_curve::track_point> points;
double heading{0.0};
auto const curvature = [&](double const S) { return S <= Straight ? 0.0 : S <= Straight + Transition ? (S - Straight) / Transition / Radius : 1.0 / Radius; };
auto const cant = [&](double const S) { return S <= Straight ? 0.0 : S <= Straight + Transition ? Cant * (S - Straight) / Transition : Cant; };
for (int k = 0; k * 0.5 <= Straight + Transition + Arc + 1e-9; ++k) {
auto const s{k * 0.5};
if (s > 0.0)
heading += 0.5 * (curvature(s - 0.5) + curvature(s)) * 0.5;
points.push_back({s, heading, cant(s)});
}
return points;
}
// the tracks of a switch Length long laid into the line from the station: the main one along it, the diverging one turning off it
// to the side by the curvature of the basic switch
std::pair<std::vector<switch_curve::track_point>, std::vector<switch_curve::track_point>> laid(std::vector<switch_curve::track_point> const &Line, double const From, double const Length, double const Radius, int const Side) {
std::vector<switch_curve::track_point> main;
std::vector<switch_curve::track_point> branch;
auto const first{std::lower_bound(Line.begin(), Line.end(), From, [](auto const &Point, double const Value) { return Point.station < Value; })};
for (auto point{first}; point != Line.end() && point->station <= From + Length + 1e-9; ++point) {
auto const s{point->station - From};
main.push_back({s, point->heading - first->heading, 0.0});
branch.push_back({s, point->heading - first->heading + Side * s / Radius, 0.0});
}
return {main, branch};
}
bool says(std::vector<std::string> const &Lines, char const *Text) {
return std::any_of(Lines.begin(), Lines.end(), [&](std::string const &Line) { return Line.find(Text) != std::string::npos; });
}
} // namespace
TEST_CASE("switch on a curve: the curvatures of its tracks on a transition curve, read the way the line turns") {
auto const track{line(100.0, 120.0, 200.0, 1000.0, 60.0)};
auto const [main, branch] {laid(track, 150.0, 30.0, 500.0, -1)};
auto const report{switch_curve::check(main, branch, track, 150.0, 180.0, 500.0, 12.0)};
CHECK(report.curved);
CHECK(report.transition);
CHECK(report.main_start == doctest::Approx(51.0 / 120.0 / 1000.0).epsilon(0.02));
CHECK(report.main_end == doctest::Approx(79.0 / 120.0 / 1000.0).epsilon(0.02));
// turning off to the outside of the curve: against it all along, the case KZW I
CHECK(report.branch_start < 0.0);
CHECK(report.branch_end < 0.0);
CHECK(false == says(report.warnings, "KZW II"));
// laid on the ramp, the cant changing under it
CHECK(report.cant_start == doctest::Approx(25.0).epsilon(0.02));
CHECK(report.cant_end == doctest::Approx(40.0).epsilon(0.02));
CHECK(says(report.warnings, "The cant changes within the switch"));
}
TEST_CASE("switch on a curve: the diverging track turning from one side to the other is the case KZW II") {
// a transition growing past the curvature of the basic switch along the switch
auto const track{line(100.0, 60.0, 100.0, 300.0, 0.0)};
auto const [main, branch] {laid(track, 125.0, 30.0, 500.0, -1)};
auto const report{switch_curve::check(main, branch, track, 125.0, 155.0, 500.0, 12.0)};
CHECK(report.branch_start < 0.0);
CHECK(report.branch_end > 0.0);
CHECK(says(report.warnings, "KZW II"));
}
TEST_CASE("switch on a curve: the ends of a cant ramp at the ends of the switch or 6 m off it") {
auto const track{line(100.0, 120.0, 200.0, 1000.0, 60.0)};
auto const ramps{switch_curve::ramp_ends(track)};
REQUIRE(ramps.size() == 2);
CHECK(ramps[0] == doctest::Approx(100.0).epsilon(0.01));
CHECK(ramps[1] == doctest::Approx(220.0).epsilon(0.01));
auto const at = [&](double const From) {
auto const [main, branch] {laid(track, From, 30.0, 500.0, 1)};
return switch_curve::check(main, branch, track, From, From + 30.0, 500.0, 12.0);
};
CHECK(says(at(210.0).warnings, "within the switch"));
CHECK(says(at(222.0).warnings, "6 m at least"));
CHECK(false == says(at(220.0).warnings, "within the switch"));
CHECK(says(at(220.0).notes, "at an end of the switch"));
CHECK(false == says(at(230.0).warnings, "cant ramp"));
// the start pressed near those places drawn to them
std::string what;
CHECK(switch_curve::snapped_start(ramps, 218.5, 30.0, 1, 3.0, &what) == doctest::Approx(220.0));
CHECK(what.find("starts at an end") != std::string::npos);
CHECK(switch_curve::snapped_start(ramps, 228.0, 30.0, 1, 3.0, &what) == doctest::Approx(226.0));
CHECK(what.find("6 m off") != std::string::npos);
CHECK(switch_curve::snapped_start(ramps, 72.0, 30.0, 1, 3.0, &what) == doctest::Approx(70.0));
CHECK(what.find("ends at an end") != std::string::npos);
CHECK(switch_curve::snapped_start(ramps, 160.0, 30.0, 1, 3.0, &what) == doctest::Approx(160.0));
CHECK(what.empty());
}
TEST_CASE("switch on a curve: one with a straight frog bent up to the frog, both tracks straight over it") {
auto const track{line(0.0, 1.0, 400.0, 1500.0, 0.0)};
for (auto const side : {1, -1}) {
CAPTURE(side);
auto [main, branch] {laid(track, 150.0, 27.0, 190.0, side)};
// the last 6 m of both straight, the diverging one with no curve of its own there either: the frog of the switch
auto const frog{21.0};
auto const straighten = [&](std::vector<switch_curve::track_point> &Track) {
auto const at{std::find_if(Track.begin(), Track.end(), [&](auto const &Point) { return Point.station >= frog; })};
for (auto point{at}; point != Track.end(); ++point)
point->heading = at->heading;
};
straighten(main);
straighten(branch);
auto const report{switch_curve::check(main, branch, track, 150.0, 177.0, 190.0, 9.0, 27.0 - frog)};
CHECK(report.curved);
// the curvature of the bent part only: no transition curve under it, the diverging track turning one way all along
CHECK_FALSE(report.transition);
CHECK(false == says(report.warnings, "KZW II"));
CHECK(says(report.warnings, "Bent up to the frog"));
}
}
TEST_CASE("switch on a curve: none of 1:9.403 nor steeper than 1:9 bent in the running and the main tracks, 1:9 itself is") {
auto const track{line(0.0, 1.0, 400.0, 1500.0, 0.0)};
auto const [main, branch] {laid(track, 150.0, 33.0, 300.0, 1)};
auto const banned = [&](double const Ratio) {
CAPTURE(Ratio);
auto const report{switch_curve::check(main, branch, track, 150.0, 183.0, 300.0, Ratio)};
REQUIRE(report.curved);
return says(report.warnings, "(11.4 pkt 4)");
};
// 1:9 of the catalogue and as read off the angle of the tracks
CHECK_FALSE(banned(9.0));
CHECK_FALSE(banned(8.998));
CHECK_FALSE(banned(9.002));
CHECK(banned(9.403));
CHECK(banned(9.41));
CHECK_FALSE(banned(9.51));
CHECK_FALSE(banned(10.0));
CHECK_FALSE(banned(12.0));
CHECK(banned(7.5));
CHECK(banned(6.6));
CHECK(banned(4.8));
}
namespace {
// a track of one curvature from its start, heading as given there, a point every half metre
std::vector<switch_curve::track_point> arc(double const Length, double const Heading, double const Curvature) {
std::vector<switch_curve::track_point> points;
for (int k = 0; k * 0.5 <= Length + 1e-9; ++k)
points.push_back({k * 0.5, Heading + Curvature * (k * 0.5), 0.0});
return points;
}
// a slip of 1:9 with the slip curves of R 190 m bent onto the line from the station on: the tracks through it with the curvature of the
// line, the slip curves with theirs plus the one of the line, one turning as the line does, the other against it
switch_curve::slip_report bent_slip(std::vector<switch_curve::track_point> const &Line, double const From, double const Curvature) {
auto const angle{std::atan(1.0 / 9.0)};
auto const half{16.6};
auto const tracks{std::vector{arc(2.0 * half, 0.0, Curvature), arc(2.0 * half, angle, Curvature * std::cos(angle))}};
auto const curves{std::vector{arc(190.0 * angle, 0.0, 1.0 / 190.0 + Curvature), arc(190.0 * angle, angle, -1.0 / 190.0 + Curvature)}};
return switch_curve::check_slip(tracks, curves, Line, From, From + 2.0 * half);
}
} // namespace
TEST_CASE("slip bent into a curve: in a side track only, its slip curve bent the way of the curve no sharper than a side track takes") {
auto const sharp{bent_slip(line(0.0, 0.0, 400.0, 800.0, 0.0), 150.0, 1.0 / 800.0)};
CHECK(sharp.curved);
CHECK(says(sharp.warnings, "11.4 pkt 4b"));
CHECK(sharp.first == doctest::Approx(1.0 / 800.0).epsilon(0.02));
CHECK(sharp.second == doctest::Approx(std::cos(std::atan(1.0 / 9.0)) / 800.0).epsilon(0.02));
REQUIRE(sharp.curves.size() == 2);
// 1/190 + 1/800: R 153.5 m, 1/190 - 1/800: R 249.2 m
CHECK(1.0 / sharp.curves[0] == doctest::Approx(153.5).epsilon(0.01));
CHECK(1.0 / sharp.curves[1] == doctest::Approx(249.2).epsilon(0.01));
CHECK(says(sharp.warnings, "R 154 m, below the least 180 m"));
CHECK(false == says(sharp.warnings, "R 249 m"));
CHECK(false == says(sharp.warnings, "9.7 pkt 12"));
// R 4000 m: the slip curve of 1/190 + 1/4000, R 181.4 m, still within the side tracks
auto const gentle{bent_slip(line(0.0, 0.0, 400.0, 4000.0, 0.0), 150.0, 1.0 / 4000.0)};
CHECK(gentle.curved);
CHECK(says(gentle.warnings, "11.4 pkt 4b"));
CHECK(false == says(gentle.warnings, "table 9.2"));
CHECK(gentle.notes.empty());
// one on a straight is no bent one
auto const straight{bent_slip(line(400.0, 0.0, 0.0, 1000.0, 0.0), 150.0, 0.0)};
CHECK_FALSE(straight.curved);
CHECK(straight.warnings.empty());
}
TEST_CASE("slip bent into a curve: the cant of the side track, a track through it turning from one side to the other") {
// the cant the same over it, none recommended in a side track though
auto const canted{bent_slip(line(0.0, 0.0, 400.0, 1000.0, 30.0), 150.0, 1.0 / 1000.0)};
CHECK(canted.cant_start == doctest::Approx(30.0));
CHECK(canted.cant_end == doctest::Approx(30.0));
CHECK(false == says(canted.warnings, "The cant changes"));
CHECK(says(canted.notes, "9.3 pkt 5"));
// a reverse curve under it
auto const curve{line(0.0, 0.0, 400.0, 1000.0, 0.0)};
auto first{arc(33.2, 0.0, 1.0 / 1000.0)};
for (auto &point : first)
if (point.station > 16.6)
point.heading = 16.6 / 1000.0 - (point.station - 16.6) / 1000.0;
auto const angle{std::atan(1.0 / 9.0)};
auto const report{switch_curve::check_slip({first, arc(33.2, angle, 1.0 / 1000.0)}, {arc(21.0, 0.0, 1.0 / 190.0)}, curve, 150.0, 183.2)};
CHECK(says(report.warnings, "9.7 pkt 12"));
}
TEST_CASE("switch exit: a curve right behind a straight frog, its sudden changes of the cant deficiency apart or together") {
double const sw{1.0 / 190.0};
// R 190 on behind a frog straight for 6.09 m, at 40 km/h: apart, 99 mm at the end, within the 130 mm of table 9.15
auto const same{switch_curve::check_exit(sw, 6.092, {{40.0, sw, sw}}, 40.0)};
CHECK(same.apart == doctest::Approx(6.092));
CHECK(same.element == doctest::Approx(6.0));
CHECK(same.change == doctest::Approx(99.4).epsilon(0.01));
CHECK(same.warnings.empty());
// the other way behind a frog straight of 1.66 m only: together, 199 mm, over the 130 mm
auto const reverse{switch_curve::check_exit(sw, 1.662, {{40.0, -sw, -sw}}, 40.0)};
CHECK(reverse.apart == doctest::Approx(1.662));
CHECK(reverse.change == doctest::Approx(198.8).epsilon(0.01));
REQUIRE(reverse.warnings.size() == 1);
CHECK(says(reverse.warnings, "tables 9.15, 9.16"));
// the same way behind it: together the curvature hardly changes
CHECK(switch_curve::check_exit(sw, 1.662, {{40.0, sw, sw}}, 40.0).warnings.empty());
// a straight of 5 m laid on first: 6.66 m apart, the curve the other way alone, 99 mm
auto const later{switch_curve::check_exit(sw, 1.662, {{5.0, 0.0, 0.0}, {40.0, -sw, -sw}}, 40.0)};
CHECK(later.apart == doctest::Approx(6.662));
CHECK(later.warnings.empty());
// a sharp curve of R 100 alone: 189 mm
CHECK(says(switch_curve::check_exit(sw, 6.092, {{30.0, 0.01, 0.01}}, 40.0).warnings, "table 9.15"));
// a transition out of the frog straight: no sudden change behind it
CHECK(switch_curve::check_exit(sw, 1.662, {{20.0, 0.0, -sw}, {20.0, -sw, -sw}}, 40.0).warnings.empty());
// the curve of a switch with a curved frog going on: nothing of the switch to judge
auto const on{switch_curve::check_exit(1.0 / 300.0, 0.0, {{30.0, 1.0 / 300.0, 1.0 / 300.0}}, 50.0)};
CHECK(on.apart < 0.0);
CHECK(on.warnings.empty());
}

View File

@@ -24,3 +24,11 @@ TEST_CASE("win1250: what win1250_to_utf8 gives is valid utf-8") {
CHECK(decoded.size() == kWin1250.size());
CHECK(decoded[12] == U'\x0142');
}
TEST_CASE("win1250: utf-8 written back the way a scenery file has it") {
CHECK(utf8_to_win1250("Bia\xC5\x82" "a Podlaska") == "Bia\xB3" "a Podlaska");
CHECK(utf8_to_win1250(kUtf8) == kWin1250);
CHECK(win1250_to_utf8(utf8_to_win1250(kUtf8)) == kUtf8);
// the letters other than the polish ones turn into question marks
CHECK(utf8_to_win1250("\xC3\xA9t\xC3\xA9") == "?t?");
}