From e0722f079850fc9e8587c64f6d1bc5095f86fc21 Mon Sep 17 00:00:00 2001 From: Michael Krisper <michael.krisper@tugraz.at> Date: Tue, 27 Oct 2015 14:52:45 +0100 Subject: [PATCH] corrected gearbox tests --- .../SimulationComponent/Impl/Gearbox.cs | 2 +- .../SimulationComponent/Impl/ShiftStrategy.cs | 2 +- VectoCore/Utils/IntExtensionMethods.cs | 5 +- .../GearboxPowertrainTest.cs | 8 +-- .../Models/SimulationComponent/GearboxTest.cs | 69 ++++--------------- VectoCoreTest/Utils/MockDriver.cs | 2 +- 6 files changed, 21 insertions(+), 67 deletions(-) diff --git a/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs b/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs index e1194460a4..4e359997ae 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs @@ -313,7 +313,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl return dryRunResponse; } - var shiftAllowed = !inEngineSpeed.IsEqual(0) && !DataBus.VehicleSpeed.IsEqual(0) && absTime.IsGreater(0); + var shiftAllowed = !inEngineSpeed.IsEqual(0) && !DataBus.VehicleSpeed.IsEqual(0); if (shiftAllowed) { var shiftRequired = _strategy.ShiftRequired(absTime, dt, outTorque, outAngularVelocity, inTorque, inEngineSpeed, diff --git a/VectoCore/Models/SimulationComponent/Impl/ShiftStrategy.cs b/VectoCore/Models/SimulationComponent/Impl/ShiftStrategy.cs index 3c0cb58e8d..26bca72120 100644 --- a/VectoCore/Models/SimulationComponent/Impl/ShiftStrategy.cs +++ b/VectoCore/Models/SimulationComponent/Impl/ShiftStrategy.cs @@ -240,7 +240,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl // normal shift when all requirements are fullfilled ------------------ - var minimumShiftTimePassed = (lastShiftTime + Data.ShiftTime).IsSmaller(absTime); + var minimumShiftTimePassed = (lastShiftTime + Data.ShiftTime).IsSmallerOrEqual(absTime); if (!minimumShiftTimePassed) { return false; } diff --git a/VectoCore/Utils/IntExtensionMethods.cs b/VectoCore/Utils/IntExtensionMethods.cs index ed3e310976..fab0e86537 100644 --- a/VectoCore/Utils/IntExtensionMethods.cs +++ b/VectoCore/Utils/IntExtensionMethods.cs @@ -10,11 +10,13 @@ namespace TUGraz.VectoCore.Utils /// </summary> /// <param name="d"></param> /// <returns></returns> + [DebuggerHidden] public static PerSecond RPMtoRad(this int d) { return d.SI().Rounds.Per.Minute.ConvertTo().Radian.Per.Second.Cast<PerSecond>(); } + [DebuggerHidden] public static MeterPerSecond KMPHtoMeterPerSecond(this int d) { return d.SI().Kilo.Meter.Per.Hour.Cast<MeterPerSecond>(); @@ -22,8 +24,9 @@ namespace TUGraz.VectoCore.Utils /// <summary> - /// Gets the SI representation of the number (unit-less). + /// Gets the unit-less SI representation of the number. /// </summary> + [DebuggerHidden] public static SI SI(this int value) { return new SI(value); diff --git a/VectoCoreTest/Models/SimulationComponent/GearboxPowertrainTest.cs b/VectoCoreTest/Models/SimulationComponent/GearboxPowertrainTest.cs index 4044afa749..6ea7988b0e 100644 --- a/VectoCoreTest/Models/SimulationComponent/GearboxPowertrainTest.cs +++ b/VectoCoreTest/Models/SimulationComponent/GearboxPowertrainTest.cs @@ -1,8 +1,5 @@ -using System.IO; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using TUGraz.VectoCore.FileIO.Reader; +using Microsoft.VisualStudio.TestTools.UnitTesting; using TUGraz.VectoCore.Models.Connector.Ports.Impl; -using TUGraz.VectoCore.Models.SimulationComponent.Data; using TUGraz.VectoCore.Tests.Integration; using TUGraz.VectoCore.Tests.Utils; using TUGraz.VectoCore.Utils; @@ -23,7 +20,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent var container = Truck40tPowerTrain.CreatePowerTrain(cycle, "Gearbox_Initialize.vmod", 7500.0.SI<Kilogram>(), 0.SI<Kilogram>()); var retVal = container.Cycle.Initialize(); - Assert.AreEqual(5u, container.Gear); + Assert.AreEqual(4u, container.Gear); Assert.IsInstanceOfType(retVal, typeof(ResponseSuccess)); AssertHelper.AreRelativeEqual(560.RPMtoRad(), container.EngineSpeed); @@ -97,6 +94,5 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent container.CommitSimulationStep(absTime, retVal.SimulationInterval); absTime += retVal.SimulationInterval; } - } } \ No newline at end of file diff --git a/VectoCoreTest/Models/SimulationComponent/GearboxTest.cs b/VectoCoreTest/Models/SimulationComponent/GearboxTest.cs index d3b6c7d158..bf03b90d46 100644 --- a/VectoCoreTest/Models/SimulationComponent/GearboxTest.cs +++ b/VectoCoreTest/Models/SimulationComponent/GearboxTest.cs @@ -115,14 +115,14 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent var gearboxData = DeclarationModeSimulationDataReader.CreateGearboxDataFromFile(GearboxDataFile, EngineDataFile); var container = new VehicleContainer(); var gearbox = new Gearbox(container, gearboxData, new AMTShiftStrategy(gearboxData, container)); - gearbox.Gear = 1; - var ratio = 6.38; - var driver = new MockDriver(container); var port = new MockTnOutPort(); gearbox.InPort().Connect(port); container.Engine = port; + gearbox.Initialize(0.SI<NewtonMeter>(), 0.RPMtoRad()); + + var ratio = 6.38; var absTime = 0.SI<Second>(); var dt = 2.SI<Second>(); var t = 2600.SI<NewtonMeter>(); @@ -148,13 +148,13 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent var container = new VehicleContainer(); var gearboxData = DeclarationModeSimulationDataReader.CreateGearboxDataFromFile(GearboxDataFile, EngineDataFile); var gearbox = new Gearbox(container, gearboxData, new AMTShiftStrategy(gearboxData, container)); - var driver = new MockDriver(container); var port = new MockTnOutPort(); gearbox.InPort().Connect(port); container.Engine = port; - gearbox.Gear = 1; + + gearbox.Initialize(0.SI<NewtonMeter>(), 0.RPMtoRad()); var ratio = 6.38; @@ -167,8 +167,8 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent foreach (var exp in expected) { var torque = exp.t.SI<NewtonMeter>() * ratio; var angularVelocity = exp.n.RPMtoRad() / ratio; - var response = gearbox.OutPort().Request(0.SI<Second>(), 1.SI<Second>(), torque, angularVelocity); + Assert.IsInstanceOfType(response, typeof(ResponseSuccess)); } @@ -262,6 +262,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent var driver = new MockDriver(container); var port = new MockTnOutPort(); gearbox.InPort().Connect(port); + var vehicle = new MockVehicle(container) { MyVehicleSpeed = 10.SI<MeterPerSecond>() }; container.Engine = port; var ratios = new[] { 0.0, 6.38, 4.63, 3.44, 2.59, 1.86, 1.35, 1, 0.76 }; @@ -276,16 +277,13 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent new { gear = 3, newGear = 2, t = 1500, n = 750, responseType = typeof(ResponseGearShift) }, new { gear = 2, newGear = 1, t = 1500, n = 750, responseType = typeof(ResponseGearShift) }, new { gear = 1, newGear = 1, t = 1200, n = 700, responseType = typeof(ResponseSuccess) }, - new { gear = 8, newGear = 1, t = 10000, n = 120, responseType = typeof(ResponseGearShift) } + new { gear = 8, newGear = 1, t = 15000, n = 50, responseType = typeof(ResponseGearShift) } }; var absTime = 0.SI<Second>(); var dt = 2.SI<Second>(); - gearbox.OutPort().Initialize(0.SI<NewtonMeter>(), 0.SI<PerSecond>()); - - // just for test case mock driver - driver.VehicleStopped = false; + gearbox.OutPort().Initialize(1.SI<NewtonMeter>(), 1.SI<PerSecond>()); foreach (var exp in expected) { var expectedT = exp.t.SI<NewtonMeter>(); @@ -313,6 +311,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent var gearboxData = DeclarationModeSimulationDataReader.CreateGearboxDataFromFile(GearboxDataFile, EngineDataFile); var gearbox = new Gearbox(container, gearboxData, new AMTShiftStrategy(gearboxData, container)); var driver = new MockDriver(container); + var vehicle = new MockVehicle(container) { MyVehicleSpeed = 10.SI<MeterPerSecond>() }; var port = new MockTnOutPort(); container.Engine = port; gearbox.InPort().Connect(port); @@ -335,8 +334,8 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent var absTime = 0.SI<Second>(); var dt = 2.SI<Second>(); - gearbox.OutPort().Initialize(1000.SI<NewtonMeter>(), 100.SI<PerSecond>()); - var first = gearbox.OutPort().Request(absTime, dt, 1000.SI<NewtonMeter>(), 100.SI<PerSecond>()); + gearbox.OutPort().Initialize(1.SI<NewtonMeter>(), 1.SI<PerSecond>()); + absTime += dt; foreach (var exp in expected) { var expectedT = exp.t.SI<NewtonMeter>(); @@ -356,49 +355,5 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent absTime += dt; } } - - [TestMethod] - public void Gearbox_NoGear() - { - var container = new VehicleContainer(); - var gearboxData = CreateGearboxData(); - var gearbox = new Gearbox(container, gearboxData, new AMTShiftStrategy(gearboxData, container)); - - var driver = new MockDriver(container); - - var port = new MockTnOutPort(); - container.Engine = (IEngineInfo)port; - gearbox.InPort().Connect(port); - - gearbox.Initialize(0.SI<NewtonMeter>(), 0.SI<PerSecond>()); - - var absTime = 0.SI<Second>(); - var dt = 2.SI<Second>(); - - //just for test driver - driver.VehicleStopped = true; - - var response = gearbox.OutPort().Request(absTime, dt, 50.SI<NewtonMeter>(), 1000000.RPMtoRad()); - Assert.IsInstanceOfType(response, typeof(ResponseSuccess)); - AssertHelper.AreRelativeEqual(absTime, port.AbsTime); - AssertHelper.AreRelativeEqual(dt, port.Dt); - Assert.IsNotNull(port.AngularVelocity); - Assert.IsNotNull(port.Torque); - Assert.IsTrue(port.AngularVelocity.IsGreater(0)); - Assert.IsTrue(port.Torque.IsGreater(0)); - - port.DoCommitSimulationStep(); - - driver.VehicleStopped = false; - - absTime += dt; - - response = gearbox.OutPort().Request(absTime, dt, 5000.SI<NewtonMeter>(), 100.SI<PerSecond>()); - Assert.IsInstanceOfType(response, typeof(ResponseGearShift)); - Assert.IsNull(port.AbsTime); - Assert.IsNull(port.Dt); - Assert.IsNull(port.AngularVelocity); - Assert.IsNull(port.Torque); - } } } \ No newline at end of file diff --git a/VectoCoreTest/Utils/MockDriver.cs b/VectoCoreTest/Utils/MockDriver.cs index 971d6f394c..10183c6a30 100644 --- a/VectoCoreTest/Utils/MockDriver.cs +++ b/VectoCoreTest/Utils/MockDriver.cs @@ -86,7 +86,7 @@ namespace TUGraz.VectoCore.Tests.Utils public DrivingBehavior DrivingBehavior { - get { throw new NotImplementedException(); } + get { return DrivingBehavior.Accelerating; } } } } \ No newline at end of file -- GitLab