From 30266e72d24375b42af6f256bc86d667a8646ce3 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Mon, 7 Sep 2020 18:47:48 +0200 Subject: [PATCH] Add better ferry handling --- AspectedRouting.Test/FunctionsTest.cs | 26 ++++++++++++++++-- AspectedRouting.sln.DotSettings.user | 5 ++-- Profiles/bicycle/bicycle.json | 1 + Profiles/general/ferry_speed.json | 35 +++++++++++++++++++++++++ Profiles/general/ferry_speed.test.csv | 5 ++++ Profiles/general/legal_maxspeed_be.json | 7 +---- 6 files changed, 69 insertions(+), 10 deletions(-) create mode 100644 Profiles/general/ferry_speed.json create mode 100644 Profiles/general/ferry_speed.test.csv diff --git a/AspectedRouting.Test/FunctionsTest.cs b/AspectedRouting.Test/FunctionsTest.cs index 6893597..35fb7d5 100644 --- a/AspectedRouting.Test/FunctionsTest.cs +++ b/AspectedRouting.Test/FunctionsTest.cs @@ -335,11 +335,33 @@ namespace AspectedRouting.Test var exprs = new[] {p0, p1}; var newTypes = exprs.SpecializeToCommonTypes(out var _); - Assert.Single( newTypes); + Assert.Single(newTypes); exprs = new[] {p1, p0}; newTypes = exprs.SpecializeToCommonTypes(out var _); - Assert.Single( newTypes); + Assert.Single(newTypes); } + + + [Fact] + public void ParseFunction_InvalidInput_NullOutput() + { + var f = Funcs.Parse; + var c = new Context(); + var result = f.Evaluate(c, new Constant("abc")); + + Assert.Null(result); + } + + [Fact] + public void ParseFunction_Duration_TotalMinutes() + { + var f = Funcs.Parse; + var c = new Context(); + var result = f.Evaluate(c, new Constant("01:15")); + + Assert.Equal(75, result); + } + } } \ No newline at end of file diff --git a/AspectedRouting.sln.DotSettings.user b/AspectedRouting.sln.DotSettings.user index be5cd77..3afa92e 100644 --- a/AspectedRouting.sln.DotSettings.user +++ b/AspectedRouting.sln.DotSettings.user @@ -1,4 +1,5 @@  - <SessionState ContinuousTestingIsOn="False" ContinuousTestingMode="0" FrameworkVersion="{x:Null}" IsLocked="False" Name="All tests from &lt;AspectedRouting.Test&gt;" PlatformMonoPreference="{x:Null}" PlatformType="{x:Null}" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> + <SessionState ContinuousTestingIsOn="False" ContinuousTestingMode="0" FrameworkVersion="{x:Null}" IsLocked="False" Name="ParseFunction_Duration_TotalMinutes" PlatformMonoPreference="{x:Null}" PlatformType="{x:Null}" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Project Location="/home/pietervdvn/werk/AspectedRouting/AspectedRouting.Test" Presentation="&lt;AspectedRouting.Test&gt;" /> -</SessionState> \ No newline at end of file +</SessionState> + \ No newline at end of file diff --git a/Profiles/bicycle/bicycle.json b/Profiles/bicycle/bicycle.json index 29294ac..528ca1b 100644 --- a/Profiles/bicycle/bicycle.json +++ b/Profiles/bicycle/bicycle.json @@ -22,6 +22,7 @@ "$min": [ "$legal_maxspeed_be", "#maxspeed", + "$ferry_speed", { "$multiply": [ "#defaultSpeed", diff --git a/Profiles/general/ferry_speed.json b/Profiles/general/ferry_speed.json new file mode 100644 index 0000000..0ac23dd --- /dev/null +++ b/Profiles/general/ferry_speed.json @@ -0,0 +1,35 @@ +{ + "name": "ferry_speed", + "description": "Gives the expected speed for a ferry. This includes the time needed to board and the expected waiting time (if duration is present). This uses the tag '_length', which is expected to be added by the preprocessing-step.", + "unit": "km/h", + "value": { + "$ifDotted": { + "route": { + "ferry": "yes" + } + }, + "then": { + "#": "(length (m) / (duration (minutes) + 5 minutes slack)) * 0.06 minutes/kilometer", + "$multiply": [ + { + "#": "The default value is chosen so that it defaults to 1km/h", + "$default": 83.33333333333333, + "value": { + "_length": "$parse" + } + }, + { + "$inv": { + "$sum": [ + { + "duration": "$parse" + }, + 5 + ] + } + }, + 0.06 + ] + } + } +} \ No newline at end of file diff --git a/Profiles/general/ferry_speed.test.csv b/Profiles/general/ferry_speed.test.csv new file mode 100644 index 0000000..b4e2d8b --- /dev/null +++ b/Profiles/general/ferry_speed.test.csv @@ -0,0 +1,5 @@ +expected,route,duration,interval,_length,comment +1,ferry,,, +2,ferry,25,,1000,25 minutes duration + 5 minutes to get on is 30 minutes total for one kilometer -> 2 km/h +4,ferry,10,,1000,10 minutes duration + 5 minutes to get on is 15 minutes total for one kilometer -> 4km/h +null,,,,Ferry is not set diff --git a/Profiles/general/legal_maxspeed_be.json b/Profiles/general/legal_maxspeed_be.json index 4ae6a32..f3216e8 100644 --- a/Profiles/general/legal_maxspeed_be.json +++ b/Profiles/general/legal_maxspeed_be.json @@ -7,8 +7,7 @@ "$firstMatchOf": [ "maxspeed", "designation", - "highway", - "route" + "highway" ], "value": { "maxspeed": "$parse", @@ -37,10 +36,6 @@ }, "designation": { "towpath": 30 - }, - "route": { - "#": "A ferry often goes once every half-an-hour, to cross like 100m; in other words: 0.2km/h", - "ferry": 0.2 } } }