Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS will be completely phased out by mid-2025. To see alternatives please check here

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

Merge pull request #98 in VECTO/vecto-sim from...

Merge pull request #98 in VECTO/vecto-sim from ~EMQUARIMA/vecto-sim:bugfix/VECTO-170-drivingcycle-limits-max-distance to develop

* commit '93e22589':
  add checks for reading driving cycle, additional testcases for drivingcycledata
parents f91c2788 93e22589
No related branches found
No related tags found
No related merge requests found
......@@ -77,6 +77,16 @@ namespace TUGraz.VectoCore.FileIO.Reader
//foreach (var entry in entries) {
for (var i = 0; i < entries.Count; i++) {
var entry = entries[i];
if (!entry.StoppingTime.IsEqual(0) && !entry.VehicleTargetSpeed.IsEqual(0)) {
throw new VectoException(
"Error in DrivingCycle: stop time specified but target-speed > 0! Distance: {0}, stop-time: {1}, target speed: {2}",
entry.Distance, entry.StoppingTime, entry.VehicleTargetSpeed);
}
if (entry.Distance < distance) {
throw new VectoException(
"Error in DrivingCycle: distance entry is smaller than last distance! last distance: {0}, current distance: {1} ",
distance, entry.Distance);
}
if (i > 0) {
altitude += (entry.Distance - distance) * entries[i - 1].RoadGradientPercent / 100.0;
}
......
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TUGraz.VectoCore.Exceptions;
using TUGraz.VectoCore.FileIO.Reader;
using TUGraz.VectoCore.FileIO.Reader.Impl;
using TUGraz.VectoCore.Models.SimulationComponent.Data;
using TUGraz.VectoCore.Models.SimulationComponent.Impl;
using TUGraz.VectoCore.Tests.Integration;
using TUGraz.VectoCore.Tests.Utils;
using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData
......@@ -15,6 +18,81 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData
private const string ResourceNamespace = "TUGraz.VectoCore.Resources.Declaration.";
[TestMethod]
public void FilterRedundantEntries()
{
var data = new[] {
" 0, 20, 0, 0",
" 1, 20, 0, 0",
" 2, 20, 0, 0",
" 3, 20, 0, 0",
" 4, 20, 0, 0",
" 5, 20, 1, 0",
" 6, 20, 1, 0",
" 6, 20, 1, 0",
" 8, 20, 1, 0",
" 9, 20, 1, 0",
};
var cycleData = SimpleDrivingCycles.CreateCycleData(data);
Assert.AreEqual(3, cycleData.Entries.Count);
Assert.AreEqual(0, cycleData.Entries[0].Distance.Value());
Assert.AreEqual(5, cycleData.Entries[1].Distance.Value());
Assert.AreEqual(9, cycleData.Entries[2].Distance.Value());
}
[TestMethod]
public void HandleStopTimes()
{
var data = new[] {
" 0, 20, 0, 0",
" 1, 20, 0, 0",
" 2, 20, 0, 0",
" 3, 20, 0, 0",
" 4, 20, 0, 0",
" 5, 0, 0, 5",
" 6, 20, 0, 0",
" 6, 20, 0, 0",
" 8, 20, 0, 0",
" 9, 20, 0, 0",
};
var cycleData = SimpleDrivingCycles.CreateCycleData(data);
Assert.AreEqual(4, cycleData.Entries.Count);
Assert.AreEqual(0, cycleData.Entries[0].Distance.Value());
Assert.AreEqual(5, cycleData.Entries[1].Distance.Value());
Assert.AreEqual(5, cycleData.Entries[2].Distance.Value());
Assert.AreEqual(9, cycleData.Entries[3].Distance.Value());
Assert.AreEqual(5, cycleData.Entries[1].StoppingTime.Value());
}
[TestMethod]
public void StopTimeWhenVehicleSpeedIsNotZero()
{
var data = new[] {
" 0, 20, 0, 0",
"20, 20, 0, 5",
"90, 20, 0, 0"
};
AssertHelper.Exception<VectoException>(() => SimpleDrivingCycles.CreateCycleData(data));
}
[TestMethod]
public void DistanceNotStrictlyIncreasing()
{
var data = new[] {
" 0, 20, 0, 0",
"90, 20, 0, 0",
"80, 20, 0, 0"
};
AssertHelper.Exception<VectoException>(() => SimpleDrivingCycles.CreateCycleData(data));
}
[TestMethod, Ignore]
public void CycleAltitudeTest()
{
......
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