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

Skip to content
Snippets Groups Projects
Commit f7704228 authored by Markus Quaritsch's avatar Markus Quaritsch
Browse files

more testcases work

parent d907c6f6
No related branches found
No related tags found
No related merge requests found
......@@ -5,8 +5,10 @@ using System.IO;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
using NLog;
using TUGraz.VectoCore.Exceptions;
using TUGraz.VectoCore.InputData.Impl;
using TUGraz.VectoCore.Models.Declaration;
using TUGraz.VectoCore.Models.SimulationComponent.Data;
using TUGraz.VectoCore.Utils;
......@@ -240,10 +242,29 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON
{
get
{
return Body[JsonKeys.Job_Cycles].Select(cycle => new CycleInputData() {
Name = Path.GetFileNameWithoutExtension(cycle.Value<string>()),
CycleData = VectoCSVFile.Read(Path.Combine(BasePath, cycle.Value<string>()))
}).Cast<ICycleData>().ToList();
var retVal = new List<ICycleData>();
foreach (var cycle in Body[JsonKeys.Job_Cycles]) {
//.Select(cycle =>
var cycleFile = Path.Combine(BasePath, cycle.Value<string>());
DataTable cycleData;
if (File.Exists(cycleFile)) {
cycleData = VectoCSVFile.Read(cycleFile);
} else {
try {
var cycleDataRes =
RessourceHelper.ReadStream(RessourceHelper.Namespace + "MissionCycles." + cycle.Value<string>() + ".vdri");
cycleData = VectoCSVFile.ReadStream(cycleDataRes);
} catch {
// todo: log?
cycleData = null;
}
}
retVal.Add(new CycleInputData() {
Name = Path.GetFileNameWithoutExtension(cycle.Value<string>()),
CycleData = cycleData
});
}
return retVal;
}
}
......@@ -314,7 +335,11 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON
public DataTable AccelerationCurve
{
get { return ReadTableData(Body[JsonKeys.DriverData_AccelerationCurve].Value<string>(), "DriverAccelerationCurve"); }
get
{
var accelerationFile = Body[JsonKeys.DriverData_AccelerationCurve].Value<string>();
return EmptyOrInvalidFileName(accelerationFile) ? null : ReadTableData(accelerationFile, "DriverAccelerationCurve");
}
}
#endregion
......
......@@ -247,6 +247,10 @@ namespace TUGraz.VectoCore.InputData.Reader
{
public IEnumerable<DrivingCycleData.DrivingCycleEntry> Parse(DataTable table)
{
if (table == null) {
Logger<DistanceBasedDataParser>().Warn("Invalid data for DistanceBasedDrivingCycle -- null");
throw new VectoException("Invalid data for DistanceBasedDrivingCycle -- null");
}
ValidateHeader(table.Columns.Cast<DataColumn>().Select(col => col.ColumnName).ToArray());
return table.Rows.Cast<DataRow>().Select(row => new DrivingCycleData.DrivingCycleEntry {
......
......@@ -110,14 +110,11 @@
<Compile Include="Exceptions\VectoExceptions.cs" />
<Compile Include="Exceptions\VectoSimulationException.cs" />
<Compile Include="InputData\Impl\InputData.cs" />
<Compile Include="InputData\FileIO\InputFileReader.cs" />
<Compile Include="InputData\FileIO\JsonDataHeader.cs" />
<Compile Include="InputData\FileIO\JSON\JSONEngineData.cs" />
<Compile Include="InputData\FileIO\JSON\JSONGearboxData.cs" />
<Compile Include="InputData\FileIO\JSON\JSONInputData.cs" />
<Compile Include="InputData\FileIO\JSON\JSONInputDataFactory.cs" />
<Compile Include="InputData\FileIO\JSON\JSONVehicleData.cs" />
<Compile Include="InputData\FileIO\VectoFiles.cs" />
<Compile Include="InputData\IInputDataProvider.cs" />
<Compile Include="InputData\InputData.cs" />
<Compile Include="InputData\IVectoRunDataFactory.cs" />
......@@ -189,11 +186,6 @@
<Compile Include="OutputData\ModalDataContainer.cs" />
<Compile Include="OutputData\PDF\DeclarationReport.cs" />
<Compile Include="OutputData\SummaryDataContainer.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Properties\Version.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
......@@ -281,10 +273,6 @@
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="JsonKeys.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>JsonKeys.Designer.cs</LastGenOutput>
......
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TUGraz.VectoCore.Configuration;
using TUGraz.VectoCore.InputData.FileIO.JSON;
using TUGraz.VectoCore.Models.Simulation.Data;
using TUGraz.VectoCore.Models.Simulation.Impl;
using TUGraz.VectoCore.Models.SimulationComponent.Impl;
using TUGraz.VectoCore.OutputData.FileIO;
using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.Tests.Models.Simulation
......@@ -18,67 +20,66 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation
[TestMethod]
public void CreateDeclarationSimulationRun()
{
var resultFileName = "test.vmod";
var sumFileName = resultFileName.Substring(0, resultFileName.Length - 5) + Constants.FileExtensions.SumFile;
var fileWriter = new FileOutputWriter(DeclarationJobFile);
//var dataWriter = new ModalDataWriter(resultFileName, engineOnly: true);
var sumWriter = new SummaryFileWriter(sumFileName);
var inputData = JSONInputDataFactory.ReadJsonJob(DeclarationJobFile);
var factory = new SimulatorFactory(SimulatorFactory.FactoryMode.DeclarationMode, inputData, fileWriter);
var factory = new SimulatorFactory(SimulatorFactory.FactoryMode.DeclarationMode) { SumWriter = sumWriter };
factory.DataReader.SetJobFile(DeclarationJobFile);
//factory.DataReader.SetJobFile(DeclarationJobFile);
var run = factory.SimulationRuns().First();
var vehicleContainer = (VehicleContainer) run.GetContainer();
var vehicleContainer = (VehicleContainer)run.GetContainer();
Assert.AreEqual(9, vehicleContainer._components.Count);
Assert.AreEqual(10, vehicleContainer.Components.Count);
Assert.IsInstanceOfType(vehicleContainer._gearbox, typeof (Gearbox), "gearbox not installed");
Assert.IsInstanceOfType(vehicleContainer._engine, typeof (CombustionEngine), "engine not installed");
Assert.IsInstanceOfType(vehicleContainer._vehicle, typeof (Vehicle), "vehicle not installed");
Assert.IsInstanceOfType(vehicleContainer.Gearbox, typeof(Gearbox), "gearbox not installed");
Assert.IsInstanceOfType(vehicleContainer.Engine, typeof(CombustionEngine), "engine not installed");
Assert.IsInstanceOfType(vehicleContainer.Vehicle, typeof(Vehicle), "vehicle not installed");
var gearbox = vehicleContainer._gearbox as Gearbox;
var gearbox = vehicleContainer.Gearbox as Gearbox;
Assert.IsNotNull(gearbox);
// -- shiftpolygon downshift
Assert.AreEqual(600.RPMtoRad().Double(), gearbox.Data[1].ShiftPolygon.Downshift[0].AngularSpeed.Double(), 0.0001);
Assert.AreEqual(0.0, gearbox.Data[1].ShiftPolygon.Downshift[0].Torque.Double(), 0.0001);
Assert.AreEqual(600.RPMtoRad().Value(), gearbox.Data.Gears[1].ShiftPolygon.Downshift[0].AngularSpeed.Value(), 0.0001);
Assert.AreEqual(0.0, gearbox.Data.Gears[1].ShiftPolygon.Downshift[0].Torque.Value(), 0.0001);
Assert.AreEqual(600.RPMtoRad().Double(), gearbox.Data[1].ShiftPolygon.Downshift[1].AngularSpeed.Double(), 0.0001);
Assert.AreEqual(266.8277, gearbox.Data[1].ShiftPolygon.Downshift[1].Torque.Double(), 0.1);
Assert.AreEqual(600.RPMtoRad().Value(), gearbox.Data.Gears[1].ShiftPolygon.Downshift[1].AngularSpeed.Value(), 0.0001);
Assert.AreEqual(266.8277, gearbox.Data.Gears[1].ShiftPolygon.Downshift[1].Torque.Value(), 0.1);
Assert.AreEqual(1310.7646.RPMtoRad().Double(), gearbox.Data[1].ShiftPolygon.Downshift[2].AngularSpeed.Double(), 0.1);
Assert.AreEqual(899, gearbox.Data[1].ShiftPolygon.Downshift[2].Torque.Double(), 0.0001);
Assert.AreEqual(1310.7646.RPMtoRad().Value(), gearbox.Data.Gears[1].ShiftPolygon.Downshift[2].AngularSpeed.Value(),
0.1);
Assert.AreEqual(899, gearbox.Data.Gears[1].ShiftPolygon.Downshift[2].Torque.Value(), 0.0001);
// -- shiftpolygon upshift
Assert.AreEqual(1531.5293.RPMtoRad().Double(), gearbox.Data[1].ShiftPolygon.Upshift[0].AngularSpeed.Double(), 0.1);
Assert.AreEqual(0, gearbox.Data[1].ShiftPolygon.Upshift[0].Torque.Double(), 0.0001);
Assert.AreEqual(1531.5293.RPMtoRad().Value(), gearbox.Data.Gears[1].ShiftPolygon.Upshift[0].AngularSpeed.Value(), 0.1);
Assert.AreEqual(0, gearbox.Data.Gears[1].ShiftPolygon.Upshift[0].Torque.Value(), 0.0001);
Assert.AreEqual(1531.5293.RPMtoRad().Double(), gearbox.Data[1].ShiftPolygon.Upshift[1].AngularSpeed.Double(), 0.1);
Assert.AreEqual(459.881, gearbox.Data[1].ShiftPolygon.Upshift[1].Torque.Double(), 0.1);
Assert.AreEqual(1531.5293.RPMtoRad().Value(), gearbox.Data.Gears[1].ShiftPolygon.Upshift[1].AngularSpeed.Value(), 0.1);
Assert.AreEqual(459.881, gearbox.Data.Gears[1].ShiftPolygon.Upshift[1].Torque.Value(), 0.1);
Assert.AreEqual(2421.RPMtoRad().Double(), gearbox.Data[1].ShiftPolygon.Upshift[2].AngularSpeed.Double(), 0.1);
Assert.AreEqual(899, gearbox.Data[1].ShiftPolygon.Upshift[2].Torque.Double(), 0.1);
Assert.AreEqual(2421.RPMtoRad().Value(), gearbox.Data.Gears[1].ShiftPolygon.Upshift[2].AngularSpeed.Value(), 0.1);
Assert.AreEqual(899, gearbox.Data.Gears[1].ShiftPolygon.Upshift[2].Torque.Value(), 0.1);
}
[TestMethod]
public void CreateEngineeringSimulationRun()
{
var factory = new SimulatorFactory(SimulatorFactory.FactoryMode.EngineeringMode);
var fileWriter = new FileOutputWriter(EngineeringJobFile);
factory.DataReader.SetJobFile(EngineeringJobFile);
var inputData = JSONInputDataFactory.ReadJsonJob(EngineeringJobFile);
var factory = new SimulatorFactory(SimulatorFactory.FactoryMode.EngineeringMode, inputData, fileWriter);
var run = factory.SimulationRuns().First();
var vehicleContainer = (VehicleContainer) run.GetContainer();
Assert.AreEqual(10, vehicleContainer._components.Count);
var vehicleContainer = (VehicleContainer)run.GetContainer();
Assert.AreEqual(11, vehicleContainer.Components.Count);
Assert.IsInstanceOfType(vehicleContainer._gearbox, typeof (Gearbox), "gearbox not installed");
Assert.IsInstanceOfType(vehicleContainer._engine, typeof (CombustionEngine), "engine not installed");
Assert.IsInstanceOfType(vehicleContainer._vehicle, typeof (Vehicle), "vehicle not installed");
Assert.IsInstanceOfType(vehicleContainer.Gearbox, typeof(Gearbox), "gearbox not installed");
Assert.IsInstanceOfType(vehicleContainer.Engine, typeof(CombustionEngine), "engine not installed");
Assert.IsInstanceOfType(vehicleContainer.Vehicle, typeof(Vehicle), "vehicle not installed");
}
}
}
\ No newline at end of file
......@@ -11,9 +11,9 @@
"EngineFile": "../Components/12t Delivery Truck.veng",
"GearboxFile": "../Components/12t Delivery Truck.vgbx",
"Cycles": [
"Long Haul",
"Regional Delivery",
"Urban Delivery"
"LongHaul",
"RegionalDelivery",
"UrbanDelivery"
],
"Aux": [
{
......
......@@ -76,6 +76,7 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="Integration\DeclarationReportTest.cs" />
<Compile Include="Models\Simulation\FactoryTest.cs" />
<Compile Include="Reports\SumWriterTest.cs" />
<Compile Include="Utils\GraphWriter.cs" />
<Compile Include="Integration\EngineOnlyCycle\EngineOnlyCycleTest.cs" />
......
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