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

Skip to content
Snippets Groups Projects
Commit e1858115 authored by Harald Martini's avatar Harald Martini
Browse files

throw exception ic socRange exceeds 1

parent 8057199d
No related branches found
No related tags found
No related merge requests found
......@@ -50,7 +50,12 @@ namespace TUGraz.VectoCore.Models.Declaration
public double LookupEquivalenceFactor(MissionType mission, VehicleClass hdvClass, LoadingType loading,
double socRange)
{
var a = _socRanges.MinBy((i => Math.Abs(socRange * 100 - i))); //closest
if (socRange > 1 || socRange < 0) {
throw new ArgumentException($"{nameof(socRange)} must be between 0 and 1 ");
}
socRange *= 100; //Percent from here on
var a = _socRanges.MinBy((i => Math.Abs(socRange - i))); //closest
if (socRange <= _socRanges.Min() || socRange >= _socRanges.Max()) {
return _initEquivalenceFactors[a].LookupEquivalenceFactor(mission, hdvClass, loading);
......
......@@ -52,6 +52,7 @@ namespace TUGraz.VectoCore.Tests.Models.Declaration
40.0)]
double socRange)
{
socRange /= 100;
Assert.DoesNotThrow(() => DeclarationData.HEVStrategyParameters.LookupEquivalenceFactor(missionType, vehClass,
loadingType, socRange));
}
......@@ -84,8 +85,9 @@ namespace TUGraz.VectoCore.Tests.Models.Declaration
//[TestCase(MissionType.LongHaul, VehicleClass.Class2, LoadingType.ReferenceLoad, 0.10, 10)]
public void TestHevStrategyLookup(MissionType missionType, VehicleClass vehicleClass, LoadingType loadingType, double expected, int socRange)
public void TestHevStrategyLookup(MissionType missionType, VehicleClass vehicleClass, LoadingType loadingType, double expected, double socRange)
{
socRange /= 100;
LookupEquivAndAssert(missionType, vehicleClass, loadingType, expected,socRange);
}
......@@ -96,7 +98,7 @@ namespace TUGraz.VectoCore.Tests.Models.Declaration
LookupSlopeAndAssert(missionType, vehicleClass, loadingType, expected);
}
private void LookupEquivAndAssert(MissionType mission, VehicleClass hdvClass, LoadingType loading, double expected, int socRange)
private void LookupEquivAndAssert(MissionType mission, VehicleClass hdvClass, LoadingType loading, double expected, double socRange)
{
var feq = DeclarationData.HEVStrategyParameters.LookupEquivalenceFactor(mission, hdvClass,
loading, socRange);
......
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