From c5b7bf8815b4bf7030b448e95e15dafb2324cf5d Mon Sep 17 00:00:00 2001
From: Michael Krisper <michael.krisper@tugraz.at>
Date: Fri, 8 Jan 2016 11:30:22 +0100
Subject: [PATCH] tests for loss map range check

---
 LicenceHeader/header.txt                      |  4 +-
 .../Simulation/LossMapRangeValidationTest.cs  | 97 +++++++++++++++++++
 VectoCoreTest/VectoCoreTest.csproj            |  1 +
 3 files changed, 100 insertions(+), 2 deletions(-)
 create mode 100644 VectoCoreTest/Models/Simulation/LossMapRangeValidationTest.cs

diff --git a/LicenceHeader/header.txt b/LicenceHeader/header.txt
index 4ad4eb3d90..e5112fb658 100644
--- a/LicenceHeader/header.txt
+++ b/LicenceHeader/header.txt
@@ -1,11 +1,11 @@
 /*
-* Copyright 2015 European Union
+* Copyright 2016 European Union
 *
 * Licensed under the EUPL (the "Licence");
 * You may not use this work except in compliance with the Licence.
 * You may obtain a copy of the Licence at:
 *
-* http://ec.europa.eu/idabc/eupl5
+* http://ec.europa.eu/idabc/eupl
 *
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the Licence is distributed on an "AS IS" basis,
diff --git a/VectoCoreTest/Models/Simulation/LossMapRangeValidationTest.cs b/VectoCoreTest/Models/Simulation/LossMapRangeValidationTest.cs
new file mode 100644
index 0000000000..4f48bcc484
--- /dev/null
+++ b/VectoCoreTest/Models/Simulation/LossMapRangeValidationTest.cs
@@ -0,0 +1,97 @@
+/*
+* Copyright 2015 European Union
+*
+* Licensed under the EUPL (the "Licence");
+* You may not use this work except in compliance with the Licence.
+* You may obtain a copy of the Licence at:
+*
+* http://ec.europa.eu/idabc/eupl
+*
+* Unless required by applicable law or agreed to in writing, software 
+* distributed under the Licence is distributed on an "AS IS" basis,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the Licence for the specific language governing permissions and 
+* limitations under the Licence.
+*/
+
+using System;
+using System.Linq;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using TUGraz.VectoCore.Exceptions;
+using TUGraz.VectoCore.Models.Simulation.Impl;
+using TUGraz.VectoCore.Models.SimulationComponent.Data;
+using TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox;
+using TUGraz.VectoCore.Tests.Utils;
+
+namespace TUGraz.VectoCore.Tests.Models.Simulation
+{
+	[TestClass]
+	public class LossMapRangeValidationTest
+	{
+		public const string ShiftPolygonFile = @"TestData\Components\ShiftPolygons.vgbs";
+		public const string AccelerationFile = @"TestData\Components\Truck.vacc";
+		public const string EngineFile = @"TestData\Components\40t_Long_Haul_Truck.veng";
+		public const string AxleGearLossMap = @"TestData\Components\Axle 40t Truck.vtlm";
+		public const string GearboxIndirectLoss = @"TestData\Components\Indirect Gear.vtlm";
+		public const string GearboxDirectLoss = @"TestData\Components\Direct Gear.vtlm";
+		public const string GearboxInsufficient = @"TestData\Components\Insufficient Gear.vtlm";
+		public const string GearboxShiftPolygonFile = @"TestData\Components\ShiftPolygons.vgbs";
+		public const string GearboxFullLoadCurveFile = @"TestData\Components\Gearbox.vfld";
+
+		[TestMethod]
+		public void LossMapValid()
+		{
+			var gearboxData = CreateGearboxData(GearboxDirectLoss, GearboxIndirectLoss);
+			var engineData = MockSimulationDataFactory.CreateEngineDataFromFile(EngineFile);
+			var axleGearData = CreateAxleGearData(AxleGearLossMap);
+			SimulatorFactory.CheckLossMapRangeForFullLoadCurves(gearboxData, engineData, axleGearData);
+		}
+
+		[TestMethod]
+		public void LossMapInvalidAxle()
+		{
+			var gearboxData = CreateGearboxData(GearboxDirectLoss, GearboxIndirectLoss);
+			var engineData = MockSimulationDataFactory.CreateEngineDataFromFile(EngineFile);
+			var axleGearData = CreateAxleGearData(GearboxIndirectLoss);
+			AssertHelper.Exception<VectoException>(() => {
+				SimulatorFactory.CheckLossMapRangeForFullLoadCurves(gearboxData, engineData, axleGearData);
+			});
+		}
+
+		[TestMethod]
+		public void LossMapInvalid()
+		{
+			var gearboxData = CreateGearboxData(GearboxInsufficient, GearboxInsufficient);
+			var engineData = MockSimulationDataFactory.CreateEngineDataFromFile(EngineFile);
+			var axleGearData = CreateAxleGearData(AxleGearLossMap);
+			SimulatorFactory.CheckLossMapRangeForFullLoadCurves(gearboxData, engineData, axleGearData);
+		}
+
+
+		private static GearboxData CreateGearboxData(string directlossMap, string indirectLossMap)
+		{
+			var ratios = new[] { 14.93, 11.64, 9.02, 7.04, 5.64, 4.4, 3.39, 2.65, 2.05, 1.6, 1.28, 1.0 };
+			return new GearboxData {
+				Gears = ratios.Select((ratio, i) =>
+					Tuple.Create((uint)i,
+						new GearData {
+							FullLoadCurve = FullLoadCurve.ReadFromFile(GearboxFullLoadCurveFile),
+							LossMap = TransmissionLossMap.ReadFromFile(ratio != 1.0 ? directlossMap : indirectLossMap, ratio,
+								string.Format("Gear {0}", i)),
+							Ratio = ratio,
+							ShiftPolygon = ShiftPolygon.ReadFromFile(ShiftPolygonFile)
+						}))
+					.ToDictionary(k => k.Item1 + 1, v => v.Item2)
+			};
+		}
+
+		private static AxleGearData CreateAxleGearData(string lossMap)
+		{
+			const double ratio = 2.59;
+			return new AxleGearData {
+				Ratio = ratio,
+				LossMap = TransmissionLossMap.ReadFromFile(lossMap, ratio, "AxleGear")
+			};
+		}
+	}
+}
\ No newline at end of file
diff --git a/VectoCoreTest/VectoCoreTest.csproj b/VectoCoreTest/VectoCoreTest.csproj
index 7c2f5886aa..b651c3762c 100644
--- a/VectoCoreTest/VectoCoreTest.csproj
+++ b/VectoCoreTest/VectoCoreTest.csproj
@@ -77,6 +77,7 @@
     </Compile>
     <Compile Include="Integration\DeclarationReportTest.cs" />
     <Compile Include="Models\Simulation\FactoryTest.cs" />
+    <Compile Include="Models\Simulation\LossMapRangeValidationTest.cs" />
     <Compile Include="Reports\SumWriterTest.cs" />
     <Compile Include="Utils\GraphWriter.cs" />
     <Compile Include="Integration\EngineOnlyCycle\EngineOnlyCycleTest.cs" />
-- 
GitLab