From e71d620d338d70cdb3018b30870e48c64c2fc5f6 Mon Sep 17 00:00:00 2001
From: Markus Quaritsch <markus.quaritsch@tugraz.at>
Date: Wed, 19 Sep 2018 15:06:19 +0200
Subject: [PATCH] adding testcase for lookup of prediction interval ratio

---
 .../PredictionDurationLookupReader.cs         | 11 +++----
 VectoCore/VectoCore/VectoCore.csproj          |  2 ++
 .../ShiftstrategyParameterTests.cs            | 30 +++++++++++++++++++
 VectoCore/VectoCoreTest/VectoCoreTest.csproj  |  1 +
 4 files changed, 39 insertions(+), 5 deletions(-)
 create mode 100644 VectoCore/VectoCoreTest/Models/SimulationComponentData/ShiftstrategyParameterTests.cs

diff --git a/VectoCore/VectoCore/InputData/Reader/ShiftStrategy/PredictionDurationLookupReader.cs b/VectoCore/VectoCore/InputData/Reader/ShiftStrategy/PredictionDurationLookupReader.cs
index a9d7b69f5a..9905ab53af 100644
--- a/VectoCore/VectoCore/InputData/Reader/ShiftStrategy/PredictionDurationLookupReader.cs
+++ b/VectoCore/VectoCore/InputData/Reader/ShiftStrategy/PredictionDurationLookupReader.cs
@@ -1,4 +1,5 @@
 using System;
+using System.Collections.Generic;
 using System.Data;
 using System.IO;
 using System.Linq;
@@ -54,11 +55,11 @@ namespace TUGraz.VectoCore.InputData.Reader.ShiftStrategy
 			return new PredictionDurationLookup(
 				data.Rows.Cast<DataRow>()
 					.Select(
-						r => new PredictionDurationLookup.Entry() {
-							SpeedRatio = r.ParseDouble(Fields.SpeedRatio),
-							PredictionTimeRatio = r.ParseDouble(Fields.PredictionTimeRatio)
-						})
-					.OrderBy(x => x.SpeedRatio)
+						r => new KeyValuePair<double, double>(
+							r.ParseDouble(Fields.SpeedRatio),
+							r.ParseDouble(Fields.PredictionTimeRatio)
+						))
+					.OrderBy(x => x.Key)
 					.ToList());
 		}
 
diff --git a/VectoCore/VectoCore/VectoCore.csproj b/VectoCore/VectoCore/VectoCore.csproj
index 5333e84a47..7a91de004f 100644
--- a/VectoCore/VectoCore/VectoCore.csproj
+++ b/VectoCore/VectoCore/VectoCore.csproj
@@ -163,6 +163,7 @@
     <Compile Include="InputData\Reader\Impl\EngineeringModeVectoRunDataFactory.cs" />
     <Compile Include="InputData\Reader\Impl\EngineOnlyVectoRunDataFactory.cs" />
     <Compile Include="InputData\Reader\ShiftPolygonReader.cs" />
+    <Compile Include="InputData\Reader\ShiftStrategy\PredictionDurationLookupReader.cs" />
     <Compile Include="Models\Declaration\AuxDemandEntry.cs" />
     <Compile Include="Models\Declaration\AuxiliaryTypeHelper.cs" />
     <Compile Include="Models\Connector\Ports\IDriverDemandPort.cs" />
@@ -465,6 +466,7 @@
     <EmbeddedResource Include="Resources\XSD\VectoOutputManufacturer.0.6.xsd">
       <SubType>Designer</SubType>
     </EmbeddedResource>
+    <EmbeddedResource Include="Resources\Declaration\GearshiftParameters\PredictionTimeLookup.csv" />
     <None Include="Utils\VectoVersionCore.tt">
       <Generator>TextTemplatingFileGenerator</Generator>
       <LastGenOutput>VectoVersionCore.cs</LastGenOutput>
diff --git a/VectoCore/VectoCoreTest/Models/SimulationComponentData/ShiftstrategyParameterTests.cs b/VectoCore/VectoCoreTest/Models/SimulationComponentData/ShiftstrategyParameterTests.cs
new file mode 100644
index 0000000000..ddad73654f
--- /dev/null
+++ b/VectoCore/VectoCoreTest/Models/SimulationComponentData/ShiftstrategyParameterTests.cs
@@ -0,0 +1,30 @@
+using NUnit.Framework;
+using NUnit.Framework.Internal;
+using TUGraz.VectoCore.InputData.Reader.ShiftStrategy;
+using TUGraz.VectoCore.Models.Declaration;
+using TUGraz.VectoCore.Models.SimulationComponent.Data.ShiftStrategy;
+using TUGraz.VectoCore.Utils;
+
+namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData
+{
+	[TestFixture]
+	public class ShiftstrategyParameterTests
+	{
+
+		[TestCase(0.3, 1.0),
+		TestCase(0.8, 1.0),
+		TestCase(0.9, 0.5),
+		TestCase(1.5, 0.5),
+		TestCase(0.85, 0.75)
+		]
+		public void TestPredictionIntervalLookup(double speedRatio, double expected)
+		{
+			var lookup = PredictionDurationLookupReader.ReadFromStream(
+				RessourceHelper.ReadStream(
+					DeclarationData.DeclarationDataResourcePrefix + ".GearshiftParameters.PredictionTimeLookup.csv"));
+			var val = lookup.Lookup(speedRatio);
+
+			Assert.AreEqual(expected, val, 1e-6);
+		}
+	}
+}
diff --git a/VectoCore/VectoCoreTest/VectoCoreTest.csproj b/VectoCore/VectoCoreTest/VectoCoreTest.csproj
index a97a3edacd..b5f47043db 100644
--- a/VectoCore/VectoCoreTest/VectoCoreTest.csproj
+++ b/VectoCore/VectoCoreTest/VectoCoreTest.csproj
@@ -100,6 +100,7 @@
     <Compile Include="Models\Declaration\DataAdapter\DeclarationDataAdapterTest_Class2.cs" />
     <Compile Include="Models\Declaration\DataAdapter\DeclarationDataAdapterTest_Class9.cs" />
     <Compile Include="Models\Declaration\ShiftPolygonTest.cs" />
+    <Compile Include="Models\SimulationComponentData\ShiftstrategyParameterTests.cs" />
     <Compile Include="Models\SimulationComponentData\TorqueConverterDataTest.cs" />
     <Compile Include="Models\SimulationComponentData\ValidationTest.cs" />
     <Compile Include="Models\SimulationComponent\ATGearboxTest.cs" />
-- 
GitLab