Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit bb98d960 authored by Harald MARTINI's avatar Harald MARTINI
Browse files

removed mockup property from simulatorfactory, added tests for primary and completed bus

parent f3ad2847
No related branches found
No related tags found
No related merge requests found
......@@ -72,11 +72,11 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl.SimulatorFactory
protected bool _simulate = true;
//TODO: set with preprocessor directive remove from interface
#if MOCKUPDEBUG
public static bool MockUpRun { get; set; } = true;
#else
public static bool MockUpRun { get; set; } = false;
#endif
//#if MOCKUPDEBUG
// public static bool MockUpRun { get; set; } = true;
//#else
// public static bool MockUpRun { get; set; } = false;
//#endif
public ISimulatorFactory FollowUpSimulatorFactory
{
......@@ -175,7 +175,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl.SimulatorFactory
}
private IVectoRun GetExemptedRun(VectoRunData data)
protected virtual IVectoRun GetExemptedRun(VectoRunData data)
{
if (data.Report != null) {
data.Report.PrepareResult(data.Loading, data.Mission, data.EngineData?.FuelMode ?? 0, data);
......@@ -187,15 +187,15 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl.SimulatorFactory
});
}
private IVectoRun GetNonExemptedRun(VectoRunData data, int current, VectoRunData d, ref bool warning1Hz)
protected virtual IVectoRun GetNonExemptedRun(VectoRunData data, int current, VectoRunData d, ref bool warning1Hz)
{
var addReportResult = PrepareReport(data);
if (MockUpRun)
{
return new MockupRun(new VehicleContainer(ExecutionMode.Declaration,
new ModalDataContainer(data, ReportWriter, addReportResult))
{ RunData = data });
}
//if (MockUpRun)
//{
// return new MockupRun(new VehicleContainer(ExecutionMode.Declaration,
// new ModalDataContainer(data, ReportWriter, addReportResult))
// { RunData = data });
//}
if (!data.Cycle.CycleType.IsDistanceBased() && ModalResults1Hz && !warning1Hz) {
Log.Error("Output filter for 1Hz results is only available for distance-based cycles!");
warning1Hz = true;
......@@ -295,7 +295,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl.SimulatorFactory
return run;
}
private static Action<ModalDataContainer> PrepareReport(VectoRunData data)
protected static Action<ModalDataContainer> PrepareReport(VectoRunData data)
{
if (data.Report != null) {
data.Report.PrepareResult(data.Loading, data.Mission, data.EngineData?.FuelMode ?? 0, data);
......
using System.IO;
using System.Xml;
using System.Xml.Linq;
using Ninject;
using NUnit.Framework;
using TUGraz.VectoCommon.InputData;
using TUGraz.VectoCommon.Models;
using TUGraz.VectoCore;
using TUGraz.VectoCore.InputData.FileIO.XML;
using TUGraz.VectoCore.InputData.FileIO.XML.Declaration.DataProvider;
using TUGraz.VectoCore.Models.Simulation;
using TUGraz.VectoCore.Models.Simulation.Impl;
using TUGraz.VectoCore.Models.Simulation.Impl.SimulatorFactory;
......@@ -75,6 +78,10 @@ namespace VectoMockupTest
protected const string PEV_IEPC_PrimaryBus =
@"TestData\XML\XMLReaderDeclaration\SchemaVersion2.4\Distributed\PrimaryBus\IEPC_primaryBus.xml";
protected const string Conventional_InterimBus =
@"TestData\XML\XMLReaderDeclaration\SchemaVersionMultistage.0.1\vecto_multistage_consolidated_multiple_stages.xml";
protected const string Conventional_CompletedBus = @"TestData\XML\XMLReaderDeclaration\SchemaVersionMultistage.0.1\vecto_multistage_conventional_final_vif.VIF_Report_1.xml";
......@@ -97,7 +104,7 @@ namespace VectoMockupTest
[SetUp]
public void Setup()
{
SimulatorFactory.MockUpRun = true;
//SimulatorFactory.MockUpRun = true;
}
......@@ -126,10 +133,10 @@ namespace VectoMockupTest
[TestCase(PEV_E4_HeavyLorry, TestName = "PEV_E4_HeavyLorry")]
[TestCase(PEV_IEPC_HeavyLorry, TestName = "PEV_IEPC_HeavyLorry")]
[TestCase(HEV_IEPC_S_HeavyLorry, TestName = "HEV_IEPC_S_HeavyLorry")]
[NonParallelizable]
//[NonParallelizable]
public void HeavyLorryMockupTest(string fileName, bool mockup = true)
{
SimulatorFactory.MockUpRun = mockup;
var inputProvider = _inputDataReader.Create(fileName);
var fileWriter = GetOutputFileWriter(TestContext.CurrentContext.Test.Name, fileName);
var sumWriter = new SummaryDataContainer(fileWriter);
......@@ -150,7 +157,6 @@ namespace VectoMockupTest
[TestCase(Conventional_PrimaryBus, TestName = "ConventionalPrimaryBus")]
public void PrimaryBusMockupTest(string fileName, bool mockup = true)
{
SimulatorFactory.MockUpRun = mockup;
var inputProvider = _inputDataReader.Create(fileName);
var fileWriter = GetOutputFileWriter(TestContext.CurrentContext.Test.Name, fileName);
var sumWriter = new SummaryDataContainer(fileWriter);
......@@ -162,21 +168,72 @@ namespace VectoMockupTest
jobContainer.AddRuns(_simulatorFactory);
jobContainer.Execute(false);
jobContainer.WaitFinished();
CheckFileExists(fileWriter);
CheckFileExists(fileWriter, checkCif:false, checkVif:true);
}
[TestCase(Conventional_InterimBus, TestName = "ConventionalInterimBus")]
public void InterimBusMockupTest(string fileName)
{
//SimulatorFactory.MockUpRun = mockup;
var inputProvider = _inputDataReader.Create(fileName);
var fileWriter = GetOutputFileWriter(TestContext.CurrentContext.Test.Name, fileName);
var sumWriter = new SummaryDataContainer(fileWriter);
var jobContainer = new JobContainer(sumWriter);
_simulatorFactory =
_simFactoryFactory.Factory(ExecutionMode.Declaration, inputProvider, fileWriter, null, null, true);
jobContainer.AddRuns(_simulatorFactory);
jobContainer.Execute(false);
jobContainer.WaitFinished();
CheckFileExists(fileWriter, checkCif: false, checkVif: true);
}
private static void CheckFileExists(FileOutputWriter fileWriter)
[TestCase(Conventional_CompletedBus, TestName = "ConventionalCompletedBus")]
public void CompletedBusMockupTest(string fileName)
{
if (!File.Exists(fileWriter.XMLCustomerReportName)) {
//SimulatorFactory.MockUpRun = mockup;
XMLDeclarationVIFInputData input = null;
var fileWriter = new FileOutputWriter(fileName);
using (var reader = XmlReader.Create(fileName))
{
input = new XMLDeclarationVIFInputData(_inputDataReader.Create(fileName) as IMultistageBusInputDataProvider, null);
fileWriter = new FileOutputVIFWriter(fileName, input.MultistageJobInputData.JobInputData.ManufacturingStages.Count);
}
var sumWriter = new SummaryDataContainer(fileWriter);
var jobContainer = new JobContainer(sumWriter);
_simulatorFactory =
_simFactoryFactory.Factory(ExecutionMode.Declaration, input, fileWriter, null, null, true);
jobContainer.AddRuns(_simulatorFactory);
jobContainer.Execute(false);
jobContainer.WaitFinished();
CheckFileExists(fileWriter, checkCif: false, checkVif: true);
}
private static void CheckFileExists(FileOutputWriter fileWriter, bool checkMrf = true, bool checkCif = true, bool checkVif = false)
{
if (checkCif && !File.Exists(fileWriter.XMLCustomerReportName)) {
TestContext.WriteLine(fileWriter.XMLCustomerReportName);
Assert.Fail();
}
if (!File.Exists(fileWriter.XMLFullReportName))
if (checkMrf && !File.Exists(fileWriter.XMLFullReportName))
{
TestContext.WriteLine(fileWriter.XMLFullReportName);
Assert.Fail();
}
if (checkVif && !File.Exists(fileWriter.XMLPrimaryVehicleReportName)) {
TestContext.WriteLine(fileWriter.XMLPrimaryVehicleReportName);
Assert.Fail();
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment