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

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

small corrections aux test

parent 72b14da3
No related branches found
No related tags found
No related merge requests found
......@@ -92,12 +92,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
public void AddConstant(string auxId, Watt powerDemand)
{
_auxDict[auxId] = ignored => powerDemand;
_auxDict[auxId] = speed => powerDemand;
}
public void AddDirect(IDrivingCycleCockpit cycle)
{
_auxDict[DirectAuxiliaryId] = ignored => cycle.CycleData().LeftSample.AdditionalAuxPowerDemand;
_auxDict[DirectAuxiliaryId] = speed => cycle.CycleData().LeftSample.AdditionalAuxPowerDemand;
}
public void AddMapping(string auxId, IDrivingCycleCockpit cycle, MappingAuxiliaryData data)
......
using System;
using System.Data;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TUGraz.VectoCore.FileIO.Reader;
using TUGraz.VectoCore.FileIO.Reader.Impl;
using TUGraz.VectoCore.Models.Simulation.Data;
using TUGraz.VectoCore.Models.Simulation.Impl;
using TUGraz.VectoCore.Models.SimulationComponent.Data;
using TUGraz.VectoCore.Models.SimulationComponent.Impl;
using TUGraz.VectoCore.Tests.Utils;
using TUGraz.VectoCore.Utils;
......@@ -43,9 +41,6 @@ namespace TUGraz.VectoCore.Tests.Integration.EngineOnlyCycle
gearbox.InPort().Connect(aux.OutPort());
var port = aux.OutPort();
// IVectoJob job = SimulationFactory.CreateTimeBasedEngineOnlyRun(TestContext.DataRow["EngineFile"].ToString(),
// TestContext.DataRow["CycleFile"].ToString(), "test2.csv");
var absTime = 0.SI<Second>();
var dt = 1.SI<Second>();
......@@ -54,11 +49,10 @@ namespace TUGraz.VectoCore.Tests.Integration.EngineOnlyCycle
var i = 0;
var results = new[] {
ModalResultField.n, ModalResultField.PaEng, ModalResultField.Tq_drag, ModalResultField.Pe_drag,
ModalResultField.Pe_eng, ModalResultField.Tq_eng, ModalResultField.Tq_full, ModalResultField.Pe_full
ModalResultField.Pe_eng, ModalResultField.Tq_eng, ModalResultField.Tq_full, ModalResultField.Pe_full,
ModalResultField.FCMap
};
//, ModalResultField.FC };
//var siFactor = new[] { 1, 1000, 1, 1000, 1000, 1, 1, 1000, 1 };
//var tolerances = new[] { 0.0001, 0.1, 0.0001, 0.1, 0.1, 0.001, 0.001, 0.1, 0.01 };
foreach (var cycleEntry in data.Entries) {
port.Request(absTime, dt, cycleEntry.EngineTorque, cycleEntry.EngineSpeed);
foreach (var sc in vehicle.SimulationComponents()) {
......@@ -68,18 +62,10 @@ namespace TUGraz.VectoCore.Tests.Integration.EngineOnlyCycle
// TODO: handle initial state of engine
var row = expectedResults.Rows[i++];
if (i > 2) {
for (var j = 0; j < results.Length; j++) {
var field = results[j];
Assert.AreEqual(row.Field<SI>(field.GetName()).Value(), dataWriter.Field<SI>(field).Value(), 0.0001,
foreach (var field in results) {
AssertHelper.AreRelativeEqual(row.Field<SI>(field.GetName()).Value(), dataWriter.Field<SI>(field).Value(),
string.Format("t: {0} field: {1}", i, field));
}
if (double.IsNaN(row.Field<SI>(ModalResultField.FCMap.GetName()).Value())) {
Assert.IsTrue(double.IsNaN(dataWriter.Field<SI>(ModalResultField.FCMap).Value()));
} else {
Assert.AreEqual(row.Field<SI>(ModalResultField.FCMap.GetName()).Value(),
dataWriter.Field<SI>(ModalResultField.FCMap).Value(),
0.01, "t: {0} field: {1}", i, ModalResultField.FCMap);
}
}
dataWriter.CommitSimulationStep(absTime, dt);
......
using System;
using System.Diagnostics;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TUGraz.VectoCore.Utils;
......@@ -29,18 +30,32 @@ namespace TUGraz.VectoCore.Tests.Utils
AreRelativeEqual(expected.Value(), actual.Value());
}
public static void AreRelativeEqual(double expected, double actual,
[DebuggerHidden]
public static void AreRelativeEqual(double expected, double actual, string message = null,
double toleranceFactor = DoubleExtensionMethods.Tolerance)
{
if (actual.IsEqual(0.0)) {
Assert.AreEqual(expected, 0.0, DoubleExtensionMethods.Tolerance,
string.Format("AssertHelper.AreRelativeEqual failed. Expected: {0}, Actual: {1}, Tolerance: {2}", expected, actual,
toleranceFactor));
if (!string.IsNullOrWhiteSpace(message)) {
message = "\n" + message;
} else {
message = "";
}
if (double.IsNaN(expected)) {
Assert.IsTrue(double.IsNaN(actual),
string.Format("Actual value is not NaN. Expected: {0}, Actual: {1}{2}", expected, actual, message));
return;
}
if (expected.IsEqual(0.0)) {
Assert.AreEqual(actual, 0.0, DoubleExtensionMethods.Tolerance,
string.Format("Actual value is different. Difference: {3} Expected: {0}, Actual: {1}, Tolerance: {2}{4}",
expected, actual, toleranceFactor, expected - actual, message));
return;
}
Assert.IsTrue(Math.Abs(expected / actual - 1) < toleranceFactor,
string.Format("AssertHelper.AreRelativeEqual failed. Expected: {0}, Actual: {1}, Tolerance: {2}", expected, actual,
toleranceFactor));
Assert.IsTrue(Math.Abs(actual / expected - 1) < toleranceFactor,
string.Format("Actual value is different. Difference: {3} Expected: {0}, Actual: {1}, Tolerance: {2}{4}",
expected, actual, toleranceFactor, expected - actual, message));
}
}
}
\ No newline at end of file
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