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 802bbdb9 authored by Michael KRISPER's avatar Michael KRISPER
Browse files

changed tests to new calling format of delaunay interpolate (nullable double as return value)

parent 3bdb9375
No related branches found
No related tags found
No related merge requests found
......@@ -194,8 +194,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox
{
var torqueLoss = _invertedLossMap.Interpolate(inAngularVelocity.ConvertTo().Rounds.Per.Minute.Value(),
inTorque.Value());
if (torqueLoss.HasValue)
return (inTorque - torqueLoss.Value.SI<NewtonMeter>()) / _ratio;
if (!torqueLoss.HasValue && allowExtrapolation) {
if (allowExtrapolation) {
torqueLoss = _invertedLossMap.Extrapolate(inAngularVelocity.ConvertTo().Rounds.Per.Minute.Value(), inTorque.Value());
return (inTorque - torqueLoss.Value.SI<NewtonMeter>()) / _ratio;
}
......
......@@ -29,11 +29,11 @@
* Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology
*/
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TUGraz.VectoCommon.Exceptions;
using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.Models.SimulationComponent.Data.Engine;
......@@ -60,19 +60,13 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData
AssertMapValuesEqual(lines, map);
}
private static void AssertMapValuesEqual(string[] lines, FuelConsumptionMap map)
private static void AssertMapValuesEqual(IReadOnlyList<string> lines, FuelConsumptionMap map)
{
for (var i = 1; i < lines.Count(); i++) {
for (var i = 1; i < lines.Count; i++) {
var entry = lines[i].Split(',').Select(x => double.Parse(x, CultureInfo.InvariantCulture)).ToArray();
try {
Assert.AreEqual(entry[2].SI().Gramm.Per.Hour.ConvertTo().Kilo.Gramm.Per.Second.Value(),
map.GetFuelConsumption(entry[1].SI<NewtonMeter>(), entry[0].RPMtoRad()).Value(),
Tolerance,
string.Format("Line: {0}, n_eng_avg={1}, T={2}", (i + 2), entry[0].SI().Rounds.Per.Minute, entry[1]));
} catch (VectoException ex) {
throw new VectoException(string.Format("Row {0}: Error in ConsumptionMap n_eng_avg={1}, T={2}: {3}",
i + 2, entry[0], entry[1], ex.Message));
}
Assert.AreEqual(entry[2].SI().Gramm.Per.Hour.ConvertTo().Kilo.Gramm.Per.Second.Value(),
map.GetFuelConsumption(entry[1].SI<NewtonMeter>(), entry[0].RPMtoRad(), true).Value(), Tolerance);
}
}
}
......
......@@ -82,10 +82,10 @@ namespace TUGraz.VectoCore.Tests.Utils
AssertHelper.AreRelativeEqual(1.5, map.Interpolate(0, 0.75).Value);
// extrapolation (should fail)
AssertHelper.Exception<VectoException>(() => map.Interpolate(1, 1), "TEST: Interpolation failed. x: 1, y: 1");
AssertHelper.Exception<VectoException>(() => map.Interpolate(-1, -1), "TEST: Interpolation failed. x: -1, y: -1");
AssertHelper.Exception<VectoException>(() => map.Interpolate(1, -1), "TEST: Interpolation failed. x: 1, y: -1");
AssertHelper.Exception<VectoException>(() => map.Interpolate(-1, 1), "TEST: Interpolation failed. x: -1, y: 1");
Assert.IsNull(map.Interpolate(1, 1));
Assert.IsNull(map.Interpolate(-1, -1));
Assert.IsNull(map.Interpolate(1, -1));
Assert.IsNull(map.Interpolate(-1, 1));
}
public void Test_DelaunayMapPlane()
......
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