From a2440dfcdf68a4d352be31c6b23dc61d9fad902c Mon Sep 17 00:00:00 2001 From: Markus Quaritsch <markus.quaritsch@tugraz.at> Date: Mon, 27 Jul 2015 09:14:10 +0200 Subject: [PATCH] test for powertrainbuilder --- .../FileIO/EngineeringFile/JobFileEng.cs | 2 +- .../EngineeringDataAdapter.cs | 2 +- .../EngineeringModeSimulationDataReader.cs | 10 +++- .../Simulation/PowerTrainBuilderTest.cs | 39 +++++++++++++ VectoCoreTest/TestData/Jobs/24t Coach.vecto | 56 +++++++++++++++++++ VectoCoreTest/VectoCoreTest.csproj | 5 +- 6 files changed, 108 insertions(+), 6 deletions(-) create mode 100644 VectoCoreTest/Models/Simulation/PowerTrainBuilderTest.cs create mode 100644 VectoCoreTest/TestData/Jobs/24t Coach.vecto diff --git a/VectoCore/FileIO/EngineeringFile/JobFileEng.cs b/VectoCore/FileIO/EngineeringFile/JobFileEng.cs index e1eb78921b..e115c46aa8 100644 --- a/VectoCore/FileIO/EngineeringFile/JobFileEng.cs +++ b/VectoCore/FileIO/EngineeringFile/JobFileEng.cs @@ -76,7 +76,7 @@ namespace TUGraz.VectoCore.FileIO.EngineeringFile [JsonProperty(Required = Required.Always)] public IList<string> Cycles; [JsonProperty] public new IList<AuxDataEng> Aux = new List<AuxDataEng>(); [JsonProperty("VACC", Required = Required.Always)] public string AccelerationCurve; - //[JsonProperty(Required = Required.Always)] public bool EngineOnlyMode; + [JsonProperty] public bool EngineOnlyMode; [JsonProperty(Required = Required.Always)] public new StartStopDataDeclEng StartStop; [JsonProperty("LAC", Required = Required.Always)] public LACDataEng LookAheadCoasting; [JsonProperty(Required = Required.Always)] public new OverSpeedEcoRollDataEng OverSpeedEcoRoll; diff --git a/VectoCore/FileIO/Reader/DataObjectAdaper/EngineeringDataAdapter.cs b/VectoCore/FileIO/Reader/DataObjectAdaper/EngineeringDataAdapter.cs index 249da4494c..f798fd4e38 100644 --- a/VectoCore/FileIO/Reader/DataObjectAdaper/EngineeringDataAdapter.cs +++ b/VectoCore/FileIO/Reader/DataObjectAdaper/EngineeringDataAdapter.cs @@ -63,7 +63,7 @@ namespace TUGraz.VectoCore.FileIO.Reader.DataObjectAdaper { var data = job.Body; - var accelerationData = AccelerationCurveData.ReadFromFile(data.AccelerationCurve); + var accelerationData = AccelerationCurveData.ReadFromFile(Path.Combine(job.BasePath, data.AccelerationCurve)); var lookAheadData = new DriverData.LACData() { Enabled = data.LookAheadCoasting.Enabled, Deceleration = DoubleExtensionMethods.SI<MeterPerSquareSecond>(data.LookAheadCoasting.Dec), diff --git a/VectoCore/FileIO/Reader/Impl/EngineeringModeSimulationDataReader.cs b/VectoCore/FileIO/Reader/Impl/EngineeringModeSimulationDataReader.cs index d724b81765..2a71e8833f 100644 --- a/VectoCore/FileIO/Reader/Impl/EngineeringModeSimulationDataReader.cs +++ b/VectoCore/FileIO/Reader/Impl/EngineeringModeSimulationDataReader.cs @@ -35,11 +35,15 @@ namespace TUGraz.VectoCore.FileIO.Reader.Impl protected override void ProcessJob(VectoJobFile vectoJob) { - var declaration = vectoJob as VectoJobFileV2Engineering; - if (declaration == null) { + var engineering = vectoJob as VectoJobFileV2Engineering; + if (engineering == null) { throw new VectoException("Unhandled Job File Format"); } - var job = declaration; + var job = engineering; + + if (job.Body.EngineOnlyMode) { + throw new VectoException("Job File has been saved in EngineOnlyMode!"); + } ReadVehicle(Path.Combine(job.BasePath, job.Body.VehicleFile)); diff --git a/VectoCoreTest/Models/Simulation/PowerTrainBuilderTest.cs b/VectoCoreTest/Models/Simulation/PowerTrainBuilderTest.cs new file mode 100644 index 0000000000..e1b8d72b40 --- /dev/null +++ b/VectoCoreTest/Models/Simulation/PowerTrainBuilderTest.cs @@ -0,0 +1,39 @@ +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using TUGraz.VectoCore.FileIO.Reader.Impl; +using TUGraz.VectoCore.Models.Connector.Ports; +using TUGraz.VectoCore.Models.Simulation; +using TUGraz.VectoCore.Models.Simulation.Impl; +using TUGraz.VectoCore.Models.SimulationComponent.Impl; +using TUGraz.VectoCore.Tests.Utils; + +namespace TUGraz.VectoCore.Tests.Models.Simulation +{ + [TestClass] + public class PowerTrainBuilderTest + { + public const string JobFile = @"TestData\Jobs\24t Coach.vecto"; + + [TestMethod] + public void BuildFullPowerTrainTest() + { + var reader = new EngineeringModeSimulationDataReader(); + reader.SetJobFile(JobFile); + var runData = reader.NextRun().First(); + + var writer = new TestModalDataWriter(); + var sumWriter = new TestSumWriter(); + var builder = new PowertrainBuilder(writer, sumWriter, false); + + var powerTrain = builder.Build(runData); + + Assert.IsInstanceOfType(powerTrain, typeof(IVehicleContainer)); + Assert.AreEqual(10, powerTrain._components.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)); + } + } +} \ No newline at end of file diff --git a/VectoCoreTest/TestData/Jobs/24t Coach.vecto b/VectoCoreTest/TestData/Jobs/24t Coach.vecto new file mode 100644 index 0000000000..d3d9212a47 --- /dev/null +++ b/VectoCoreTest/TestData/Jobs/24t Coach.vecto @@ -0,0 +1,56 @@ +{ + "Header": { + "CreatedBy": " ()", + "Date": "3/4/2015 2:09:13 PM", + "AppVersion": "2.0.4-beta3", + "FileVersion": 2 + }, + "Body": { + "SavedInDeclMode": false, + "VehicleFile": "../Components/24t Coach.vveh", + "EngineFile": "../Components/24t Coach.veng", + "GearboxFile": "../Components/24t Coach.vgbx", + "Cycles": [ + "../Cycles/Coach_24t_xshort.vdri" + ], + "Aux": [ + { + "ID": "ALT1", + "Type": "Alternator", + "Path": "24t_Coach_ALT.vaux", + "Technology": "" + }, + { + "ID": "ALT2", + "Type": "Alternator", + "Path": "24t_Coach_ALT.vaux", + "Technology": "" + }, + { + "ID": "ALT3", + "Type": "Alternator", + "Path": "24t_Coach_ALT.vaux", + "Technology": "" + } + ], + "VACC": "../Components/Coach.vacc", + "EngineOnlyMode": false, + "StartStop": { + "Enabled": false, + "MaxSpeed": 5.0, + "MinTime": 0.0, + "Delay": 0 + }, + "LAC": { + "Enabled": true, + "Dec": -0.5, + "MinSpeed": 50.0 + }, + "OverSpeedEcoRoll": { + "Mode": "OverSpeed", + "MinSpeed": 70.0, + "OverSpeed": 5.0, + "UnderSpeed": 5.0 + } + } +} \ No newline at end of file diff --git a/VectoCoreTest/VectoCoreTest.csproj b/VectoCoreTest/VectoCoreTest.csproj index c3216b7846..8c3c045555 100644 --- a/VectoCoreTest/VectoCoreTest.csproj +++ b/VectoCoreTest/VectoCoreTest.csproj @@ -236,6 +236,9 @@ <None Include="TestData\Jobs\12t Delivery Truck.vecto"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> + <None Include="TestData\Jobs\24t Coach.vecto"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </None> <None Include="TestData\Jobs\EngineOnlyJob.vecto"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> @@ -251,7 +254,7 @@ <None Include="TestData\Results\EngineOnlyCycles\24tCoach_EngineOnlyFullLoad.vmod"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> - <None Include="TestData\Jobs\24t Coach.vecto"> + <None Include="TestData\Jobs\24t Coach EngineOnly.vecto"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> <None Include="TestData\Results\EngineOnlyCycles\24t Coach.vsum"> -- GitLab