Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS has been phased out. To see alternatives please check here

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

fix: sorted list does not allow duplicates

parent 0566e0b9
Branches
Tags
No related merge requests found
......@@ -48,8 +48,8 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
{
public class VehicleContainer : LoggingObject, IVehicleContainer
{
internal readonly SortedList<int, VectoSimulationComponent> Components =
new SortedList<int, VectoSimulationComponent>();
private List<Tuple<int, VectoSimulationComponent>> _components =
new List<Tuple<int, VectoSimulationComponent>>();
internal IEngineInfo Engine;
internal IGearboxInfo Gearbox;
......@@ -227,7 +227,8 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
commitPriority = 3;
});
Components.Add(-commitPriority, component);
_components.Add(Tuple.Create(commitPriority, component));
_components = _components.OrderBy(x => x.Item1).Reverse().ToList();
}
......@@ -236,8 +237,8 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
Log.Info("VehicleContainer committing simulation. time: {0}, dist: {1}, speed: {2}", time,
ExecutionMode == ExecutionMode.EngineOnly ? null : Distance, VehicleSpeed);
foreach (var component in Components) {
component.Value.CommitSimulationStep(ModData);
foreach (var component in _components) {
component.Item2.CommitSimulationStep(ModData);
}
if (ModData != null) {
......@@ -261,7 +262,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
public IReadOnlyCollection<VectoSimulationComponent> SimulationComponents()
{
return new ReadOnlyCollection<VectoSimulationComponent>(Components.Select(x => x.Value).ToList());
return new ReadOnlyCollection<VectoSimulationComponent>(_components.Select(x => x.Item2).ToList());
}
public Meter Distance
......
......@@ -60,7 +60,7 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation
var run = factory.SimulationRuns().First();
var vehicleContainer = (VehicleContainer)run.GetContainer();
Assert.AreEqual(11, vehicleContainer.Components.Count);
Assert.AreEqual(11, vehicleContainer.SimulationComponents().Count);
Assert.IsInstanceOfType(vehicleContainer.Gearbox, typeof(Gearbox), "gearbox not installed");
Assert.IsInstanceOfType(vehicleContainer.Engine, typeof(CombustionEngine), "engine not installed");
......@@ -112,7 +112,7 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation
var run = factory.SimulationRuns().First();
var vehicleContainer = (VehicleContainer)run.GetContainer();
Assert.AreEqual(11, vehicleContainer.Components.Count);
Assert.AreEqual(11, vehicleContainer.SimulationComponents().Count);
Assert.IsInstanceOfType(vehicleContainer.Gearbox, typeof(Gearbox), "gearbox not installed");
Assert.IsInstanceOfType(vehicleContainer.Engine, typeof(CombustionEngine), "engine not installed");
......
......@@ -65,7 +65,7 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation
var powerTrain = builder.Build(runData);
Assert.IsInstanceOfType(powerTrain, typeof(IVehicleContainer));
Assert.AreEqual(11, powerTrain.Components.Count);
Assert.AreEqual(11, powerTrain.SimulationComponents().Count);
Assert.IsInstanceOfType(powerTrain.Engine, typeof(CombustionEngine));
Assert.IsInstanceOfType(powerTrain.Gearbox, typeof(Gearbox));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment