From 42a59b652679de0c24e169a914ae3aa3fbf9e9be Mon Sep 17 00:00:00 2001 From: Markus Quaritsch <markus.quaritsch@tugraz.at> Date: Thu, 10 Aug 2017 08:33:34 +0200 Subject: [PATCH] switch to NUnit testframework --- .../VectoAuxiliariesTests.vbproj | 1 - .../VectoHashingTest/Utils/AssertHelper.cs | 50 +-- .../BusAuxiliaries/AuxDemandTest.cs | 240 +++++------ .../BusAuxiliaries/BusAdapterTest.cs | 18 +- .../Integration/TorqueLimitsTest.cs | 405 +++++++++--------- .../DeclarationAdapterTestHelper.cs | 75 ++-- .../DeclarationDataAdapterTest_Class2.cs | 20 +- .../DeclarationDataAdapterTest_Class5.cs | 304 +++++++------ .../Models/Simulation/AuxTests.cs | 4 +- .../Models/Simulation/DrivingCycleTests.cs | 12 +- .../Simulation/PowerTrainBuilderTest.cs | 23 +- .../Models/SimulationComponent/ClutchTest.cs | 337 ++++++++------- .../VectoCoreTest/Reports/ModDataTest.cs | 16 +- .../VectoCoreTest/Utils/ResultFileHelper.cs | 8 +- .../VectoCoreTest/Utils/VectoMathTest.cs | 235 +++++----- 15 files changed, 859 insertions(+), 889 deletions(-) diff --git a/VECTOAux/VectoAuxiliariesTests/VectoAuxiliariesTests.vbproj b/VECTOAux/VectoAuxiliariesTests/VectoAuxiliariesTests.vbproj index 5c0e10988e..3c8ea02e6a 100644 --- a/VECTOAux/VectoAuxiliariesTests/VectoAuxiliariesTests.vbproj +++ b/VECTOAux/VectoAuxiliariesTests/VectoAuxiliariesTests.vbproj @@ -111,7 +111,6 @@ <Import Include="System.Linq" /> <Import Include="System.Xml.Linq" /> <Import Include="System.Threading.Tasks" /> - <Import Include="Microsoft.VisualStudio.TestTools.UnitTesting" /> </ItemGroup> <ItemGroup> <Compile Include="IntegrationTests\AuxDemandTest.vb" /> diff --git a/VectoCommon/VectoHashingTest/Utils/AssertHelper.cs b/VectoCommon/VectoHashingTest/Utils/AssertHelper.cs index 21dee8b5b9..8b3546d56e 100644 --- a/VectoCommon/VectoHashingTest/Utils/AssertHelper.cs +++ b/VectoCommon/VectoHashingTest/Utils/AssertHelper.cs @@ -29,28 +29,28 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ -using System; -using System.Diagnostics; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace VectoHashingTest.Utils -{ - public static class AssertHelper - { - /// <summary> - /// Assert an expected Exception. - /// </summary> - [DebuggerHidden] - public static void Exception<T>(this Action func, string message = null) where T : Exception - { - try { - func(); - Assert.Fail("Expected Exception {0}, but no exception occured.", typeof(T)); - } catch (T ex) { - if (message != null) { - Assert.AreEqual(message, ex.Message); - } - } - } - } -} \ No newline at end of file +using System; +using System.Diagnostics; +using NUnit.Framework; + +namespace VectoHashingTest.Utils +{ + public static class AssertHelper + { + /// <summary> + /// Assert an expected Exception. + /// </summary> + [DebuggerHidden] + public static void Exception<T>(this Action func, string message = null) where T : Exception + { + try { + func(); + Assert.Fail("Expected Exception {0}, but no exception occured.", typeof(T)); + } catch (T ex) { + if (message != null) { + Assert.AreEqual(message, ex.Message); + } + } + } + } +} diff --git a/VectoCore/VectoCoreTest/Integration/BusAuxiliaries/AuxDemandTest.cs b/VectoCore/VectoCoreTest/Integration/BusAuxiliaries/AuxDemandTest.cs index 8a48924b44..a5a2e39137 100644 --- a/VectoCore/VectoCoreTest/Integration/BusAuxiliaries/AuxDemandTest.cs +++ b/VectoCore/VectoCoreTest/Integration/BusAuxiliaries/AuxDemandTest.cs @@ -29,127 +29,125 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ -using System.Collections.Generic; -using NUnit.Framework; -using TUGraz.VectoCommon.Models; -using TUGraz.VectoCommon.Utils; -using TUGraz.VectoCore.InputData.Reader; -using TUGraz.VectoCore.Models.Simulation.Data; -using TUGraz.VectoCore.Models.Simulation.DataBus; -using TUGraz.VectoCore.Models.Simulation.Impl; -using TUGraz.VectoCore.Models.SimulationComponent.Data; -using TUGraz.VectoCore.Models.SimulationComponent.Data.Engine; -using TUGraz.VectoCore.Models.SimulationComponent.Impl; -using TUGraz.VectoCore.Tests.Utils; -using Assert = Microsoft.VisualStudio.TestTools.UnitTesting.Assert; +using System.Collections.Generic; +using NUnit.Framework; +using TUGraz.VectoCommon.Models; +using TUGraz.VectoCommon.Utils; +using TUGraz.VectoCore.InputData.Reader; +using TUGraz.VectoCore.Models.Simulation.Data; +using TUGraz.VectoCore.Models.Simulation.DataBus; +using TUGraz.VectoCore.Models.Simulation.Impl; +using TUGraz.VectoCore.Models.SimulationComponent.Data; +using TUGraz.VectoCore.Models.SimulationComponent.Data.Engine; +using TUGraz.VectoCore.Models.SimulationComponent.Impl; +using TUGraz.VectoCore.Tests.Utils; using System.IO; -namespace TUGraz.VectoCore.Tests.Integration.BusAuxiliaries -{ - - [TestFixture] - public class AuxDemandTest +namespace TUGraz.VectoCore.Tests.Integration.BusAuxiliaries +{ + [TestFixture] + public class AuxDemandTest { - [OneTimeSetUp] - public void RunBeforeAnyTests() - { - Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory); - } - - [Test] - [TestCase(12000, 1256, 148, 148, 6086.9321)] - [TestCase(12000, 1256, -15, -50, 8954.1396)] - [TestCase(15700, 1319, -35.79263, -144.0441, 9093.9473)] - public void AuxDemandtest(double vehicleWeight, double engineSpeedRpm, double driveLinePower, double internalPower, - double expectedPowerDemand) - { - MockDriver driver; - var busAux = CreateBusAuxAdapterForTesting(vehicleWeight, out driver); - - var engineDrivelinePower = (driveLinePower * 1000).SI<Watt>(); - var engineSpeed = engineSpeedRpm.RPMtoRad(); - busAux.Initialize(engineDrivelinePower / engineSpeed, engineSpeed); - - var torque = busAux.TorqueDemand(0.SI<Second>(), 1.SI<Second>(), engineDrivelinePower / engineSpeed, - (internalPower * 1000).SI<Watt>() / engineSpeed, engineSpeed); - - Assert.AreEqual(expectedPowerDemand, (torque * engineSpeed).Value(), 1e-2); - } - - [Test] - public void AuxFCConsumptionTest() - { - var driveLinePower = 148; - var engineSpeedRpm = 1256; - var internalPower = 148; - - MockDriver driver; - var busAux = CreateBusAuxAdapterForTesting(12000, out driver); - - var engineDrivelinePower = (driveLinePower * 1000).SI<Watt>(); - var engineSpeed = engineSpeedRpm.RPMtoRad(); - busAux.Initialize(engineDrivelinePower / engineSpeed, engineSpeed); - - var modalData = new MockModalDataContainer(); - - for (int i = 0; i < 10; i++) { - var torque = busAux.TorqueDemand(0.SI<Second>(), 1.SI<Second>(), engineDrivelinePower / engineSpeed, - (internalPower * 1000).SI<Watt>() / engineSpeed, engineSpeed); - Assert.AreEqual(6086.9321, (torque * engineSpeed).Value(), 1e-3); - busAux.DoWriteModalResults(modalData); - } - - Assert.AreEqual(79.303.SI().Gramm.Value(), ((SI)modalData[ModalResultField.AA_TotalCycleFC_Grams]).Value(), 0.0001); - - engineDrivelinePower = -15000.SI<Watt>(); - internalPower = -50; - - for (int i = 0; i < 10; i++) { - var torque = busAux.TorqueDemand(0.SI<Second>(), 1.SI<Second>(), engineDrivelinePower / engineSpeed, - (internalPower * 1000).SI<Watt>() / engineSpeed, engineSpeed); - Assert.AreEqual(8954.1396, (torque * engineSpeed).Value(), 1e-3); - busAux.DoWriteModalResults(modalData); - } - - Assert.AreEqual(82.5783.SI().Gramm.Value(), ((SI)modalData[ModalResultField.AA_TotalCycleFC_Grams]).Value(), 0.0001); - - engineDrivelinePower = (driveLinePower * 1000).SI<Watt>(); - internalPower = 148; - - for (int i = 0; i < 10; i++) { - var torque = busAux.TorqueDemand(0.SI<Second>(), 1.SI<Second>(), engineDrivelinePower / engineSpeed, - (internalPower * 1000).SI<Watt>() / engineSpeed, engineSpeed); - Assert.AreEqual(6086.9321, (torque * engineSpeed).Value(), 1e-3); - busAux.DoWriteModalResults(modalData); - } - - Assert.AreEqual(162.4654.SI().Gramm.Value(), ((SI)modalData[ModalResultField.AA_TotalCycleFC_Grams]).Value(), 0.0001); - } - - public static BusAuxiliariesAdapter CreateBusAuxAdapterForTesting(double vehicleWeight, out MockDriver driver) - { - var auxFilePath = @"TestData\Integration\BusAuxiliaries\AdvAuxTest.aaux"; - var engineFLDFilePath = @"TestData\Integration\BusAuxiliaries\24t Coach.vfld"; - var engineFCMapFilePath = @"TestData\Integration\BusAuxiliaries\24t Coach.vmap"; - - var vehicle = new VehicleContainer(ExecutionMode.Engineering, new MockModalDataContainer()); - var fcMap = FuelConsumptionMapReader.ReadFromFile(engineFCMapFilePath); - var fld = FullLoadCurveReader.ReadFromFile(engineFLDFilePath); - var modelData = new CombustionEngineData() { - ConsumptionMap = fcMap, - FullLoadCurves = new Dictionary<uint, EngineFullLoadCurve>() { { 0, fld }, { 1, fld } }, - IdleSpeed = 560.SI<PerSecond>() - }; - - var engine = new CombustionEngine(vehicle, modelData); - //new Vehicle(vehicle, new VehicleData()); - driver = new MockDriver(vehicle) { VehicleStopped = false, DriverBehavior = DrivingBehavior.Braking }; - var gbx = new MockGearbox(vehicle) { Gear = 1 }; - var brakes = new MockBrakes(vehicle); - var veh = new MockVehicle(vehicle) { MyVehicleSpeed = 50.KMPHtoMeterPerSecond() }; - var busAux = new BusAuxiliariesAdapter(vehicle, auxFilePath, "Coach", vehicleWeight.SI<Kilogram>(), - fcMap, modelData.IdleSpeed); - return busAux; - } - } -} \ No newline at end of file + [OneTimeSetUp] + public void RunBeforeAnyTests() + { + Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory); + } + + [Test] + [TestCase(12000, 1256, 148, 148, 6086.9321)] + [TestCase(12000, 1256, -15, -50, 8954.1396)] + [TestCase(15700, 1319, -35.79263, -144.0441, 9093.9473)] + public void AuxDemandtest(double vehicleWeight, double engineSpeedRpm, double driveLinePower, double internalPower, + double expectedPowerDemand) + { + MockDriver driver; + var busAux = CreateBusAuxAdapterForTesting(vehicleWeight, out driver); + + var engineDrivelinePower = (driveLinePower * 1000).SI<Watt>(); + var engineSpeed = engineSpeedRpm.RPMtoRad(); + busAux.Initialize(engineDrivelinePower / engineSpeed, engineSpeed); + + var torque = busAux.TorqueDemand(0.SI<Second>(), 1.SI<Second>(), engineDrivelinePower / engineSpeed, + (internalPower * 1000).SI<Watt>() / engineSpeed, engineSpeed); + + Assert.AreEqual(expectedPowerDemand, (torque * engineSpeed).Value(), 1e-2); + } + + [Test] + public void AuxFCConsumptionTest() + { + var driveLinePower = 148; + var engineSpeedRpm = 1256; + var internalPower = 148; + + MockDriver driver; + var busAux = CreateBusAuxAdapterForTesting(12000, out driver); + + var engineDrivelinePower = (driveLinePower * 1000).SI<Watt>(); + var engineSpeed = engineSpeedRpm.RPMtoRad(); + busAux.Initialize(engineDrivelinePower / engineSpeed, engineSpeed); + + var modalData = new MockModalDataContainer(); + + for (int i = 0; i < 10; i++) { + var torque = busAux.TorqueDemand(0.SI<Second>(), 1.SI<Second>(), engineDrivelinePower / engineSpeed, + (internalPower * 1000).SI<Watt>() / engineSpeed, engineSpeed); + Assert.AreEqual(6086.9321, (torque * engineSpeed).Value(), 1e-3); + busAux.DoWriteModalResults(modalData); + } + + Assert.AreEqual(79.303.SI().Gramm.Value(), ((SI)modalData[ModalResultField.AA_TotalCycleFC_Grams]).Value(), 0.0001); + + engineDrivelinePower = -15000.SI<Watt>(); + internalPower = -50; + + for (int i = 0; i < 10; i++) { + var torque = busAux.TorqueDemand(0.SI<Second>(), 1.SI<Second>(), engineDrivelinePower / engineSpeed, + (internalPower * 1000).SI<Watt>() / engineSpeed, engineSpeed); + Assert.AreEqual(8954.1396, (torque * engineSpeed).Value(), 1e-3); + busAux.DoWriteModalResults(modalData); + } + + Assert.AreEqual(82.5783.SI().Gramm.Value(), ((SI)modalData[ModalResultField.AA_TotalCycleFC_Grams]).Value(), 0.0001); + + engineDrivelinePower = (driveLinePower * 1000).SI<Watt>(); + internalPower = 148; + + for (int i = 0; i < 10; i++) { + var torque = busAux.TorqueDemand(0.SI<Second>(), 1.SI<Second>(), engineDrivelinePower / engineSpeed, + (internalPower * 1000).SI<Watt>() / engineSpeed, engineSpeed); + Assert.AreEqual(6086.9321, (torque * engineSpeed).Value(), 1e-3); + busAux.DoWriteModalResults(modalData); + } + + Assert.AreEqual(162.4654.SI().Gramm.Value(), ((SI)modalData[ModalResultField.AA_TotalCycleFC_Grams]).Value(), 0.0001); + } + + public static BusAuxiliariesAdapter CreateBusAuxAdapterForTesting(double vehicleWeight, out MockDriver driver) + { + var auxFilePath = @"TestData\Integration\BusAuxiliaries\AdvAuxTest.aaux"; + var engineFLDFilePath = @"TestData\Integration\BusAuxiliaries\24t Coach.vfld"; + var engineFCMapFilePath = @"TestData\Integration\BusAuxiliaries\24t Coach.vmap"; + + var vehicle = new VehicleContainer(ExecutionMode.Engineering, new MockModalDataContainer()); + var fcMap = FuelConsumptionMapReader.ReadFromFile(engineFCMapFilePath); + var fld = FullLoadCurveReader.ReadFromFile(engineFLDFilePath); + var modelData = new CombustionEngineData() { + ConsumptionMap = fcMap, + FullLoadCurves = new Dictionary<uint, EngineFullLoadCurve>() { { 0, fld }, { 1, fld } }, + IdleSpeed = 560.SI<PerSecond>() + }; + + var engine = new CombustionEngine(vehicle, modelData); + //new Vehicle(vehicle, new VehicleData()); + driver = new MockDriver(vehicle) { VehicleStopped = false, DriverBehavior = DrivingBehavior.Braking }; + var gbx = new MockGearbox(vehicle) { Gear = 1 }; + var brakes = new MockBrakes(vehicle); + var veh = new MockVehicle(vehicle) { MyVehicleSpeed = 50.KMPHtoMeterPerSecond() }; + var busAux = new BusAuxiliariesAdapter(vehicle, auxFilePath, "Coach", vehicleWeight.SI<Kilogram>(), + fcMap, modelData.IdleSpeed); + return busAux; + } + } +} diff --git a/VectoCore/VectoCoreTest/Integration/BusAuxiliaries/BusAdapterTest.cs b/VectoCore/VectoCoreTest/Integration/BusAuxiliaries/BusAdapterTest.cs index 5b739dcd6f..354353af16 100644 --- a/VectoCore/VectoCoreTest/Integration/BusAuxiliaries/BusAdapterTest.cs +++ b/VectoCore/VectoCoreTest/Integration/BusAuxiliaries/BusAdapterTest.cs @@ -34,10 +34,7 @@ using NUnit.Framework; using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.Configuration; using TUGraz.VectoCore.Models.Simulation.DataBus; -using TUGraz.VectoCore.Models.SimulationComponent.Data; using TUGraz.VectoCore.Tests.Utils; -using TUGraz.VectoCore.Utils; -using Assert = Microsoft.VisualStudio.TestTools.UnitTesting.Assert; using System.IO; namespace TUGraz.VectoCore.Tests.Integration.BusAuxiliaries @@ -45,15 +42,14 @@ namespace TUGraz.VectoCore.Tests.Integration.BusAuxiliaries [TestFixture] public class BusAdapterTest { - - [OneTimeSetUp] - public void RunBeforeAnyTests() - { - Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory); - } + [OneTimeSetUp] + public void RunBeforeAnyTests() + { + Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory); + } - [Test] + [Test] [TestCase(12000, 1256, 148, 148, 6086.9321)] [TestCase(12000, 1256, -48, -148, 6086.9321)] [TestCase(12000, 1256, 48, -148, 6086.9321)] @@ -178,4 +174,4 @@ namespace TUGraz.VectoCore.Tests.Integration.BusAuxiliaries //VectoCSVFile.Write("auxPowerDemand_EngineSpeed.csv", table); } } -} \ No newline at end of file +} diff --git a/VectoCore/VectoCoreTest/Integration/TorqueLimitsTest.cs b/VectoCore/VectoCoreTest/Integration/TorqueLimitsTest.cs index 32dfcb7c3e..ce2eeb4836 100644 --- a/VectoCore/VectoCoreTest/Integration/TorqueLimitsTest.cs +++ b/VectoCore/VectoCoreTest/Integration/TorqueLimitsTest.cs @@ -29,213 +29,212 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ -using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using NUnit.Framework; -using TUGraz.VectoCommon.Models; -using TUGraz.VectoCore.InputData.FileIO.JSON; -using TUGraz.VectoCore.Models.Simulation.Impl; -using TUGraz.VectoCore.OutputData; -using TUGraz.VectoCore.OutputData.FileIO; -using Assert = NUnit.Framework.Assert; - -namespace TUGraz.VectoCore.Tests.Integration -{ - [TestFixture] - public class TorqueLimitsTest - { - const string GearboxLimitJobDecl_865 = - @"Testdata\Integration\DeclarationMode\Class2_RigidTruck_4x2_GbxTorqueLimits\Class2_RigidTruck_gbxTqLimit-865_DECL.vecto"; - - const string GearboxLimitJobDecl_800 = - @"Testdata\Integration\DeclarationMode\Class2_RigidTruck_4x2_GbxTorqueLimits\Class2_RigidTruck_gbxTqLimit-800_DECL.vecto"; - - - const string VehicleLimitJobDecl_910 = - @"Testdata\Integration\DeclarationMode\Class2_RigidTruck_4x2_VehTorqueLimits\Class2_RigidTruck_vehTqLimit-910_DECL.vecto"; - - const string VehicleLimitJobDecl_850 = - @"Testdata\Integration\DeclarationMode\Class2_RigidTruck_4x2_VehTorqueLimits\Class2_RigidTruck_vehTqLimit-850_DECL.vecto"; - - const string GearboxSpeedLimitJobDecl = - @"Testdata\Integration\DeclarationMode\Class2_RigidTruck_4x2_GbxSpeedLimits\Class2_RigidTruck_DECL.vecto"; - - const string EngineSpeedLimitJobDecl = - @"TestData\Integration\DeclarationMode\Class2_RigidTruck_4x2_engineSpeedlimit\Class2_RigidTruck_DECL.vecto"; - - [TestCase()] - public void TestGearboxTorqueLimitsAbove90FLD() - { - var inputDataProvider = JSONInputDataFactory.ReadJsonJob(GearboxLimitJobDecl_865); - var factory = new SimulatorFactory(ExecutionMode.Declaration, inputDataProvider, null); - - var run = factory.DataReader.NextRun().First(); - - var engineData = run.EngineData; - - // check default FLD - Assert.AreEqual(956, engineData.FullLoadCurves[0].MaxTorque.Value()); - Assert.AreEqual(-115, engineData.FullLoadCurves[0].MaxDragTorque.Value()); - - // check first gear - limited by gbx - Assert.AreEqual(865, engineData.FullLoadCurves[1].MaxTorque.Value()); - Assert.AreEqual(-115, engineData.FullLoadCurves[1].MaxDragTorque.Value()); - - // check fourth gear - limited by gbx but not applicaple - Assert.AreEqual(956, engineData.FullLoadCurves[4].MaxTorque.Value()); - Assert.AreEqual(-115, engineData.FullLoadCurves[4].MaxDragTorque.Value()); - - // check last gear - limited by gbx but not applicaple - Assert.AreEqual(956, engineData.FullLoadCurves[6].MaxTorque.Value()); - Assert.AreEqual(-115, engineData.FullLoadCurves[6].MaxDragTorque.Value()); - } - - [TestCase()] - public void TestGearboxTorqueLimitsBelow90FLD() - { - var inputDataProvider = JSONInputDataFactory.ReadJsonJob(GearboxLimitJobDecl_800); - var factory = new SimulatorFactory(ExecutionMode.Declaration, inputDataProvider, null); - - var run = factory.DataReader.NextRun().First(); - - var engineData = run.EngineData; - - // check default FLD - Assert.AreEqual(956, engineData.FullLoadCurves[0].MaxTorque.Value()); - Assert.AreEqual(-115, engineData.FullLoadCurves[0].MaxDragTorque.Value()); - - // check first gear - limited by gbx - Assert.AreEqual(800, engineData.FullLoadCurves[1].MaxTorque.Value()); - Assert.AreEqual(-115, engineData.FullLoadCurves[1].MaxDragTorque.Value()); - - // check fourth gear - limited by gbx - Assert.AreEqual(800, engineData.FullLoadCurves[4].MaxTorque.Value()); - Assert.AreEqual(-115, engineData.FullLoadCurves[4].MaxDragTorque.Value()); - - // check last gear - limited by gbx - Assert.AreEqual(800, engineData.FullLoadCurves[6].MaxTorque.Value()); - Assert.AreEqual(-115, engineData.FullLoadCurves[6].MaxDragTorque.Value()); - } - - [TestCase()] - public void TestVehicleTorqueLimitsAbove95FLD() - { - var inputDataProvider = JSONInputDataFactory.ReadJsonJob(VehicleLimitJobDecl_910); - var factory = new SimulatorFactory(ExecutionMode.Declaration, inputDataProvider, null); - - var run = factory.DataReader.NextRun().First(); - - var engineData = run.EngineData; - - // check default FLD - Assert.AreEqual(956, engineData.FullLoadCurves[0].MaxTorque.Value()); - Assert.AreEqual(-115, engineData.FullLoadCurves[0].MaxDragTorque.Value()); - - // check first gear - limited by vehicle but not applicaple - Assert.AreEqual(956, engineData.FullLoadCurves[1].MaxTorque.Value()); - Assert.AreEqual(-115, engineData.FullLoadCurves[1].MaxDragTorque.Value()); - - // check fourth gear - limited by vehicle but not applicaple - Assert.AreEqual(956, engineData.FullLoadCurves[4].MaxTorque.Value()); - Assert.AreEqual(-115, engineData.FullLoadCurves[4].MaxDragTorque.Value()); - - // check last gear - limited by vehicle but not applicaple - Assert.AreEqual(956, engineData.FullLoadCurves[6].MaxTorque.Value()); - Assert.AreEqual(-115, engineData.FullLoadCurves[6].MaxDragTorque.Value()); - } - - [TestCase()] - public void TestVehicleTorqueLimitsBelow95FLD() - { - var inputDataProvider = JSONInputDataFactory.ReadJsonJob(VehicleLimitJobDecl_850); - var factory = new SimulatorFactory(ExecutionMode.Declaration, inputDataProvider, null); - - var run = factory.DataReader.NextRun().First(); - - var engineData = run.EngineData; - - // check default FLD - Assert.AreEqual(956, engineData.FullLoadCurves[0].MaxTorque.Value()); - Assert.AreEqual(-115, engineData.FullLoadCurves[0].MaxDragTorque.Value()); - - // check first gear - limited by vehicle but not applicaple - Assert.AreEqual(956, engineData.FullLoadCurves[1].MaxTorque.Value()); - Assert.AreEqual(-115, engineData.FullLoadCurves[1].MaxDragTorque.Value()); - - // check fourth gear - limited by vehicle - Assert.AreEqual(850, engineData.FullLoadCurves[4].MaxTorque.Value()); - Assert.AreEqual(-115, engineData.FullLoadCurves[4].MaxDragTorque.Value()); - - // check last gear - limited by vehicle - Assert.AreEqual(850, engineData.FullLoadCurves[6].MaxTorque.Value()); - Assert.AreEqual(-115, engineData.FullLoadCurves[6].MaxDragTorque.Value()); +using System.Linq; +using NUnit.Framework; +using TUGraz.VectoCommon.Models; +using TUGraz.VectoCore.InputData.FileIO.JSON; +using TUGraz.VectoCore.Models.Simulation.Impl; +using TUGraz.VectoCore.OutputData; +using TUGraz.VectoCore.OutputData.FileIO; +using Assert = NUnit.Framework.Assert; + +namespace TUGraz.VectoCore.Tests.Integration +{ + [TestFixture] + public class TorqueLimitsTest + { + const string GearboxLimitJobDecl_865 = + @"Testdata\Integration\DeclarationMode\Class2_RigidTruck_4x2_GbxTorqueLimits\Class2_RigidTruck_gbxTqLimit-865_DECL.vecto"; + + const string GearboxLimitJobDecl_800 = + @"Testdata\Integration\DeclarationMode\Class2_RigidTruck_4x2_GbxTorqueLimits\Class2_RigidTruck_gbxTqLimit-800_DECL.vecto"; + + + const string VehicleLimitJobDecl_910 = + @"Testdata\Integration\DeclarationMode\Class2_RigidTruck_4x2_VehTorqueLimits\Class2_RigidTruck_vehTqLimit-910_DECL.vecto"; + + const string VehicleLimitJobDecl_850 = + @"Testdata\Integration\DeclarationMode\Class2_RigidTruck_4x2_VehTorqueLimits\Class2_RigidTruck_vehTqLimit-850_DECL.vecto"; + + const string GearboxSpeedLimitJobDecl = + @"Testdata\Integration\DeclarationMode\Class2_RigidTruck_4x2_GbxSpeedLimits\Class2_RigidTruck_DECL.vecto"; + + const string EngineSpeedLimitJobDecl = + @"TestData\Integration\DeclarationMode\Class2_RigidTruck_4x2_engineSpeedlimit\Class2_RigidTruck_DECL.vecto"; + + [TestCase()] + public void TestGearboxTorqueLimitsAbove90FLD() + { + var inputDataProvider = JSONInputDataFactory.ReadJsonJob(GearboxLimitJobDecl_865); + var factory = new SimulatorFactory(ExecutionMode.Declaration, inputDataProvider, null); + + var run = factory.DataReader.NextRun().First(); + + var engineData = run.EngineData; + + // check default FLD + Assert.AreEqual(956, engineData.FullLoadCurves[0].MaxTorque.Value()); + Assert.AreEqual(-115, engineData.FullLoadCurves[0].MaxDragTorque.Value()); + + // check first gear - limited by gbx + Assert.AreEqual(865, engineData.FullLoadCurves[1].MaxTorque.Value()); + Assert.AreEqual(-115, engineData.FullLoadCurves[1].MaxDragTorque.Value()); + + // check fourth gear - limited by gbx but not applicaple + Assert.AreEqual(956, engineData.FullLoadCurves[4].MaxTorque.Value()); + Assert.AreEqual(-115, engineData.FullLoadCurves[4].MaxDragTorque.Value()); + + // check last gear - limited by gbx but not applicaple + Assert.AreEqual(956, engineData.FullLoadCurves[6].MaxTorque.Value()); + Assert.AreEqual(-115, engineData.FullLoadCurves[6].MaxDragTorque.Value()); + } + + [TestCase()] + public void TestGearboxTorqueLimitsBelow90FLD() + { + var inputDataProvider = JSONInputDataFactory.ReadJsonJob(GearboxLimitJobDecl_800); + var factory = new SimulatorFactory(ExecutionMode.Declaration, inputDataProvider, null); + + var run = factory.DataReader.NextRun().First(); + + var engineData = run.EngineData; + + // check default FLD + Assert.AreEqual(956, engineData.FullLoadCurves[0].MaxTorque.Value()); + Assert.AreEqual(-115, engineData.FullLoadCurves[0].MaxDragTorque.Value()); + + // check first gear - limited by gbx + Assert.AreEqual(800, engineData.FullLoadCurves[1].MaxTorque.Value()); + Assert.AreEqual(-115, engineData.FullLoadCurves[1].MaxDragTorque.Value()); + + // check fourth gear - limited by gbx + Assert.AreEqual(800, engineData.FullLoadCurves[4].MaxTorque.Value()); + Assert.AreEqual(-115, engineData.FullLoadCurves[4].MaxDragTorque.Value()); + + // check last gear - limited by gbx + Assert.AreEqual(800, engineData.FullLoadCurves[6].MaxTorque.Value()); + Assert.AreEqual(-115, engineData.FullLoadCurves[6].MaxDragTorque.Value()); + } + + [TestCase()] + public void TestVehicleTorqueLimitsAbove95FLD() + { + var inputDataProvider = JSONInputDataFactory.ReadJsonJob(VehicleLimitJobDecl_910); + var factory = new SimulatorFactory(ExecutionMode.Declaration, inputDataProvider, null); + + var run = factory.DataReader.NextRun().First(); + + var engineData = run.EngineData; + + // check default FLD + Assert.AreEqual(956, engineData.FullLoadCurves[0].MaxTorque.Value()); + Assert.AreEqual(-115, engineData.FullLoadCurves[0].MaxDragTorque.Value()); + + // check first gear - limited by vehicle but not applicaple + Assert.AreEqual(956, engineData.FullLoadCurves[1].MaxTorque.Value()); + Assert.AreEqual(-115, engineData.FullLoadCurves[1].MaxDragTorque.Value()); + + // check fourth gear - limited by vehicle but not applicaple + Assert.AreEqual(956, engineData.FullLoadCurves[4].MaxTorque.Value()); + Assert.AreEqual(-115, engineData.FullLoadCurves[4].MaxDragTorque.Value()); + + // check last gear - limited by vehicle but not applicaple + Assert.AreEqual(956, engineData.FullLoadCurves[6].MaxTorque.Value()); + Assert.AreEqual(-115, engineData.FullLoadCurves[6].MaxDragTorque.Value()); + } + + [TestCase()] + public void TestVehicleTorqueLimitsBelow95FLD() + { + var inputDataProvider = JSONInputDataFactory.ReadJsonJob(VehicleLimitJobDecl_850); + var factory = new SimulatorFactory(ExecutionMode.Declaration, inputDataProvider, null); + + var run = factory.DataReader.NextRun().First(); + + var engineData = run.EngineData; + + // check default FLD + Assert.AreEqual(956, engineData.FullLoadCurves[0].MaxTorque.Value()); + Assert.AreEqual(-115, engineData.FullLoadCurves[0].MaxDragTorque.Value()); + + // check first gear - limited by vehicle but not applicaple + Assert.AreEqual(956, engineData.FullLoadCurves[1].MaxTorque.Value()); + Assert.AreEqual(-115, engineData.FullLoadCurves[1].MaxDragTorque.Value()); + + // check fourth gear - limited by vehicle + Assert.AreEqual(850, engineData.FullLoadCurves[4].MaxTorque.Value()); + Assert.AreEqual(-115, engineData.FullLoadCurves[4].MaxDragTorque.Value()); + + // check last gear - limited by vehicle + Assert.AreEqual(850, engineData.FullLoadCurves[6].MaxTorque.Value()); + Assert.AreEqual(-115, engineData.FullLoadCurves[6].MaxDragTorque.Value()); } [TestCase(GearboxLimitJobDecl_800), TestCase(GearboxLimitJobDecl_865), TestCase(VehicleLimitJobDecl_850), TestCase(VehicleLimitJobDecl_910), Category("LongRunning")] - public void TestRunTorqueLimitedSimulations(string file) - { - var fileWriter = new FileOutputWriter(file); - var sumData = new SummaryDataContainer(fileWriter); - var inputDataProvider = JSONInputDataFactory.ReadJsonJob(file); - var factory = new SimulatorFactory(ExecutionMode.Declaration, inputDataProvider, fileWriter) { - WriteModalResults = true - }; - - - var jobContainer = new JobContainer(sumData); - jobContainer.AddRuns(factory); - - jobContainer.Execute(); - jobContainer.WaitFinished(); - - Assert.IsTrue(jobContainer.Runs.All(r => r.Success), string.Concat(jobContainer.Runs.Select(r => r.ExecException))); - } - - [TestCategory("LongRunning"), TestCase(GearboxSpeedLimitJobDecl)] - public void TestRunGbxSpeedLimitedSimulations(string file) - { - var fileWriter = new FileOutputWriter(file); - var sumData = new SummaryDataContainer(fileWriter); - var inputDataProvider = JSONInputDataFactory.ReadJsonJob(file); - var factory = new SimulatorFactory(ExecutionMode.Declaration, inputDataProvider, fileWriter) { - WriteModalResults = true, - ActualModalData = true - }; - - - var jobContainer = new JobContainer(sumData); - jobContainer.AddRuns(factory); - - jobContainer.Execute(); - jobContainer.WaitFinished(); - - Assert.IsTrue(jobContainer.Runs.All(r => r.Success), string.Concat(jobContainer.Runs.Select(r => r.ExecException))); - } - + public void TestRunTorqueLimitedSimulations(string file) + { + var fileWriter = new FileOutputWriter(file); + var sumData = new SummaryDataContainer(fileWriter); + var inputDataProvider = JSONInputDataFactory.ReadJsonJob(file); + var factory = new SimulatorFactory(ExecutionMode.Declaration, inputDataProvider, fileWriter) { + WriteModalResults = true + }; + + + var jobContainer = new JobContainer(sumData); + jobContainer.AddRuns(factory); + + jobContainer.Execute(); + jobContainer.WaitFinished(); + + Assert.IsTrue(jobContainer.Runs.All(r => r.Success), string.Concat(jobContainer.Runs.Select(r => r.ExecException))); + } + + [Category("LongRunning"), TestCase(GearboxSpeedLimitJobDecl)] + public void TestRunGbxSpeedLimitedSimulations(string file) + { + var fileWriter = new FileOutputWriter(file); + var sumData = new SummaryDataContainer(fileWriter); + var inputDataProvider = JSONInputDataFactory.ReadJsonJob(file); + var factory = new SimulatorFactory(ExecutionMode.Declaration, inputDataProvider, fileWriter) { + WriteModalResults = true, + ActualModalData = true + }; + + + var jobContainer = new JobContainer(sumData); + jobContainer.AddRuns(factory); + + jobContainer.Execute(); + jobContainer.WaitFinished(); + + Assert.IsTrue(jobContainer.Runs.All(r => r.Success), string.Concat(jobContainer.Runs.Select(r => r.ExecException))); + } + [TestCase(EngineSpeedLimitJobDecl), Category("LongRunning")] - public void TestRunEngineSpeedLimitedSimulations(string file) - { - var fileWriter = new FileOutputWriter(file); - var sumData = new SummaryDataContainer(fileWriter); - var inputDataProvider = JSONInputDataFactory.ReadJsonJob(file); - var factory = new SimulatorFactory(ExecutionMode.Declaration, inputDataProvider, fileWriter) { - WriteModalResults = true, - //ActualModalData = true - }; - - - var jobContainer = new JobContainer(sumData); - jobContainer.AddRuns(factory); - - //jobContainer.Runs[1].RunWorkerAsync().Wait(); - - jobContainer.Execute(); - jobContainer.WaitFinished(); - - Assert.IsTrue(jobContainer.Runs.All(r => r.Success), string.Concat(jobContainer.Runs.Select(r => r.ExecException))); - } - } -} \ No newline at end of file + public void TestRunEngineSpeedLimitedSimulations(string file) + { + var fileWriter = new FileOutputWriter(file); + var sumData = new SummaryDataContainer(fileWriter); + var inputDataProvider = JSONInputDataFactory.ReadJsonJob(file); + var factory = new SimulatorFactory(ExecutionMode.Declaration, inputDataProvider, fileWriter) { + WriteModalResults = true, + //ActualModalData = true + }; + + + var jobContainer = new JobContainer(sumData); + jobContainer.AddRuns(factory); + + //jobContainer.Runs[1].RunWorkerAsync().Wait(); + + jobContainer.Execute(); + jobContainer.WaitFinished(); + + Assert.IsTrue(jobContainer.Runs.All(r => r.Success), string.Concat(jobContainer.Runs.Select(r => r.ExecException))); + } + } +} diff --git a/VectoCore/VectoCoreTest/Models/Declaration/DataAdapter/DeclarationAdapterTestHelper.cs b/VectoCore/VectoCoreTest/Models/Declaration/DataAdapter/DeclarationAdapterTestHelper.cs index 2f0b67c64b..d5ecd7bbf1 100644 --- a/VectoCore/VectoCoreTest/Models/Declaration/DataAdapter/DeclarationAdapterTestHelper.cs +++ b/VectoCore/VectoCoreTest/Models/Declaration/DataAdapter/DeclarationAdapterTestHelper.cs @@ -29,41 +29,40 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ -using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using TUGraz.VectoCommon.InputData; -using TUGraz.VectoCommon.Models; -using TUGraz.VectoCommon.Utils; -using TUGraz.VectoCore.InputData.FileIO.JSON; -using TUGraz.VectoCore.InputData.Reader.Impl; -using TUGraz.VectoCore.Models.Declaration; -using TUGraz.VectoCore.Models.Simulation.Data; -using TUGraz.VectoCore.Models.SimulationComponent.Data; - -namespace TUGraz.VectoCore.Tests.Models.Declaration.DataAdapter -{ - public class DeclarationAdapterTestHelper - { - public static VectoRunData[] CreateVectoRunData(string file) - { - var inputData = (IDeclarationInputDataProvider)JSONInputDataFactory.ReadJsonJob(file); - var dataReader = new DeclarationModeVectoRunDataFactory(inputData, null); - var runData = dataReader.NextRun().ToArray(); - return runData; - } - - public static void AssertVehicleData(VehicleData vehicleData, AirdragData airdragData, VehicleCategory vehicleCategory, - VehicleClass vehicleClass, AxleConfiguration axleConfiguration, double wheelsInertia, double totalVehicleWeight, - double totalRollResistance, double aerodynamicDragArea) - { - Assert.AreEqual(vehicleCategory, vehicleData.VehicleCategory, "VehicleCategory"); - Assert.AreEqual(vehicleClass, vehicleData.VehicleClass, "VehicleClass"); - Assert.AreEqual(axleConfiguration, vehicleData.AxleConfiguration, "AxleConfiguration"); - Assert.AreEqual(totalVehicleWeight, vehicleData.TotalVehicleWeight.Value(), 1e-3, "TotalVehicleWeight"); - Assert.AreEqual(wheelsInertia, vehicleData.WheelsInertia.Value(), 1e-6, "WheelsInertia"); - Assert.AreEqual(totalRollResistance, vehicleData.TotalRollResistanceCoefficient, 1e-6, "TotalRollResistance"); - - Assert.AreEqual(aerodynamicDragArea, airdragData.CrossWindCorrectionCurve.AirDragArea.Value(), 1e-6, "Cd x A"); - } - } -} \ No newline at end of file +using System.Linq; +using NUnit.Framework; +using TUGraz.VectoCommon.InputData; +using TUGraz.VectoCommon.Models; +using TUGraz.VectoCore.InputData.FileIO.JSON; +using TUGraz.VectoCore.InputData.Reader.Impl; +using TUGraz.VectoCore.Models.Declaration; +using TUGraz.VectoCore.Models.Simulation.Data; +using TUGraz.VectoCore.Models.SimulationComponent.Data; + +namespace TUGraz.VectoCore.Tests.Models.Declaration.DataAdapter +{ + public class DeclarationAdapterTestHelper + { + public static VectoRunData[] CreateVectoRunData(string file) + { + var inputData = (IDeclarationInputDataProvider)JSONInputDataFactory.ReadJsonJob(file); + var dataReader = new DeclarationModeVectoRunDataFactory(inputData, null); + var runData = dataReader.NextRun().ToArray(); + return runData; + } + + public static void AssertVehicleData(VehicleData vehicleData, AirdragData airdragData, VehicleCategory vehicleCategory, + VehicleClass vehicleClass, AxleConfiguration axleConfiguration, double wheelsInertia, double totalVehicleWeight, + double totalRollResistance, double aerodynamicDragArea) + { + Assert.AreEqual(vehicleCategory, vehicleData.VehicleCategory, "VehicleCategory"); + Assert.AreEqual(vehicleClass, vehicleData.VehicleClass, "VehicleClass"); + Assert.AreEqual(axleConfiguration, vehicleData.AxleConfiguration, "AxleConfiguration"); + Assert.AreEqual(totalVehicleWeight, vehicleData.TotalVehicleWeight.Value(), 1e-3, "TotalVehicleWeight"); + Assert.AreEqual(wheelsInertia, vehicleData.WheelsInertia.Value(), 1e-6, "WheelsInertia"); + Assert.AreEqual(totalRollResistance, vehicleData.TotalRollResistanceCoefficient, 1e-6, "TotalRollResistance"); + + Assert.AreEqual(aerodynamicDragArea, airdragData.CrossWindCorrectionCurve.AirDragArea.Value(), 1e-6, "Cd x A"); + } + } +} diff --git a/VectoCore/VectoCoreTest/Models/Declaration/DataAdapter/DeclarationDataAdapterTest_Class2.cs b/VectoCore/VectoCoreTest/Models/Declaration/DataAdapter/DeclarationDataAdapterTest_Class2.cs index ca5f4b5ee1..e4ad342adf 100644 --- a/VectoCore/VectoCoreTest/Models/Declaration/DataAdapter/DeclarationDataAdapterTest_Class2.cs +++ b/VectoCore/VectoCoreTest/Models/Declaration/DataAdapter/DeclarationDataAdapterTest_Class2.cs @@ -29,15 +29,9 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ -using System.Linq; using NUnit.Framework; -using TUGraz.VectoCommon.InputData; using TUGraz.VectoCommon.Models; -using TUGraz.VectoCore.InputData.FileIO.JSON; -using TUGraz.VectoCore.InputData.Reader.Impl; using TUGraz.VectoCore.Models.Declaration; -using TUGraz.VectoCore.Models.SimulationComponent.Data; -using Assert = Microsoft.VisualStudio.TestTools.UnitTesting.Assert; using System.IO; namespace TUGraz.VectoCore.Tests.Models.Declaration.DataAdapter @@ -51,13 +45,13 @@ namespace TUGraz.VectoCore.Tests.Models.Declaration.DataAdapter public const int CurbWeight = 4670; public const double CdxA = 4.83; - [OneTimeSetUp] - public void RunBeforeAnyTests() - { - Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory); - } + [OneTimeSetUp] + public void RunBeforeAnyTests() + { + Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory); + } - [TestCase(Class2RigidTruckNoEMSJob, 0)] + [TestCase(Class2RigidTruckNoEMSJob, 0)] public void TestClass2_Vehicle_LongHaul_LowLoad(string file, int runIdx) { var runData = DeclarationAdapterTestHelper.CreateVectoRunData(file); @@ -156,4 +150,4 @@ namespace TUGraz.VectoCore.Tests.Models.Declaration.DataAdapter aerodynamicDragArea: CdxA); } } -} \ No newline at end of file +} diff --git a/VectoCore/VectoCoreTest/Models/Declaration/DataAdapter/DeclarationDataAdapterTest_Class5.cs b/VectoCore/VectoCoreTest/Models/Declaration/DataAdapter/DeclarationDataAdapterTest_Class5.cs index 35c66be08f..51c23b7160 100644 --- a/VectoCore/VectoCoreTest/Models/Declaration/DataAdapter/DeclarationDataAdapterTest_Class5.cs +++ b/VectoCore/VectoCoreTest/Models/Declaration/DataAdapter/DeclarationDataAdapterTest_Class5.cs @@ -29,158 +29,152 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ -using System.Linq; -using NUnit.Framework; -using TUGraz.VectoCommon.InputData; -using TUGraz.VectoCommon.Models; -using TUGraz.VectoCore.InputData.FileIO.JSON; -using TUGraz.VectoCore.InputData.Reader.Impl; -using TUGraz.VectoCore.Models.Declaration; -using TUGraz.VectoCore.Models.SimulationComponent.Data; -using Assert = Microsoft.VisualStudio.TestTools.UnitTesting.Assert; - -namespace TUGraz.VectoCore.Tests.Models.Declaration.DataAdapter -{ - [TestFixture] - public class DeclarationDataAdapterTest_Class5 - { - public const string Class5TractorPTOJob = - @"TestData\Integration\DeclarationMode\Class5_Tractor_4x2\Class5_Tractor_DECL.vecto"; - - public const int CurbWeight = 8229; - - public const double CdxA = 5.3; - - [TestCase(Class5TractorPTOJob, 0)] - public void TestClass5_Vehicle_LongHaul_LowLoad(string file, int runIdx) - { - var runData = DeclarationAdapterTestHelper.CreateVectoRunData(file); - - Assert.AreEqual(8, runData.Length); - - // long haul, min load - DeclarationAdapterTestHelper.AssertVehicleData(runData[runIdx].VehicleData, runData[runIdx].AirdragData, - vehicleCategory: VehicleCategory.Tractor, - vehicleClass: VehicleClass.Class5, - axleConfiguration: AxleConfiguration.AxleConfig_4x2, - wheelsInertia: 204.6, - totalVehicleWeight: CurbWeight + 7500 + 2600, - totalRollResistance: 0.0062662, - aerodynamicDragArea: CdxA); - } - - [TestCase(Class5TractorPTOJob, 1)] - public void TestClass5_Vehicle_LongHaul_RefLoad(string file, int runIdx) - { - var runData = DeclarationAdapterTestHelper.CreateVectoRunData(file); - - // long haul, ref load - DeclarationAdapterTestHelper.AssertVehicleData(runData[runIdx].VehicleData, runData[runIdx].AirdragData, - vehicleCategory: VehicleCategory.Tractor, - vehicleClass: VehicleClass.Class5, - axleConfiguration: AxleConfiguration.AxleConfig_4x2, - wheelsInertia: 204.6, - totalVehicleWeight: CurbWeight + 7500 + 19300, - totalRollResistance: 0.00587322, - aerodynamicDragArea: CdxA); - } - - [TestCase(Class5TractorPTOJob, 2)] - public void TestClass5_Vehicle_LongHaul_EMS_LowLoad(string file, int runIdx) - { - var runData = DeclarationAdapterTestHelper.CreateVectoRunData(file); - - Assert.AreEqual(8, runData.Length); - - // long haul, min load - DeclarationAdapterTestHelper.AssertVehicleData(runData[runIdx].VehicleData, runData[runIdx].AirdragData, - vehicleCategory: VehicleCategory.Tractor, - vehicleClass: VehicleClass.Class5, - axleConfiguration: AxleConfiguration.AxleConfig_4x2, - wheelsInertia: 281.4, - totalVehicleWeight: CurbWeight + 7500 + 5400 + 3500, - totalRollResistance: 0.0062159, - aerodynamicDragArea: CdxA + 1.5); - } - - [TestCase(Class5TractorPTOJob, 3)] - public void TestClass5_Vehicle_LongHaul_EMS_RefLoad(string file, int runIdx) - { - var runData = DeclarationAdapterTestHelper.CreateVectoRunData(file); - - // long haul, ref load - DeclarationAdapterTestHelper.AssertVehicleData(runData[runIdx].VehicleData, runData[runIdx].AirdragData, - vehicleCategory: VehicleCategory.Tractor, - vehicleClass: VehicleClass.Class5, - axleConfiguration: AxleConfiguration.AxleConfig_4x2, - wheelsInertia: 281.4, - totalVehicleWeight: CurbWeight + 7500 + 5400 + 26500, - totalRollResistance: 0.0058192, - aerodynamicDragArea: CdxA + 1.5); - } - - [TestCase(Class5TractorPTOJob, 4)] - public void TestClass5_Vehicle_RegionalDel_LowLoad(string file, int runIdx) - { - var runData = DeclarationAdapterTestHelper.CreateVectoRunData(file); - - // regional del., min load - DeclarationAdapterTestHelper.AssertVehicleData(runData[runIdx].VehicleData, runData[runIdx].AirdragData, - vehicleCategory: VehicleCategory.Tractor, - vehicleClass: VehicleClass.Class5, - axleConfiguration: AxleConfiguration.AxleConfig_4x2, - wheelsInertia: 204.6, - totalVehicleWeight: CurbWeight + 7500 + 2600, - totalRollResistance: 0.0062565, - aerodynamicDragArea: CdxA); - } - - [TestCase(Class5TractorPTOJob, 5)] - public void TestClass5_Vehicle_RegionalDel_RefLoad(string file, int runIdx) - { - var runData = DeclarationAdapterTestHelper.CreateVectoRunData(file); - - // regional del., ref load - DeclarationAdapterTestHelper.AssertVehicleData(runData[runIdx].VehicleData, runData[runIdx].AirdragData, - vehicleCategory: VehicleCategory.Tractor, - vehicleClass: VehicleClass.Class5, - axleConfiguration: AxleConfiguration.AxleConfig_4x2, - wheelsInertia: 204.6, - totalVehicleWeight: CurbWeight + 7500 + 12900, - totalRollResistance: 0.0059836, - aerodynamicDragArea: CdxA); - } - - [TestCase(Class5TractorPTOJob, 6)] - public void TestClass5_Vehicle_RegionalDelEMS_LowLoad(string file, int runIdx) - { - var runData = DeclarationAdapterTestHelper.CreateVectoRunData(file); - - // regional del., min load - DeclarationAdapterTestHelper.AssertVehicleData(runData[runIdx].VehicleData, runData[runIdx].AirdragData, - vehicleCategory: VehicleCategory.Tractor, - vehicleClass: VehicleClass.Class5, - axleConfiguration: AxleConfiguration.AxleConfig_4x2, - wheelsInertia: 281.4, - totalVehicleWeight: CurbWeight + 7500 + 5400 + 3500, - totalRollResistance: 0.006259, - aerodynamicDragArea: CdxA + 1.5); - } - - [TestCase(Class5TractorPTOJob, 7)] - public void TestClass5_Vehicle_RegionalDelEMS_RefLoad(string file, int runIdx) - { - var runData = DeclarationAdapterTestHelper.CreateVectoRunData(file); - - // regional del., ref load - DeclarationAdapterTestHelper.AssertVehicleData(runData[runIdx].VehicleData, runData[runIdx].AirdragData, - vehicleCategory: VehicleCategory.Tractor, - vehicleClass: VehicleClass.Class5, - axleConfiguration: AxleConfiguration.AxleConfig_4x2, - wheelsInertia: 281.4, - totalVehicleWeight: CurbWeight + 7500 + 5400 + 17500, - totalRollResistance: 0.0059836, - aerodynamicDragArea: CdxA + 1.5); - } - } -} \ No newline at end of file +using NUnit.Framework; +using TUGraz.VectoCommon.Models; +using TUGraz.VectoCore.Models.Declaration; + +namespace TUGraz.VectoCore.Tests.Models.Declaration.DataAdapter +{ + [TestFixture] + public class DeclarationDataAdapterTest_Class5 + { + public const string Class5TractorPTOJob = + @"TestData\Integration\DeclarationMode\Class5_Tractor_4x2\Class5_Tractor_DECL.vecto"; + + public const int CurbWeight = 8229; + + public const double CdxA = 5.3; + + [TestCase(Class5TractorPTOJob, 0)] + public void TestClass5_Vehicle_LongHaul_LowLoad(string file, int runIdx) + { + var runData = DeclarationAdapterTestHelper.CreateVectoRunData(file); + + Assert.AreEqual(8, runData.Length); + + // long haul, min load + DeclarationAdapterTestHelper.AssertVehicleData(runData[runIdx].VehicleData, runData[runIdx].AirdragData, + vehicleCategory: VehicleCategory.Tractor, + vehicleClass: VehicleClass.Class5, + axleConfiguration: AxleConfiguration.AxleConfig_4x2, + wheelsInertia: 204.6, + totalVehicleWeight: CurbWeight + 7500 + 2600, + totalRollResistance: 0.0062662, + aerodynamicDragArea: CdxA); + } + + [TestCase(Class5TractorPTOJob, 1)] + public void TestClass5_Vehicle_LongHaul_RefLoad(string file, int runIdx) + { + var runData = DeclarationAdapterTestHelper.CreateVectoRunData(file); + + // long haul, ref load + DeclarationAdapterTestHelper.AssertVehicleData(runData[runIdx].VehicleData, runData[runIdx].AirdragData, + vehicleCategory: VehicleCategory.Tractor, + vehicleClass: VehicleClass.Class5, + axleConfiguration: AxleConfiguration.AxleConfig_4x2, + wheelsInertia: 204.6, + totalVehicleWeight: CurbWeight + 7500 + 19300, + totalRollResistance: 0.00587322, + aerodynamicDragArea: CdxA); + } + + [TestCase(Class5TractorPTOJob, 2)] + public void TestClass5_Vehicle_LongHaul_EMS_LowLoad(string file, int runIdx) + { + var runData = DeclarationAdapterTestHelper.CreateVectoRunData(file); + + Assert.AreEqual(8, runData.Length); + + // long haul, min load + DeclarationAdapterTestHelper.AssertVehicleData(runData[runIdx].VehicleData, runData[runIdx].AirdragData, + vehicleCategory: VehicleCategory.Tractor, + vehicleClass: VehicleClass.Class5, + axleConfiguration: AxleConfiguration.AxleConfig_4x2, + wheelsInertia: 281.4, + totalVehicleWeight: CurbWeight + 7500 + 5400 + 3500, + totalRollResistance: 0.0062159, + aerodynamicDragArea: CdxA + 1.5); + } + + [TestCase(Class5TractorPTOJob, 3)] + public void TestClass5_Vehicle_LongHaul_EMS_RefLoad(string file, int runIdx) + { + var runData = DeclarationAdapterTestHelper.CreateVectoRunData(file); + + // long haul, ref load + DeclarationAdapterTestHelper.AssertVehicleData(runData[runIdx].VehicleData, runData[runIdx].AirdragData, + vehicleCategory: VehicleCategory.Tractor, + vehicleClass: VehicleClass.Class5, + axleConfiguration: AxleConfiguration.AxleConfig_4x2, + wheelsInertia: 281.4, + totalVehicleWeight: CurbWeight + 7500 + 5400 + 26500, + totalRollResistance: 0.0058192, + aerodynamicDragArea: CdxA + 1.5); + } + + [TestCase(Class5TractorPTOJob, 4)] + public void TestClass5_Vehicle_RegionalDel_LowLoad(string file, int runIdx) + { + var runData = DeclarationAdapterTestHelper.CreateVectoRunData(file); + + // regional del., min load + DeclarationAdapterTestHelper.AssertVehicleData(runData[runIdx].VehicleData, runData[runIdx].AirdragData, + vehicleCategory: VehicleCategory.Tractor, + vehicleClass: VehicleClass.Class5, + axleConfiguration: AxleConfiguration.AxleConfig_4x2, + wheelsInertia: 204.6, + totalVehicleWeight: CurbWeight + 7500 + 2600, + totalRollResistance: 0.0062565, + aerodynamicDragArea: CdxA); + } + + [TestCase(Class5TractorPTOJob, 5)] + public void TestClass5_Vehicle_RegionalDel_RefLoad(string file, int runIdx) + { + var runData = DeclarationAdapterTestHelper.CreateVectoRunData(file); + + // regional del., ref load + DeclarationAdapterTestHelper.AssertVehicleData(runData[runIdx].VehicleData, runData[runIdx].AirdragData, + vehicleCategory: VehicleCategory.Tractor, + vehicleClass: VehicleClass.Class5, + axleConfiguration: AxleConfiguration.AxleConfig_4x2, + wheelsInertia: 204.6, + totalVehicleWeight: CurbWeight + 7500 + 12900, + totalRollResistance: 0.0059836, + aerodynamicDragArea: CdxA); + } + + [TestCase(Class5TractorPTOJob, 6)] + public void TestClass5_Vehicle_RegionalDelEMS_LowLoad(string file, int runIdx) + { + var runData = DeclarationAdapterTestHelper.CreateVectoRunData(file); + + // regional del., min load + DeclarationAdapterTestHelper.AssertVehicleData(runData[runIdx].VehicleData, runData[runIdx].AirdragData, + vehicleCategory: VehicleCategory.Tractor, + vehicleClass: VehicleClass.Class5, + axleConfiguration: AxleConfiguration.AxleConfig_4x2, + wheelsInertia: 281.4, + totalVehicleWeight: CurbWeight + 7500 + 5400 + 3500, + totalRollResistance: 0.006259, + aerodynamicDragArea: CdxA + 1.5); + } + + [TestCase(Class5TractorPTOJob, 7)] + public void TestClass5_Vehicle_RegionalDelEMS_RefLoad(string file, int runIdx) + { + var runData = DeclarationAdapterTestHelper.CreateVectoRunData(file); + + // regional del., ref load + DeclarationAdapterTestHelper.AssertVehicleData(runData[runIdx].VehicleData, runData[runIdx].AirdragData, + vehicleCategory: VehicleCategory.Tractor, + vehicleClass: VehicleClass.Class5, + axleConfiguration: AxleConfiguration.AxleConfig_4x2, + wheelsInertia: 281.4, + totalVehicleWeight: CurbWeight + 7500 + 5400 + 17500, + totalRollResistance: 0.0059836, + aerodynamicDragArea: CdxA + 1.5); + } + } +} diff --git a/VectoCore/VectoCoreTest/Models/Simulation/AuxTests.cs b/VectoCore/VectoCoreTest/Models/Simulation/AuxTests.cs index 2e4233ba6d..e4e0424d43 100644 --- a/VectoCore/VectoCoreTest/Models/Simulation/AuxTests.cs +++ b/VectoCore/VectoCoreTest/Models/Simulation/AuxTests.cs @@ -30,9 +30,7 @@ */ using System.Collections.Generic; -using Microsoft.VisualStudio.TestTools.UnitTesting; using TUGraz.VectoCommon.Exceptions; -using TUGraz.VectoCommon.InputData; using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.InputData; @@ -371,4 +369,4 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation AssertHelper.Exception<VectoException>(() => jobContainer.AddRuns(runsFactory)); } } -} \ No newline at end of file +} diff --git a/VectoCore/VectoCoreTest/Models/Simulation/DrivingCycleTests.cs b/VectoCore/VectoCoreTest/Models/Simulation/DrivingCycleTests.cs index 6419b916a7..3ab571be01 100644 --- a/VectoCore/VectoCoreTest/Models/Simulation/DrivingCycleTests.cs +++ b/VectoCore/VectoCoreTest/Models/Simulation/DrivingCycleTests.cs @@ -30,7 +30,6 @@ */ using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; using NUnit.Framework; using TUGraz.VectoCommon.Exceptions; using TUGraz.VectoCommon.Models; @@ -42,7 +41,6 @@ using TUGraz.VectoCore.Models.SimulationComponent.Data; using TUGraz.VectoCore.Models.SimulationComponent.Impl; using TUGraz.VectoCore.Tests.Utils; using TUGraz.VectoCore.Utils; -using Assert = Microsoft.VisualStudio.TestTools.UnitTesting.Assert; namespace TUGraz.VectoCore.Tests.Models.Simulation { @@ -69,7 +67,7 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation var dt = 1.SI<Second>(); var response = cycleOut.Request(absTime, dt); - Assert.IsInstanceOfType(response, typeof(ResponseSuccess)); + Assert.IsInstanceOf<ResponseSuccess>(response); var time = absTime + dt / 2; var simulationInterval = dt; @@ -100,14 +98,14 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation var response = cycle.OutPort().Request(absTime, dt); var timeFail = (response as ResponseFailTimeInterval); - Assert.IsInstanceOfType(response, typeof(ResponseFailTimeInterval)); + Assert.IsInstanceOf<ResponseFailTimeInterval>(response); // ReSharper disable once PossibleNullReferenceException Assert.AreEqual(0.25.SI<Second>(), timeFail.DeltaT); dt = timeFail.DeltaT; response = cycle.OutPort().Request(absTime, dt); - Assert.IsInstanceOfType(response, typeof(ResponseSuccess)); + Assert.IsInstanceOf<ResponseSuccess>(response); container.CommitSimulationStep(absTime, dt); @@ -121,7 +119,7 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation dt = 1.SI<Second>(); response = cycle.OutPort().Request(absTime, dt); - Assert.IsInstanceOfType(response, typeof(ResponseFailTimeInterval)); + Assert.IsInstanceOf<ResponseFailTimeInterval>(response); dt = ((ResponseFailTimeInterval)response).DeltaT; Assert.AreEqual(0.5.SI<Second>(), dt); @@ -389,4 +387,4 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation Assert.AreEqual(entryCount, drivingCycle.Entries.Count, "Driving Cycle Entry count."); } } -} \ No newline at end of file +} diff --git a/VectoCore/VectoCoreTest/Models/Simulation/PowerTrainBuilderTest.cs b/VectoCore/VectoCoreTest/Models/Simulation/PowerTrainBuilderTest.cs index f825193969..057c58e023 100644 --- a/VectoCore/VectoCoreTest/Models/Simulation/PowerTrainBuilderTest.cs +++ b/VectoCore/VectoCoreTest/Models/Simulation/PowerTrainBuilderTest.cs @@ -40,7 +40,6 @@ using TUGraz.VectoCore.Models.Simulation; using TUGraz.VectoCore.Models.Simulation.Impl; using TUGraz.VectoCore.Models.SimulationComponent.Impl; using TUGraz.VectoCore.Tests.Utils; -using Assert = Microsoft.VisualStudio.TestTools.UnitTesting.Assert; namespace TUGraz.VectoCore.Tests.Models.Simulation { @@ -73,13 +72,13 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation var powerTrain = builder.Build(runData); - Assert.IsInstanceOfType(powerTrain, typeof(IVehicleContainer)); + Assert.IsInstanceOf<IVehicleContainer>(powerTrain); Assert.AreEqual(componentCount, powerTrain.SimulationComponents().Count); - Assert.IsInstanceOfType(powerTrain.Engine, typeof(CombustionEngine)); - Assert.IsInstanceOfType(powerTrain.Gearbox, typeof(Gearbox)); - Assert.IsInstanceOfType(powerTrain.Cycle, typeof(ISimulationOutPort)); - Assert.IsInstanceOfType(powerTrain.Vehicle, typeof(Vehicle)); + Assert.IsInstanceOf<CombustionEngine>(powerTrain.Engine); + Assert.IsInstanceOf<Gearbox>(powerTrain.Gearbox); + Assert.IsInstanceOf<ISimulationOutPort>(powerTrain.Cycle); + Assert.IsInstanceOf<Vehicle>(powerTrain.Vehicle); } [TestCase(JobFileDeclNoAngular, 11, false), @@ -102,16 +101,16 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation var powerTrain = builder.Build(runData); - Assert.IsInstanceOfType(powerTrain, typeof(IVehicleContainer)); + Assert.IsInstanceOf<IVehicleContainer>(powerTrain); Assert.AreEqual(componentCount, powerTrain.SimulationComponents().Count); - Assert.IsInstanceOfType(powerTrain.Engine, typeof(CombustionEngine)); - Assert.IsInstanceOfType(powerTrain.Gearbox, typeof(Gearbox)); - Assert.IsInstanceOfType(powerTrain.Cycle, typeof(ISimulationOutPort)); - Assert.IsInstanceOfType(powerTrain.Vehicle, typeof(Vehicle)); + Assert.IsInstanceOf<CombustionEngine>(powerTrain.Engine); + Assert.IsInstanceOf<Gearbox>(powerTrain.Gearbox); + Assert.IsInstanceOf<ISimulationOutPort>(powerTrain.Cycle); + Assert.IsInstanceOf<Vehicle>(powerTrain.Vehicle); } else { AssertHelper.Exception<VectoException>(() => { reader.NextRun().ToList(); }); } } } -} \ No newline at end of file +} diff --git a/VectoCore/VectoCoreTest/Models/SimulationComponent/ClutchTest.cs b/VectoCore/VectoCoreTest/Models/SimulationComponent/ClutchTest.cs index 71e1458bfa..01b1f2eb60 100644 --- a/VectoCore/VectoCoreTest/Models/SimulationComponent/ClutchTest.cs +++ b/VectoCore/VectoCoreTest/Models/SimulationComponent/ClutchTest.cs @@ -29,172 +29,171 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ -using System.Data; -using NUnit.Framework; -using TUGraz.VectoCommon.Models; -using TUGraz.VectoCommon.Utils; -using TUGraz.VectoCore.Models.Simulation; -using TUGraz.VectoCore.Models.Simulation.Data; -using TUGraz.VectoCore.Models.Simulation.DataBus; -using TUGraz.VectoCore.Models.Simulation.Impl; -using TUGraz.VectoCore.Models.SimulationComponent; -using TUGraz.VectoCore.Models.SimulationComponent.Impl; -using TUGraz.VectoCore.OutputData; -using TUGraz.VectoCore.Tests.Utils; -using TUGraz.VectoCore.Utils; -using Assert = Microsoft.VisualStudio.TestTools.UnitTesting.Assert; - -namespace TUGraz.VectoCore.Tests.Models.SimulationComponent -{ - [TestFixture] - public class ClutchTest - { - private const string CoachEngine = @"TestData\Components\24t Coach.veng"; - - [Test, - // clutch slipping - TestCase(DrivingBehavior.Driving, 100, 0, 0, 65.6889), - // clutch opened - would cause neg. clutch losses (which is not possible), torque is adapted - TestCase(DrivingBehavior.Halted, 100, 30, 51.1569, 58.643062), - // clutch closed - TestCase(DrivingBehavior.Driving, 100, 80, 100, 80), - TestCase(DrivingBehavior.Braking, 100, 80, 100, 80), - TestCase(DrivingBehavior.Driving, 100, 30, 100, 30), - // clutch opened due to braking - //TestCase(DrivingBehavior.Braking, 0, 55, null, null), - ] - public void TestClutch(DrivingBehavior drivingBehavior, double torque, double angularSpeed, double expectedTorque, - double expectedEngineSpeed) - { - var container = new VehicleContainer(ExecutionMode.Engineering); - var engineData = MockSimulationDataFactory.CreateEngineDataFromFile(CoachEngine, 1); - var gearbox = new MockGearbox(container); - gearbox.Gear = 0; - var clutch = new Clutch(container, engineData) { IdleController = new MockIdleController() }; - var vehicle = new MockVehicle(container); - vehicle.MyVehicleSpeed = 50.KMPHtoMeterPerSecond(); - - var inPort = clutch.InPort(); - var outPort = new MockTnOutPort(); - - inPort.Connect(outPort); - - var clutchOutPort = clutch.OutPort(); - - var driver = new MockDriver(container); - - driver.DriverBehavior = drivingBehavior; - - clutchOutPort.Request(0.SI<Second>(), 0.SI<Second>(), torque.SI<NewtonMeter>(), angularSpeed.SI<PerSecond>()); - - Assert.AreEqual(expectedTorque, outPort.Torque.Value(), 0.001); - Assert.AreEqual(expectedEngineSpeed, outPort.AngularVelocity.Value(), 0.001); - } - - //[Test] // this test is just to make sure the clutch characteristic has no unsteadiness - public void ClutchContinuityTest() - { - var container = new VehicleContainer(ExecutionMode.Engineering); - var engineData = MockSimulationDataFactory.CreateEngineDataFromFile(CoachEngine, 1); - var gearbox = new MockGearbox(container); - gearbox.Gear = 1; - var engine = new MockEngine(container); - var clutch = new Clutch(container, engineData) { IdleController = new MockIdleController() }; - - var inPort = clutch.InPort(); - var outPort = new MockTnOutPort(); - - inPort.Connect(outPort); - - var clutchOutPort = clutch.OutPort(); - - var driver = new MockDriver(container); - - var mass = 15E3.SI<Kilogram>(); - var rDyn = 0.5.SI<Meter>(); - var ds = 1.SI<Meter>(); - var ratio = 15.0; - - var data = new DataTable(); - data.Columns.Add("a", typeof(double)); - data.Columns.Add("n_out", typeof(double)); - data.Columns.Add("tq_out", typeof(double)); - data.Columns.Add("n_in", typeof(double)); - data.Columns.Add("tq_in", typeof(double)); - data.Columns.Add("P_out", typeof(double)); - data.Columns.Add("P_in", typeof(double)); - - var step = 0.001; - engine.EngineSpeed = 595.RPMtoRad(); - - var dt = 1.SI<Second>(); // VectoMath.Sqrt<Second>(2 * ds / accel); - - for (var a = -3.0; a < 3; a += step) { - var accel = a.SI<MeterPerSquareSecond>(); - - var tq = mass * accel * rDyn / ratio; - var angularVelocity = (accel * dt / rDyn * ratio).Cast<PerSecond>(); - - clutchOutPort.Request(0.SI<Second>(), 0.SI<Second>(), tq, angularVelocity); - - var row = data.NewRow(); - row["a"] = a; - row["n_out"] = angularVelocity.Value(); - row["tq_out"] = tq.Value(); - row["n_in"] = outPort.AngularVelocity.Value(); - row["tq_in"] = outPort.Torque.Value(); - row["P_out"] = (angularVelocity * tq).Value(); - row["P_in"] = (outPort.AngularVelocity * outPort.Torque).Value(); - data.Rows.Add(row); - } - - VectoCSVFile.Write("clutch.csv", data); - } - } - - public class MockEngine : VectoSimulationComponent, IEngineInfo - { - public MockEngine(IVehicleContainer container) : base(container) {} - - public PerSecond EngineSpeed { get; set; } - public NewtonMeter EngineTorque { get; set; } - - public Watt EngineStationaryFullPower(PerSecond angularSpeed) - { - throw new System.NotImplementedException(); - } - - public Watt EngineDragPower(PerSecond angularSpeed) - { - throw new System.NotImplementedException(); - } - - public PerSecond EngineIdleSpeed { get; set; } - public PerSecond EngineRatedSpeed { get; set; } - public PerSecond EngineN95hSpeed { get; set; } - public PerSecond EngineN80hSpeed { get; set; } - - protected override void DoWriteModalResults(IModalDataContainer container) - { - container[ModalResultField.P_eng_fcmap] = 0.SI<Watt>(); - container[ModalResultField.P_eng_out] = 0.SI<Watt>(); - container[ModalResultField.P_eng_inertia] = 0.SI<Watt>(); - - container[ModalResultField.n_eng_avg] = 0.SI<PerSecond>(); - container[ModalResultField.T_eng_fcmap] = 0.SI<NewtonMeter>(); - - container[ModalResultField.P_eng_full] = 0.SI<Watt>(); - container[ModalResultField.P_eng_drag] = 0.SI<Watt>(); - container[ModalResultField.Tq_full] = 0.SI<NewtonMeter>(); - container[ModalResultField.Tq_drag] = 0.SI<NewtonMeter>(); - - container[ModalResultField.FCMap] = 0.SI<KilogramPerSecond>(); - container[ModalResultField.FCAUXc] = 0.SI<KilogramPerSecond>(); - container[ModalResultField.FCWHTCc] = 0.SI<KilogramPerSecond>(); - container[ModalResultField.FCAAUX] = 0.SI<KilogramPerSecond>(); - container[ModalResultField.FCFinal] = 0.SI<KilogramPerSecond>(); - } - - protected override void DoCommitSimulationStep() {} - } -} \ No newline at end of file +using System.Data; +using NUnit.Framework; +using TUGraz.VectoCommon.Models; +using TUGraz.VectoCommon.Utils; +using TUGraz.VectoCore.Models.Simulation; +using TUGraz.VectoCore.Models.Simulation.Data; +using TUGraz.VectoCore.Models.Simulation.DataBus; +using TUGraz.VectoCore.Models.Simulation.Impl; +using TUGraz.VectoCore.Models.SimulationComponent; +using TUGraz.VectoCore.Models.SimulationComponent.Impl; +using TUGraz.VectoCore.OutputData; +using TUGraz.VectoCore.Tests.Utils; +using TUGraz.VectoCore.Utils; + +namespace TUGraz.VectoCore.Tests.Models.SimulationComponent +{ + [TestFixture] + public class ClutchTest + { + private const string CoachEngine = @"TestData\Components\24t Coach.veng"; + + [Test, + // clutch slipping + TestCase(DrivingBehavior.Driving, 100, 0, 0, 65.6889), + // clutch opened - would cause neg. clutch losses (which is not possible), torque is adapted + TestCase(DrivingBehavior.Halted, 100, 30, 51.1569, 58.643062), + // clutch closed + TestCase(DrivingBehavior.Driving, 100, 80, 100, 80), + TestCase(DrivingBehavior.Braking, 100, 80, 100, 80), + TestCase(DrivingBehavior.Driving, 100, 30, 100, 30), + // clutch opened due to braking + //TestCase(DrivingBehavior.Braking, 0, 55, null, null), + ] + public void TestClutch(DrivingBehavior drivingBehavior, double torque, double angularSpeed, double expectedTorque, + double expectedEngineSpeed) + { + var container = new VehicleContainer(ExecutionMode.Engineering); + var engineData = MockSimulationDataFactory.CreateEngineDataFromFile(CoachEngine, 1); + var gearbox = new MockGearbox(container); + gearbox.Gear = 0; + var clutch = new Clutch(container, engineData) { IdleController = new MockIdleController() }; + var vehicle = new MockVehicle(container); + vehicle.MyVehicleSpeed = 50.KMPHtoMeterPerSecond(); + + var inPort = clutch.InPort(); + var outPort = new MockTnOutPort(); + + inPort.Connect(outPort); + + var clutchOutPort = clutch.OutPort(); + + var driver = new MockDriver(container); + + driver.DriverBehavior = drivingBehavior; + + clutchOutPort.Request(0.SI<Second>(), 0.SI<Second>(), torque.SI<NewtonMeter>(), angularSpeed.SI<PerSecond>()); + + Assert.AreEqual(expectedTorque, outPort.Torque.Value(), 0.001); + Assert.AreEqual(expectedEngineSpeed, outPort.AngularVelocity.Value(), 0.001); + } + + //[Test] // this test is just to make sure the clutch characteristic has no unsteadiness + public void ClutchContinuityTest() + { + var container = new VehicleContainer(ExecutionMode.Engineering); + var engineData = MockSimulationDataFactory.CreateEngineDataFromFile(CoachEngine, 1); + var gearbox = new MockGearbox(container); + gearbox.Gear = 1; + var engine = new MockEngine(container); + var clutch = new Clutch(container, engineData) { IdleController = new MockIdleController() }; + + var inPort = clutch.InPort(); + var outPort = new MockTnOutPort(); + + inPort.Connect(outPort); + + var clutchOutPort = clutch.OutPort(); + + var driver = new MockDriver(container); + + var mass = 15E3.SI<Kilogram>(); + var rDyn = 0.5.SI<Meter>(); + var ds = 1.SI<Meter>(); + var ratio = 15.0; + + var data = new DataTable(); + data.Columns.Add("a", typeof(double)); + data.Columns.Add("n_out", typeof(double)); + data.Columns.Add("tq_out", typeof(double)); + data.Columns.Add("n_in", typeof(double)); + data.Columns.Add("tq_in", typeof(double)); + data.Columns.Add("P_out", typeof(double)); + data.Columns.Add("P_in", typeof(double)); + + var step = 0.001; + engine.EngineSpeed = 595.RPMtoRad(); + + var dt = 1.SI<Second>(); // VectoMath.Sqrt<Second>(2 * ds / accel); + + for (var a = -3.0; a < 3; a += step) { + var accel = a.SI<MeterPerSquareSecond>(); + + var tq = mass * accel * rDyn / ratio; + var angularVelocity = (accel * dt / rDyn * ratio).Cast<PerSecond>(); + + clutchOutPort.Request(0.SI<Second>(), 0.SI<Second>(), tq, angularVelocity); + + var row = data.NewRow(); + row["a"] = a; + row["n_out"] = angularVelocity.Value(); + row["tq_out"] = tq.Value(); + row["n_in"] = outPort.AngularVelocity.Value(); + row["tq_in"] = outPort.Torque.Value(); + row["P_out"] = (angularVelocity * tq).Value(); + row["P_in"] = (outPort.AngularVelocity * outPort.Torque).Value(); + data.Rows.Add(row); + } + + VectoCSVFile.Write("clutch.csv", data); + } + } + + public class MockEngine : VectoSimulationComponent, IEngineInfo + { + public MockEngine(IVehicleContainer container) : base(container) {} + + public PerSecond EngineSpeed { get; set; } + public NewtonMeter EngineTorque { get; set; } + + public Watt EngineStationaryFullPower(PerSecond angularSpeed) + { + throw new System.NotImplementedException(); + } + + public Watt EngineDragPower(PerSecond angularSpeed) + { + throw new System.NotImplementedException(); + } + + public PerSecond EngineIdleSpeed { get; set; } + public PerSecond EngineRatedSpeed { get; set; } + public PerSecond EngineN95hSpeed { get; set; } + public PerSecond EngineN80hSpeed { get; set; } + + protected override void DoWriteModalResults(IModalDataContainer container) + { + container[ModalResultField.P_eng_fcmap] = 0.SI<Watt>(); + container[ModalResultField.P_eng_out] = 0.SI<Watt>(); + container[ModalResultField.P_eng_inertia] = 0.SI<Watt>(); + + container[ModalResultField.n_eng_avg] = 0.SI<PerSecond>(); + container[ModalResultField.T_eng_fcmap] = 0.SI<NewtonMeter>(); + + container[ModalResultField.P_eng_full] = 0.SI<Watt>(); + container[ModalResultField.P_eng_drag] = 0.SI<Watt>(); + container[ModalResultField.Tq_full] = 0.SI<NewtonMeter>(); + container[ModalResultField.Tq_drag] = 0.SI<NewtonMeter>(); + + container[ModalResultField.FCMap] = 0.SI<KilogramPerSecond>(); + container[ModalResultField.FCAUXc] = 0.SI<KilogramPerSecond>(); + container[ModalResultField.FCWHTCc] = 0.SI<KilogramPerSecond>(); + container[ModalResultField.FCAAUX] = 0.SI<KilogramPerSecond>(); + container[ModalResultField.FCFinal] = 0.SI<KilogramPerSecond>(); + } + + protected override void DoCommitSimulationStep() {} + } +} diff --git a/VectoCore/VectoCoreTest/Reports/ModDataTest.cs b/VectoCore/VectoCoreTest/Reports/ModDataTest.cs index 4b3cab997e..f1e7981b69 100644 --- a/VectoCore/VectoCoreTest/Reports/ModDataTest.cs +++ b/VectoCore/VectoCoreTest/Reports/ModDataTest.cs @@ -47,7 +47,6 @@ using TUGraz.VectoCore.OutputData; using TUGraz.VectoCore.OutputData.FileIO; using TUGraz.VectoCore.Tests.Integration; using TUGraz.VectoCore.Tests.Utils; -using Assert = Microsoft.VisualStudio.TestTools.UnitTesting.Assert; using System.IO; namespace TUGraz.VectoCore.Tests.Reports @@ -55,14 +54,13 @@ namespace TUGraz.VectoCore.Tests.Reports [TestFixture] public class ModDataTest { + [OneTimeSetUp] + public void RunBeforeAnyTests() + { + Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory); + } - [OneTimeSetUp] - public void RunBeforeAnyTests() - { - Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory); - } - - [TestCase()] + [TestCase()] public void ModDataIntegritySimpleTest() { var cycleData = new[] { @@ -513,4 +511,4 @@ namespace TUGraz.VectoCore.Tests.Reports } } } -} \ No newline at end of file +} diff --git a/VectoCore/VectoCoreTest/Utils/ResultFileHelper.cs b/VectoCore/VectoCoreTest/Utils/ResultFileHelper.cs index 6459379795..5c475f5cfc 100644 --- a/VectoCore/VectoCoreTest/Utils/ResultFileHelper.cs +++ b/VectoCore/VectoCoreTest/Utils/ResultFileHelper.cs @@ -33,7 +33,7 @@ using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using NUnit.Framework; using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.Models.Simulation.Data; using TUGraz.VectoCore.Utils; @@ -63,12 +63,12 @@ namespace TUGraz.VectoCore.Tests.Utils !double.IsNaN(actual.Rows[0].Field<string>(ModalResultField.v_act.GetShortCaption()).ToDouble(double.NaN))) { // test v_act >= 0 Assert.IsTrue(actual.Rows.Cast<DataRow>() - .All(r => r.ParseDouble(ModalResultField.v_act.GetShortCaption()).IsGreaterOrEqual(0)), + .All(r => r.ParseDouble(ModalResultField.v_act.GetShortCaption()).IsGreaterOrEqual(0)), "v_act must not be negative."); // test v_targ >= 0 Assert.IsTrue(actual.Rows.Cast<DataRow>() - .All(r => r.ParseDouble(ModalResultField.v_targ.GetShortCaption()).IsGreaterOrEqual(0)), + .All(r => r.ParseDouble(ModalResultField.v_targ.GetShortCaption()).IsGreaterOrEqual(0)), "v_targ must not be negative."); } @@ -155,4 +155,4 @@ namespace TUGraz.VectoCore.Tests.Utils } } } -} \ No newline at end of file +} diff --git a/VectoCore/VectoCoreTest/Utils/VectoMathTest.cs b/VectoCore/VectoCoreTest/Utils/VectoMathTest.cs index 9f45dc77dd..4940aba3de 100644 --- a/VectoCore/VectoCoreTest/Utils/VectoMathTest.cs +++ b/VectoCore/VectoCoreTest/Utils/VectoMathTest.cs @@ -29,121 +29,120 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ -using System; -using System.Linq; -using NUnit.Framework; -using TUGraz.VectoCommon.Utils; -using Assert = Microsoft.VisualStudio.TestTools.UnitTesting.Assert; - -namespace TUGraz.VectoCore.Tests.Utils -{ - [TestFixture] - public class VectoMathTest - { - [Test] - public void VectoMath_Min() - { - var smaller = 0.SI(); - var bigger = 5.SI(); - var negative = -1 * 10.SI(); - var positive = 10.SI(); - Assert.AreEqual(smaller, VectoMath.Min(smaller, bigger)); - - Assert.AreEqual(bigger, VectoMath.Max(smaller, bigger)); - - Assert.AreEqual(positive, VectoMath.Abs(negative)); - Assert.AreEqual(positive, VectoMath.Abs(positive)); - - var smallerWatt = 0.SI<Watt>(); - var biggerWatt = 5.SI<Watt>(); - var negativeWatt = -10.SI<Watt>(); - var positiveWatt = 10.SI<Watt>(); - Assert.AreEqual(smallerWatt, VectoMath.Min(smallerWatt, biggerWatt)); - Assert.AreEqual(smallerWatt, VectoMath.Min(biggerWatt, smallerWatt)); - - Assert.AreEqual(biggerWatt, VectoMath.Max(smallerWatt, biggerWatt)); - - Assert.AreEqual(positiveWatt, VectoMath.Abs(negativeWatt)); - Assert.AreEqual(positiveWatt, VectoMath.Abs(positiveWatt)); - } - - [TestCase(0, -1, 0, 1, -1, 0, 1, 0, 0, 0), - TestCase(0, 0, 10, 0, 0, 5, 10, 5, double.NaN, double.NaN), - TestCase(0, 0, 0, 10, 5, 0, 10, 5, double.NaN, double.NaN), - TestCase(0, 0, 1, 1, 1, 0, 0, 1, 0.5, 0.5)] - public void IntersectionTest(double p0x, double p0y, double p1x, double p1y, double p2x, double p2y, double p3x, - double p3y, double isx, double isy) - { - var line1 = new Edge(new Point(p0x, p0y), new Point(p1x, p1y)); - var line2 = new Edge(new Point(p2x, p2y), new Point(p3x, p3y)); - - var intersect = VectoMath.Intersect(line1, line2); - if (intersect != null) { - Assert.AreEqual(isx, intersect.X); - Assert.AreEqual(isy, intersect.Y); - } else { - Assert.IsTrue(double.IsNaN(isx)); - Assert.IsTrue(double.IsNaN(isy)); - } - } - - [TestCase(1, 2, 0, 5, new[] { -2.6906474480286136 }), - TestCase(5, -3, 2, 10, new[] { -1.0 }), - TestCase(5, -30, 2, 10, new[] { -0.5238756689475912, 0.6499388479175676, 5.873936821030023 })] - public void CubicSolverTest(double a, double b, double c, double d, double[] expected) - { - var results = VectoMath.CubicEquationSolver(a, b, c, d); - - Assert.AreEqual(expected.Length, results.Length); - var sorted = expected.ToList(); - sorted.Sort(); - Array.Sort(results); - - var comparison = sorted.Zip(results, (exp, result) => exp - result); - foreach (var cmp in comparison) { - Assert.AreEqual(0, cmp, 1e-15); - } - } - - [TestCase()] - public void TestLeastSquaresFittingExact() - { - var entries = new[] { - new { X = 0, Y = 4 }, - new { X = 10, Y = 8 }, - new { X = 20, Y = 12 } - }; - - double k, d, r; - VectoMath.LeastSquaresFitting(entries, x => x.X, x => x.Y, out k, out d, out r); - - Assert.AreEqual(4, d, 1e-6); - Assert.AreEqual(0.4, k, 1e-6); - Assert.AreEqual(1, r, 1e-6); - } - - [TestCase()] - public void TestLeastSquaresFittingEx1() - { - var entries = new[] { - new { X = 12, Y = 34.12 }, - new { X = 19, Y = 40.94 }, - new { X = 23, Y = 33.58 }, - new { X = 30, Y = 38.95 }, - new { X = 22, Y = 35.42}, - new { X = 11, Y = 32.12 }, - new { X = 13, Y = 28.57 }, - new { X = 28, Y = 40.97 }, - new { X = 10, Y = 32.06 }, - new { X = 11, Y = 30.55 }, - }; - - double k, d, r; - VectoMath.LeastSquaresFitting(entries, x => x.X, x => x.Y, out k, out d, out r); - - Assert.AreEqual(27.003529, d, 1e-6); - Assert.AreEqual(0.431535, k, 1e-6); - //Assert.AreEqual(1, r, 1e-3); - } - } -} \ No newline at end of file +using System; +using System.Linq; +using NUnit.Framework; +using TUGraz.VectoCommon.Utils; + +namespace TUGraz.VectoCore.Tests.Utils +{ + [TestFixture] + public class VectoMathTest + { + [Test] + public void VectoMath_Min() + { + var smaller = 0.SI(); + var bigger = 5.SI(); + var negative = -1 * 10.SI(); + var positive = 10.SI(); + Assert.AreEqual(smaller, VectoMath.Min(smaller, bigger)); + + Assert.AreEqual(bigger, VectoMath.Max(smaller, bigger)); + + Assert.AreEqual(positive, VectoMath.Abs(negative)); + Assert.AreEqual(positive, VectoMath.Abs(positive)); + + var smallerWatt = 0.SI<Watt>(); + var biggerWatt = 5.SI<Watt>(); + var negativeWatt = -10.SI<Watt>(); + var positiveWatt = 10.SI<Watt>(); + Assert.AreEqual(smallerWatt, VectoMath.Min(smallerWatt, biggerWatt)); + Assert.AreEqual(smallerWatt, VectoMath.Min(biggerWatt, smallerWatt)); + + Assert.AreEqual(biggerWatt, VectoMath.Max(smallerWatt, biggerWatt)); + + Assert.AreEqual(positiveWatt, VectoMath.Abs(negativeWatt)); + Assert.AreEqual(positiveWatt, VectoMath.Abs(positiveWatt)); + } + + [TestCase(0, -1, 0, 1, -1, 0, 1, 0, 0, 0), + TestCase(0, 0, 10, 0, 0, 5, 10, 5, double.NaN, double.NaN), + TestCase(0, 0, 0, 10, 5, 0, 10, 5, double.NaN, double.NaN), + TestCase(0, 0, 1, 1, 1, 0, 0, 1, 0.5, 0.5)] + public void IntersectionTest(double p0x, double p0y, double p1x, double p1y, double p2x, double p2y, double p3x, + double p3y, double isx, double isy) + { + var line1 = new Edge(new Point(p0x, p0y), new Point(p1x, p1y)); + var line2 = new Edge(new Point(p2x, p2y), new Point(p3x, p3y)); + + var intersect = VectoMath.Intersect(line1, line2); + if (intersect != null) { + Assert.AreEqual(isx, intersect.X); + Assert.AreEqual(isy, intersect.Y); + } else { + Assert.IsTrue(double.IsNaN(isx)); + Assert.IsTrue(double.IsNaN(isy)); + } + } + + [TestCase(1, 2, 0, 5, new[] { -2.6906474480286136 }), + TestCase(5, -3, 2, 10, new[] { -1.0 }), + TestCase(5, -30, 2, 10, new[] { -0.5238756689475912, 0.6499388479175676, 5.873936821030023 })] + public void CubicSolverTest(double a, double b, double c, double d, double[] expected) + { + var results = VectoMath.CubicEquationSolver(a, b, c, d); + + Assert.AreEqual(expected.Length, results.Length); + var sorted = expected.ToList(); + sorted.Sort(); + Array.Sort(results); + + var comparison = sorted.Zip(results, (exp, result) => exp - result); + foreach (var cmp in comparison) { + Assert.AreEqual(0, cmp, 1e-15); + } + } + + [TestCase()] + public void TestLeastSquaresFittingExact() + { + var entries = new[] { + new { X = 0, Y = 4 }, + new { X = 10, Y = 8 }, + new { X = 20, Y = 12 } + }; + + double k, d, r; + VectoMath.LeastSquaresFitting(entries, x => x.X, x => x.Y, out k, out d, out r); + + Assert.AreEqual(4, d, 1e-6); + Assert.AreEqual(0.4, k, 1e-6); + Assert.AreEqual(1, r, 1e-6); + } + + [TestCase()] + public void TestLeastSquaresFittingEx1() + { + var entries = new[] { + new { X = 12, Y = 34.12 }, + new { X = 19, Y = 40.94 }, + new { X = 23, Y = 33.58 }, + new { X = 30, Y = 38.95 }, + new { X = 22, Y = 35.42 }, + new { X = 11, Y = 32.12 }, + new { X = 13, Y = 28.57 }, + new { X = 28, Y = 40.97 }, + new { X = 10, Y = 32.06 }, + new { X = 11, Y = 30.55 }, + }; + + double k, d, r; + VectoMath.LeastSquaresFitting(entries, x => x.X, x => x.Y, out k, out d, out r); + + Assert.AreEqual(27.003529, d, 1e-6); + Assert.AreEqual(0.431535, k, 1e-6); + //Assert.AreEqual(1, r, 1e-3); + } + } +} -- GitLab