Skip to content

Commit

Permalink
Adds a service to get ship CII boundaries
Browse files Browse the repository at this point in the history
  • Loading branch information
liamlaverty committed Mar 29, 2024
1 parent 02465ee commit e42170e
Show file tree
Hide file tree
Showing 9 changed files with 372 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using EtiveMor.OpenImoCiiCalculator.Core.Models.Enums;
using EtiveMor.OpenImoCiiCalculator.Core.Models.ShipModels;
using EtiveMor.OpenImoCiiCalculator.Core.Services.Impl;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EtiveMor.OpenImoCiiCalculator.Core.Tests
{
[TestClass]
public class RatingBoundariesServiceTests
{

/// <summary>
/// This method tests that ShipType enum values are considered by the
/// GetBoundaries method. If a new value is added to the Enum, this method
/// will fail until the RatingsBoundariesService is updated to handle the new value.
/// </summary>
[TestMethod]
public void TestGetBoundariesProcessesAllEnumValues()
{
ShipType[] possibleShipTypeEnums = (ShipType[])Enum.GetValues(typeof(ShipType));

for (int i = 0; i < possibleShipTypeEnums.Length; i++)
{
if (possibleShipTypeEnums[i] == ShipType.UNKNOWN)
{
// intentionally ignore the UNKNOWN value
continue;
}
var ship = new Ship(possibleShipTypeEnums[i], 250000, 0);
var service = new RatingBoundariesService();
var boundaries = service.GetBoundaries(ship, 0.5);

Assert.IsNotNull(boundaries);
}
}


/// <summary>
/// Method checks that an exception is thrown when an unknown ShipType
/// is passed to the GetBoundaries method.
/// </summary>
[TestMethod]
public void TestGetBoundariesFailsOnUnknownShipType()
{
var ship = new Ship(ShipType.UNKNOWN, 250000, 0);
var service = new RatingBoundariesService();

Assert.ThrowsException<NotSupportedException>(() => service.GetBoundaries(ship, 0.5));
}


[DataRow(ShipType.BulkCarrier, CapacityUnit.DWT)]
[DataRow(ShipType.GasCarrier, CapacityUnit.DWT)]
[DataRow(ShipType.Tanker, CapacityUnit.DWT)]
[DataRow(ShipType.ContainerShip, CapacityUnit.DWT)]
[DataRow(ShipType.GeneralCargoShip, CapacityUnit.DWT)]
[DataRow(ShipType.RefrigeratedCargoCarrier, CapacityUnit.DWT)]
[DataRow(ShipType.CombinationCarrier, CapacityUnit.DWT)]
[DataRow(ShipType.LngCarrier, CapacityUnit.DWT)]
[DataRow(ShipType.RoRoCargoShipVehicleCarrier, CapacityUnit.GT)]
[DataRow(ShipType.RoRoPassengerShip, CapacityUnit.GT)]
[DataRow(ShipType.CruisePassengerShip, CapacityUnit.GT)]
[TestMethod]
public void TestGrossTonnageCapacityShipTypesAreHandledCorrectly(ShipType shipType, CapacityUnit expectedCapacityUnit)
{
var ship = new Ship(shipType, 250000, 0);
var service = new RatingBoundariesService();
var boundaries = service.GetBoundaries(ship, 0.5);

Assert.AreEqual(expectedCapacityUnit, boundaries.CapacityUnit);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void TestCalculateCapacity_BulkCarrier()
[DataRow(ShipType.LngCarrier, 0, 100000)]
[DataRow(ShipType.RoRoCargoShipVehicleCarrier, 250000, 0)]
[DataRow(ShipType.RoRoPassengerShip, 250000, 0)]
[DataRow(ShipType.RoRoCruisePassengerShip, 250000, 0)]
[DataRow(ShipType.CruisePassengerShip, 250000, 0)]
public void TestValidateTonnageParamsSet_ArgumentOutOfRangeException(ShipType shipType, double deadweightTonnage, double grossTonnage)
{
var ship = new Ship(
Expand Down Expand Up @@ -86,7 +86,7 @@ public void TestValidateTonnageParamsSet_ArgumentOutOfRangeException(ShipType sh
[DataRow(ShipType.RoRoPassengerShip_HighSpeedSOLAS, 0, 250000, 250000)]
[DataRow(ShipType.RoRoCargoShipVehicleCarrier, 0, 100000, 100000)]
[DataRow(ShipType.RoRoPassengerShip, 0, 100000, 100000)]
[DataRow(ShipType.RoRoCruisePassengerShip, 0, 100000, 100000)]
[DataRow(ShipType.CruisePassengerShip, 0, 100000, 100000)]
public void TestCalculateCapacity(ShipType shipType, double deadweightTonnage, double grossTonnage, double expectedCapacity)
{
var ship = new Ship(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public CalculationResult CalculateAttainedCiiRating(

private ImoCiiRating GetImoCiiRatingInYear(double attainedCiiInYear, double requiredCiiInYear, int year)
{
var gradeLowerBoundaries = GetBoundaries(ShipType.RoRoCruisePassengerShip, requiredCiiInYear);
var gradeLowerBoundaries = GetBoundaries(ShipType.CruisePassengerShip, requiredCiiInYear);

if (attainedCiiInYear < gradeLowerBoundaries[ImoCiiBoundary.Superior])
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ public enum ShipType
/// A type of ship designed to carry both wheeled cargo and passengers, with
/// built-in ramps for loading and unloading vehicles.
/// </summary>
/// <seealso cref="RoRoCruisePassengerShip"/>
/// <seealso cref="CruisePassengerShip"/>
RoRoPassengerShip = 110,

/// <summary>
/// A type of high-speed ship designed to conform to SOLAS Chapter X standards
/// </summary>
/// <seealso cref="RoRoCruisePassengerShip"/>
/// <seealso cref="CruisePassengerShip"/>
RoRoPassengerShip_HighSpeedSOLAS = 111,

/// <summary>
Expand All @@ -90,7 +90,7 @@ public enum ShipType
/// venues, and recreational facilities.
/// </summary>
/// <seealso cref="RoRoPassengerShip"/>
RoRoCruisePassengerShip = 120
CruisePassengerShip = 120
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ double grossTonnage
ShipType = shipType;
DeadweightTonnage = deadweightTonnage;
GrossTonnage = grossTonnage;

if (shipType == ShipType.UNKNOWN)
{
throw new System.InvalidOperationException("ShipType must be set");
}
}


Expand Down Expand Up @@ -60,14 +55,7 @@ double grossTonnage
}


public enum CapacityUnit
{
ERR,
DWT,
DWT_CAP_HIGH,
GT,
GT_CAP_LOW
}




Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using EtiveMor.OpenImoCiiCalculator.Core.Models.ShipModels;
using EtiveMor.OpenImoCiiCalculator.Core.Services.Impl;

namespace EtiveMor.OpenImoCiiCalculator.Core.Services
{
public interface IRatingBoundariesService
{
DdVectorDataTableRow GetBoundaries(Ship ship, double requiredCiiInYear);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private double GetValue(ValType valType, ShipType shipType, double capacity)
ShipType.RoRoCargoShip => GetRoRoCargoShipValue(valType, capacity),
ShipType.RoRoPassengerShip => GetRoRoPassengerShipValue(valType, capacity),
ShipType.RoRoPassengerShip_HighSpeedSOLAS => GetRoRoPassengerShip_HighSpeedSOLASValue(valType, capacity),
ShipType.RoRoCruisePassengerShip => GetRoRoCruisePassengerShipValue(valType, capacity),
ShipType.CruisePassengerShip => GetRoRoCruisePassengerShipValue(valType, capacity),
ShipType.UNKNOWN => throw new NotSupportedException($"Unsupported {nameof(shipType)} '{shipType}'"),
_ => throw new NotSupportedException($"Unsupported {nameof(shipType)} '{shipType}'")
};
Expand Down
Loading

0 comments on commit e42170e

Please sign in to comment.