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

Skip to content
Snippets Groups Projects
Commit 33fad05c authored by Michael KRISPER's avatar Michael KRISPER
Browse files

added tests for truck and coach for all speed and slopes (simple cycle)

parent c35052d0
No related branches found
No related tags found
No related merge requests found
......@@ -5,7 +5,6 @@ using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.Models.Simulation.Data;
using TUGraz.VectoCore.Tests.Integration;
using TUGraz.VectoCore.Tests.Utils;
using Assert = Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
namespace TUGraz.VectoCore.ModelbasedTests.DriverStrategy
{
......@@ -16,11 +15,11 @@ namespace TUGraz.VectoCore.ModelbasedTests.DriverStrategy
public void DisableLogging()
{
//LogManager.DisableLogging();
//#if TRACE
#if TRACE
GraphWriter.Enable();
//#else
// GraphWriter.Disable();
//#endif
#else
GraphWriter.Disable();
#endif
GraphWriter.Xfields = new[] { ModalResultField.dist };
......
/*
* This file is part of VECTO.
*
* Copyright © 2012-2016 European Union
*
* Developed by Graz University of Technology,
* Institute of Internal Combustion Engines and Thermodynamics,
* Institute of Technical Informatics
*
* VECTO is licensed under the EUPL, Version 1.1 or - as soon they will be approved
* by the European Commission - subsequent versions of the EUPL (the "Licence");
* You may not use VECTO except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* https://joinup.ec.europa.eu/community/eupl/og_page/eupl
*
* Unless required by applicable law or agreed to in writing, VECTO
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*
* Authors:
* Stefan Hausberger, hausberger@ivt.tugraz.at, IVT, Graz University of Technology
* Christian Kreiner, christian.kreiner@tugraz.at, ITI, Graz University of Technology
* Michael Krisper, michael.krisper@tugraz.at, ITI, Graz University of Technology
* Raphael Luz, luz@ivt.tugraz.at, IVT, Graz University of Technology
* Markus Quaritsch, markus.quaritsch@tugraz.at, IVT, Graz University of Technology
* Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology
*/
using System;
using System.Globalization;
using NUnit.Framework;
using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.Models.Simulation.Data;
using TUGraz.VectoCore.Tests.Integration;
using TUGraz.VectoCore.Tests.Utils;
namespace TUGraz.VectoCore.ModelbasedTests.DriverStrategy
{
[TestFixture]
public class SimpleCycles
{
[TestFixtureSetUp]
public void Init()
{
//LogManager.DisableLogging();
#if TRACE
GraphWriter.Enable();
#else
GraphWriter.Disable();
#endif
GraphWriter.Xfields = new[] { ModalResultField.time, ModalResultField.dist };
GraphWriter.Yfields = new[] {
ModalResultField.v_act, ModalResultField.acc, ModalResultField.n_eng_avg, ModalResultField.Gear,
ModalResultField.P_eng_out, ModalResultField.T_eng_fcmap, ModalResultField.FCMap
};
GraphWriter.Series1Label = "Vecto 3";
}
private static string GetSlopeString(double slope)
{
var slopeStr = slope > 0
? Math.Abs(slope).ToString("uphill_#")
: slope < 0
? Math.Abs(slope).ToString("downhill_#")
: "level";
return slopeStr;
}
[
TestCase(0, 80), TestCase(80, 0), TestCase(80, 80),
TestCase(0, 60), TestCase(60, 0), TestCase(60, 60),
TestCase(0, 40), TestCase(40, 0), TestCase(40, 40),
TestCase(0, 20), TestCase(20, 0), TestCase(20, 20),
]
public void Truck_AllSlopes(double v1, double v2)
{
var slopes = new[] { 25, 20, 15, 10, 5, 3, 1, 0, -1, -3, -5, -10, -15, -20, -25 };
foreach (var slope in slopes) {
try {
var cycle = string.Format(CultureInfo.InvariantCulture, "0, {0}, {1}, {2}\n1000, {3}, {4}, {5}", v1, slope,
v1.IsEqual(0) ? 2 : 0, v2, slope, v2.IsEqual(0) ? 2 : 0);
var modFileName = string.Format(CultureInfo.InvariantCulture, "Truck_{0}_{1}_{2}.vmod", v1, v2,
GetSlopeString(slope));
var cycleData = SimpleDrivingCycles.CreateCycleData(cycle);
var run = Truck40tPowerTrain.CreateEngineeringRun(cycleData, modFileName);
run.Run();
Assert.IsTrue(run.FinishedWithoutErrors, "Truck Run (v1: {0}, v2: {1}, slope: {2}) failed.", v1, v2, slope);
GraphWriter.Write(modFileName);
} catch (Exception ex) {
Assert.Fail("Truck Run (v1: {0}, v2: {1}, slope: {2}) failed: {3}", v1, v2, slope, ex);
}
}
}
[
TestCase(0, 80), TestCase(80, 0), TestCase(80, 80),
TestCase(0, 60), TestCase(60, 0), TestCase(60, 60),
TestCase(0, 40), TestCase(40, 0), TestCase(40, 40),
TestCase(0, 20), TestCase(20, 0), TestCase(20, 20),
]
public void Coach_AllSlopes(double v1, double v2)
{
var slopes = new[] { 25, 20, 15, 12, 10, 7, 5, 3, 1, 0, -1, -3, -5, -7, -10, -12, -15, -20, -25 };
foreach (var slope in slopes) {
try {
var cycle = string.Format(CultureInfo.InvariantCulture, "0, {0}, {1}, {2}\n1000, {3}, {4}, {5}", v1, slope,
v1.IsEqual(0) ? 2 : 0, v2, slope, v2.IsEqual(0) ? 2 : 0);
var modFileName = string.Format(CultureInfo.InvariantCulture, "Coach_{0}_{1}_{2}.vmod", v1, v2,
GetSlopeString(slope));
var cycleData = SimpleDrivingCycles.CreateCycleData(cycle);
var run = CoachPowerTrain.CreateEngineeringRun(cycleData, modFileName);
run.Run();
Assert.IsTrue(run.FinishedWithoutErrors, "Truck Run (v1: {0}, v2: {1}, slope: {2}) failed.", v1, v2, slope);
GraphWriter.Write(modFileName);
} catch (Exception ex) {
Assert.Fail("Truck Run (v1: {0}, v2: {1}, slope: {2}) failed: {3}", v1, v2, slope, ex);
}
}
}
}
}
\ No newline at end of file
......@@ -57,6 +57,7 @@
</Choose>
<ItemGroup>
<Compile Include="DriverStrategy\CoastingTests.cs" />
<Compile Include="DriverStrategy\SimpleCycles.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
......
......@@ -30,7 +30,6 @@
*/
using System;
using System.Collections.Generic;
using System.Linq;
using TUGraz.VectoCommon.Exceptions;
using TUGraz.VectoCommon.Models;
......@@ -38,9 +37,9 @@ using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.Configuration;
using TUGraz.VectoCore.Models.Connector.Ports;
using TUGraz.VectoCore.Models.Connector.Ports.Impl;
using TUGraz.VectoCore.Models.Simulation;
using TUGraz.VectoCore.Models.Simulation.Data;
using TUGraz.VectoCore.Models.Simulation.DataBus;
using TUGraz.VectoCore.Models.Simulation.Impl;
using TUGraz.VectoCore.OutputData;
using TUGraz.VectoCore.Utils;
using DriverData = TUGraz.VectoCore.Models.SimulationComponent.Data.DriverData;
......@@ -56,18 +55,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
public DriverData DriverData { get; protected set; }
protected IDriverStrategy DriverStrategy;
private Dictionary<string, object> _coastData = new Dictionary<string, object>(20);
public string CurrentAction = "";
//public MeterPerSquareSecond LookaheadDeceleration { get; protected set; }
public Driver(VehicleContainer container, DriverData driverData, IDriverStrategy strategy) : base(container)
public Driver(IVehicleContainer container, DriverData driverData, IDriverStrategy strategy) : base(container)
{
DriverData = driverData;
DriverStrategy = strategy;
strategy.Driver = this;
//LookaheadDeceleration = DeclarationData.Driver.LookAhead.Deceleration;
}
public IDriverDemandInPort InPort()
......@@ -110,8 +104,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
var retVal = DriverStrategy.Request(absTime, ds, targetVelocity, gradient);
_coastData = ((DefaultDriverStrategy)DriverStrategy).LookAheadCoasting(ds);
CurrentState.Response = retVal;
retVal.SimulationInterval = CurrentState.dt;
retVal.Acceleration = CurrentState.Acceleration;
......
......@@ -85,7 +85,6 @@
<Compile Include="Integration\BusAuxiliaries\AAuxTests.cs" />
<Compile Include="Integration\CoachAdvancedAuxPowertrain.cs" />
<Compile Include="Integration\CoachPowerTrain.cs" />
<Compile Include="Integration\DriverStrategy\CoastingTests.cs" />
<Compile Include="Integration\DriverStrategy\SimpleCycles.cs" />
<Compile Include="Integration\FullCycleDeclarationTest.cs">
<SubType>Code</SubType>
......
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