From 229662bcea534fb85a99b10c5bd0674395af2e5f Mon Sep 17 00:00:00 2001 From: Michael Krisper <michael.krisper@tugraz.at> Date: Mon, 13 Jun 2016 14:09:22 +0200 Subject: [PATCH] added test files, added missing ValidateObject Attributes --- .../SimulationComponent/Data/AxleGearData.cs | 3 +- .../SimulationComponent/Impl/AxleGear.cs | 3 +- .../Models/SimulationComponent/GearboxTest.cs | 26 ++++-- .../Components/AxleGearInvalidRange.vgbx | 90 +++++++++++++++++++ .../Components/AxleGearValidRange.vgbx | 90 +++++++++++++++++++ .../TestData/Components/AxleInvalid.vtlm | 8 ++ .../TestData/Components/AxleValid.vtlm | 6 ++ VectoCore/VectoCoreTest/VectoCoreTest.csproj | 12 +++ 8 files changed, 230 insertions(+), 8 deletions(-) create mode 100644 VectoCore/VectoCoreTest/TestData/Components/AxleGearInvalidRange.vgbx create mode 100644 VectoCore/VectoCoreTest/TestData/Components/AxleGearValidRange.vgbx create mode 100644 VectoCore/VectoCoreTest/TestData/Components/AxleInvalid.vtlm create mode 100644 VectoCore/VectoCoreTest/TestData/Components/AxleValid.vtlm diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Data/AxleGearData.cs b/VectoCore/VectoCore/Models/SimulationComponent/Data/AxleGearData.cs index 2bd8d6f8f9..72f567e92c 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Data/AxleGearData.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Data/AxleGearData.cs @@ -30,11 +30,12 @@ */ using TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox; +using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.SimulationComponent.Data { public class AxleGearData : SimulationComponentData { - public GearData AxleGear; + [ValidateObject] public GearData AxleGear; } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/AxleGear.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/AxleGear.cs index f8fa67be3d..568d60ea80 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/AxleGear.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/AxleGear.cs @@ -37,6 +37,7 @@ using TUGraz.VectoCore.Models.Simulation; using TUGraz.VectoCore.Models.Simulation.Data; using TUGraz.VectoCore.Models.SimulationComponent.Data; using TUGraz.VectoCore.OutputData; +using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { @@ -45,7 +46,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { protected ITnOutPort NextComponent; - internal readonly AxleGearData ModelData; + [ValidateObject] internal readonly AxleGearData ModelData; public AxleGear(IVehicleContainer container, AxleGearData modelData) : base(container) { diff --git a/VectoCore/VectoCoreTest/Models/SimulationComponent/GearboxTest.cs b/VectoCore/VectoCoreTest/Models/SimulationComponent/GearboxTest.cs index d57756c7ad..d12aff8fdf 100644 --- a/VectoCore/VectoCoreTest/Models/SimulationComponent/GearboxTest.cs +++ b/VectoCore/VectoCoreTest/Models/SimulationComponent/GearboxTest.cs @@ -68,7 +68,8 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent public const string GearboxShiftPolygonFile = @"TestData\Components\ShiftPolygons.vgbs"; public const string GearboxFullLoadCurveFile = @"TestData\Components\Gearbox.vfld"; - public TestContext TestContext { get; set; } + public const string AxleGearValidRangeDataFile = @"TestData\Components\AxleGearValidRange.vgbx"; + public const string AxleGearInvalidRangeDataFile = @"TestData\Components\AxleGearInvalidRange.vgbx"; private static GearboxData CreateGearboxData() { @@ -124,6 +125,24 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent "AngularVelocity Engine Side"); } + [TestCase] + public void AxleGearValidRangeTest() + { + var vehicle = new VehicleContainer(ExecutionMode.Engineering); + var axleGearData = MockSimulationDataFactory.CreateAxleGearDataFromFile(AxleGearValidRangeDataFile); + var axleGear = new AxleGear(vehicle, axleGearData); + Assert.AreEqual(0, axleGear.Validate().Count); + } + + [TestCase] + public void AxleGearInvalidRangeTest() + { + var vehicle = new VehicleContainer(ExecutionMode.Engineering); + var axleGearData = MockSimulationDataFactory.CreateAxleGearDataFromFile(AxleGearInvalidRangeDataFile); + var axleGear = new AxleGear(vehicle, axleGearData); + var errors = axleGear.Validate(); + Assert.AreEqual(1, errors.Count); + } [Test, TestCase(@"TestData\Components\24t Coach LessThanTwoGears.vgbx")] @@ -359,7 +378,6 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent var ratios = new[] { 0.0, 6.38, 4.63, 3.44, 2.59, 1.86, 1.35, 1, 0.76 }; // the first element 0.0 is just a placeholder for axlegear, not used in this test - var absTime = 0.SI<Second>(); var dt = 2.SI<Second>(); @@ -370,7 +388,6 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent var torque = (expectedT - expectedLoss) * ratios[gear]; var angularVelocity = expectedN / ratios[gear]; - gearbox.OutPort().Initialize(torque, angularVelocity); gearbox.Gear = (uint)gear; var response = gearbox.OutPort().Request(absTime, dt, torque, angularVelocity); @@ -384,7 +401,6 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent } } - [Test, TestCase(8, 7, 1500, 750, typeof(ResponseGearShift)), TestCase(7, 6, 1500, 750, typeof(ResponseGearShift)), @@ -410,13 +426,11 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent var ratios = new[] { 0.0, 6.38, 4.63, 3.44, 2.59, 1.86, 1.35, 1, 0.76 }; // the first element 0.0 is just a placeholder for axlegear, not used in this test - var absTime = 0.SI<Second>(); var dt = 2.SI<Second>(); gearbox.OutPort().Initialize(1.SI<NewtonMeter>(), 1.SI<PerSecond>()); - var expectedT = t.SI<NewtonMeter>(); var expectedN = n.RPMtoRad(); diff --git a/VectoCore/VectoCoreTest/TestData/Components/AxleGearInvalidRange.vgbx b/VectoCore/VectoCoreTest/TestData/Components/AxleGearInvalidRange.vgbx new file mode 100644 index 0000000000..760da5d3f8 --- /dev/null +++ b/VectoCore/VectoCoreTest/TestData/Components/AxleGearInvalidRange.vgbx @@ -0,0 +1,90 @@ +{ + "Header": { + "CreatedBy": " ()", + "Date": "8/21/2015 10:16:31 AM", + "AppVersion": "2.2 beta-2", + "FileVersion": 5 + }, + "Body": { + "SavedInDeclMode": false, + "ModelName": "Generic 24t Coach", + "Inertia": 0.0, + "TracInt": 1.0, + "Gears": [ + { + "Ratio": 3.240355, + "LossMap": "AxleInvalid.vtlm" + }, + { + "Ratio": 6.38, + "LossMap": "Indirect Gear.vtlm", + "TCactive": false, + "ShiftPolygon": "ShiftPolygons.vgbs", + "FullLoadCurve": "<NOFILE>" + }, + { + "Ratio": 4.63, + "LossMap": "Indirect Gear.vtlm", + "TCactive": false, + "ShiftPolygon": "ShiftPolygons.vgbs", + "FullLoadCurve": "<NOFILE>" + }, + { + "Ratio": 3.44, + "LossMap": "Indirect Gear.vtlm", + "TCactive": false, + "ShiftPolygon": "ShiftPolygons.vgbs", + "FullLoadCurve": "<NOFILE>" + }, + { + "Ratio": 2.59, + "LossMap": "Indirect Gear.vtlm", + "TCactive": false, + "ShiftPolygon": "ShiftPolygons.vgbs", + "FullLoadCurve": "<NOFILE>" + }, + { + "Ratio": 1.86, + "LossMap": "Indirect Gear.vtlm", + "TCactive": false, + "ShiftPolygon": "ShiftPolygons.vgbs", + "FullLoadCurve": "<NOFILE>" + }, + { + "Ratio": 1.35, + "LossMap": "Indirect Gear.vtlm", + "TCactive": false, + "ShiftPolygon": "ShiftPolygons.vgbs", + "FullLoadCurve": "<NOFILE>" + }, + { + "Ratio": 1.0, + "LossMap": "Direct Gear.vtlm", + "TCactive": false, + "ShiftPolygon": "ShiftPolygons.vgbs", + "FullLoadCurve": "<NOFILE>" + }, + { + "Ratio": 0.76, + "LossMap": "Indirect Gear.vtlm", + "TCactive": false, + "ShiftPolygon": "ShiftPolygons.vgbs", + "FullLoadCurve": "<NOFILE>" + } + ], + "TqReserve": 20.0, + "SkipGears": true, + "ShiftTime": 2, + "EaryShiftUp": true, + "StartTqReserve": 20.0, + "StartSpeed": 2.0, + "StartAcc": 0.6, + "GearboxType": "AMT", + "TorqueConverter": { + "Enabled": false, + "File": "<NOFILE>", + "RefRPM": 0.0, + "Inertia": 0.0 + } + } +} \ No newline at end of file diff --git a/VectoCore/VectoCoreTest/TestData/Components/AxleGearValidRange.vgbx b/VectoCore/VectoCoreTest/TestData/Components/AxleGearValidRange.vgbx new file mode 100644 index 0000000000..2079420a65 --- /dev/null +++ b/VectoCore/VectoCoreTest/TestData/Components/AxleGearValidRange.vgbx @@ -0,0 +1,90 @@ +{ + "Header": { + "CreatedBy": " ()", + "Date": "8/21/2015 10:16:31 AM", + "AppVersion": "2.2 beta-2", + "FileVersion": 5 + }, + "Body": { + "SavedInDeclMode": false, + "ModelName": "Generic 24t Coach", + "Inertia": 0.0, + "TracInt": 1.0, + "Gears": [ + { + "Ratio": 3.240355, + "LossMap": "AxleValid.vtlm" + }, + { + "Ratio": 6.38, + "LossMap": "Indirect Gear.vtlm", + "TCactive": false, + "ShiftPolygon": "ShiftPolygons.vgbs", + "FullLoadCurve": "<NOFILE>" + }, + { + "Ratio": 4.63, + "LossMap": "Indirect Gear.vtlm", + "TCactive": false, + "ShiftPolygon": "ShiftPolygons.vgbs", + "FullLoadCurve": "<NOFILE>" + }, + { + "Ratio": 3.44, + "LossMap": "Indirect Gear.vtlm", + "TCactive": false, + "ShiftPolygon": "ShiftPolygons.vgbs", + "FullLoadCurve": "<NOFILE>" + }, + { + "Ratio": 2.59, + "LossMap": "Indirect Gear.vtlm", + "TCactive": false, + "ShiftPolygon": "ShiftPolygons.vgbs", + "FullLoadCurve": "<NOFILE>" + }, + { + "Ratio": 1.86, + "LossMap": "Indirect Gear.vtlm", + "TCactive": false, + "ShiftPolygon": "ShiftPolygons.vgbs", + "FullLoadCurve": "<NOFILE>" + }, + { + "Ratio": 1.35, + "LossMap": "Indirect Gear.vtlm", + "TCactive": false, + "ShiftPolygon": "ShiftPolygons.vgbs", + "FullLoadCurve": "<NOFILE>" + }, + { + "Ratio": 1.0, + "LossMap": "Direct Gear.vtlm", + "TCactive": false, + "ShiftPolygon": "ShiftPolygons.vgbs", + "FullLoadCurve": "<NOFILE>" + }, + { + "Ratio": 0.76, + "LossMap": "Indirect Gear.vtlm", + "TCactive": false, + "ShiftPolygon": "ShiftPolygons.vgbs", + "FullLoadCurve": "<NOFILE>" + } + ], + "TqReserve": 20.0, + "SkipGears": true, + "ShiftTime": 2, + "EaryShiftUp": true, + "StartTqReserve": 20.0, + "StartSpeed": 2.0, + "StartAcc": 0.6, + "GearboxType": "AMT", + "TorqueConverter": { + "Enabled": false, + "File": "<NOFILE>", + "RefRPM": 0.0, + "Inertia": 0.0 + } + } +} \ No newline at end of file diff --git a/VectoCore/VectoCoreTest/TestData/Components/AxleInvalid.vtlm b/VectoCore/VectoCoreTest/TestData/Components/AxleInvalid.vtlm new file mode 100644 index 0000000000..6bcb2735fe --- /dev/null +++ b/VectoCore/VectoCoreTest/TestData/Components/AxleInvalid.vtlm @@ -0,0 +1,8 @@ +Input Speed [rpm],Input Torque [Nm],Torque Loss [Nm],Eff [-] +0,0,0 +-1,-100000,100 +-1,100000,100 +0,-100001,100 +0,100001,100 +5001,-100000,100 +5001,100000,100 \ No newline at end of file diff --git a/VectoCore/VectoCoreTest/TestData/Components/AxleValid.vtlm b/VectoCore/VectoCoreTest/TestData/Components/AxleValid.vtlm new file mode 100644 index 0000000000..2a285b6e26 --- /dev/null +++ b/VectoCore/VectoCoreTest/TestData/Components/AxleValid.vtlm @@ -0,0 +1,6 @@ +Input Speed [rpm],Input Torque [Nm],Torque Loss [Nm],Eff [-] +0,0,0 +0,-100000,100 +0,100000,100 +5000,-100000,100 +5000,100000,100 \ No newline at end of file diff --git a/VectoCore/VectoCoreTest/VectoCoreTest.csproj b/VectoCore/VectoCoreTest/VectoCoreTest.csproj index 529dc58fc4..3197d49a96 100644 --- a/VectoCore/VectoCoreTest/VectoCoreTest.csproj +++ b/VectoCore/VectoCoreTest/VectoCoreTest.csproj @@ -189,6 +189,18 @@ <None Include="TestData\Components\12t Delivery Truck.vveh"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> + <None Include="TestData\Components\AxleInvalid.vtlm"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </None> + <None Include="TestData\Components\AxleValid.vtlm"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </None> + <None Include="TestData\Components\AxleGearInvalidRange.vgbx"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </None> + <None Include="TestData\Components\AxleGearValidRange.vgbx"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </None> <None Include="TestData\Components\24t Coach_IncPT1.vfld"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> -- GitLab