using Deltares.Dam.Data; using NUnit.Framework; namespace Deltares.Dam.Tests { [TestFixture] public class DesignPointCalculationTest { [Test] public void TestCalculationMaxLevelAboveTopLevel() { Assert.AreEqual(4.18882, PerformBasicCorrectCalculation(true, 4.90), CTolerance); } [Test] public void TestCalculationMaxLevelBelowLowestLevel() { Assert.AreEqual(6.4903, PerformBasicCorrectCalculation(true, 0.90), CTolerance); } [Test] [Ignore("reason for this failure is to be checked by Best!")] public void TestCalculationMaxLevelBelowTopLevelDoesNotConverge() { PerformBasicCorrectCalculation(true, 2.95); // reason for this to be checked by Best! Assert.IsFalse(FDDesignPointWater.ErrorMessage == ""); } [Test] public void TestCalculationMaxLevelMiddleTopLevel() { Assert.AreEqual(4.4422, PerformBasicCorrectCalculation(true, 2.70), CTolerance); } [Test] public void TestCalculationWithMaxLevelEqualToTopLevel() { Assert.AreEqual(4.18882, PerformBasicCorrectCalculation(true, 3.90), CTolerance); } [Test] public void TestCalculationWithSortedDataEqualsCalculationWithUnsortedData() { Assert.AreEqual(PerformBasicCorrectCalculation(false, 0), PerformCalculationWithUnsortedData(false, 0), CTolerance); } [Test] public void TestCalculationWithZeroData() { Assert.AreEqual(0, PerformCalculationWithZeroData(false, 0), CTolerance); } [Test] public void TestCalculationWithoutMaxLevel() { Assert.AreEqual(4.18882, PerformBasicCorrectCalculation(false, 0), CTolerance); } [Test] public void TestCalculationWithoutMaxLevelEqualsCalculationWithMaxLevelAboveToTopLevel() { Assert.AreEqual(PerformBasicCorrectCalculation(false, 0), PerformBasicCorrectCalculation(true, 4.90), CTolerance); } [Test] public void TestCalculationWithoutMaxLevelEqualsCalculationWithMaxLevelEqualToTopLevel() { Assert.AreEqual(PerformBasicCorrectCalculation(false, 0), PerformBasicCorrectCalculation(true, 3.90), CTolerance); } private DesignPointCalculation FDDesignPointWater; private double CTolerance = 0.0001; private void SetLevelsForCalculation(double ALevel1, double ALevel2, double ALevel3) { double[] LWaterlevels; LWaterlevels = new double[3]; LWaterlevels[0] = ALevel1; LWaterlevels[1] = ALevel2; LWaterlevels[2] = ALevel3; FDDesignPointWater.Waterlevels = LWaterlevels; } private void SetBetasForCalculation(double ABeta1, double ABeta2, double ABeta3) { double[] LBetas; LBetas = new double[3]; LBetas[0] = ABeta1; LBetas[1] = ABeta2; LBetas[2] = ABeta3; FDDesignPointWater.Betas = LBetas; } private double PerformBasicCorrectCalculation(bool AMaxLevelUsed, double AMaxLevel) { double cNoResult = -999.99; double LBeta; LBeta = cNoResult; FDDesignPointWater = new DesignPointCalculation(); SetLevelsForCalculation(1.0, 2.9, 3.9); SetBetasForCalculation(6.37653, 4.214663, 3.725901); FDDesignPointWater.MHW = 3.90; FDDesignPointWater.Decimate = 0.31; FDDesignPointWater.Exceed = DesignPointCalculation.ExceedingSet.twoThousend; FDDesignPointWater.IsMaxLevelUsed = AMaxLevelUsed; FDDesignPointWater.MaxLevel = AMaxLevel; if (FDDesignPointWater.CalculateTheWaterDesignpoint()) { LBeta = FDDesignPointWater.Beta; } return LBeta; } private double PerformCalculationWithUnsortedData(bool AMaxLevelUsed, double AMaxLevel) { double cNoResult = -999.99; double LBeta; LBeta = cNoResult; FDDesignPointWater = new DesignPointCalculation(); SetLevelsForCalculation(2.9, 1.0, 3.9); SetBetasForCalculation(4.214663, 6.37653, 3.725901); FDDesignPointWater.MHW = 3.90; FDDesignPointWater.Decimate = 0.31; FDDesignPointWater.Exceed = DesignPointCalculation.ExceedingSet.twoThousend; FDDesignPointWater.IsMaxLevelUsed = AMaxLevelUsed; FDDesignPointWater.MaxLevel = AMaxLevel; if (FDDesignPointWater.CalculateTheWaterDesignpoint()) { LBeta = FDDesignPointWater.Beta; } return LBeta; } private double PerformCalculationWithZeroData(bool AMaxLevelUsed, double AMaxLevel) { double cNoResult = -999.99; double LBeta; LBeta = cNoResult; FDDesignPointWater = new DesignPointCalculation(); SetLevelsForCalculation(0, 0, 0); SetBetasForCalculation(0, 0, 0); FDDesignPointWater.MHW = 3.90; FDDesignPointWater.Decimate = 0.31; FDDesignPointWater.Exceed = DesignPointCalculation.ExceedingSet.twoThousend; FDDesignPointWater.IsMaxLevelUsed = AMaxLevelUsed; FDDesignPointWater.MaxLevel = AMaxLevel; if (FDDesignPointWater.CalculateTheWaterDesignpoint()) { LBeta = FDDesignPointWater.Beta; } return LBeta; } } }