public void Read_ValidEntity_ReturnGrassCoverErosionInwardsOutput() { // Setup var entity = new GrassCoverErosionInwardsOutputEntity { WaveHeight = 1.1, IsOvertoppingDominant = Convert.ToByte(false), Reliability = 0.2 }; // Call GrassCoverErosionInwardsOutput output = entity.Read(); // Assert OvertoppingOutput overtoppingOutput = output.OvertoppingOutput; Assert.AreEqual(entity.WaveHeight, overtoppingOutput.WaveHeight.Value); Assert.IsFalse(overtoppingOutput.IsOvertoppingDominant); Assert.IsNull(output.DikeHeightOutput); Assert.IsNull(output.OvertoppingRateOutput); Assert.AreEqual(entity.Reliability, overtoppingOutput.Reliability); }
public void PropertyAttributes_WithoutDikeHeightAndOvertoppingRateCalculated_ReturnExpectedValues(double waveHeight) { // Setup var resultOutput = new OvertoppingOutput(waveHeight, true, 0, null); var output = new GrassCoverErosionInwardsOutput(resultOutput, null, null); // Call var properties = new GrassCoverErosionInwardsOutputProperties(output); // Assert int propertiesCount = double.IsNaN(waveHeight) ? 3 : 4; PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); Assert.AreEqual(propertiesCount, dynamicProperties.Count); AssertResultOutputProperties(dynamicProperties, !double.IsNaN(waveHeight)); }
public void Read_ValidEntityWithNullValues_ReturnGrassCoverErosionInwardsOutput() { // Setup var entity = new GrassCoverErosionInwardsOutputEntity { WaveHeight = null, IsOvertoppingDominant = Convert.ToByte(true), Reliability = null, GeneralResultFaultTreeIllustrationPointEntity = null }; // Call GrassCoverErosionInwardsOutput output = entity.Read(); // Assert OvertoppingOutput overtoppingOutput = output.OvertoppingOutput; Assert.IsNaN(overtoppingOutput.WaveHeight); Assert.IsTrue(overtoppingOutput.IsOvertoppingDominant); Assert.IsNull(output.DikeHeightOutput); Assert.IsNull(output.OvertoppingRateOutput); Assert.IsNaN(overtoppingOutput.Reliability); Assert.IsNull(overtoppingOutput.GeneralResult); }
public void Create_CalculationWithOutput_ReturnEntity() { // Setup var random = new Random(456); var overtoppingOutput = new OvertoppingOutput(random.NextDouble(), false, random.NextDouble(), null); var output = new GrassCoverErosionInwardsOutput(overtoppingOutput, null, null); var calculation = new GrassCoverErosionInwardsCalculationScenario { Output = output }; var registry = new PersistenceRegistry(); // Call GrassCoverErosionInwardsCalculationEntity entity = calculation.Create(registry, 0); // Assert GrassCoverErosionInwardsOutputEntity outputEntity = entity.GrassCoverErosionInwardsOutputEntities.Single(); Assert.AreEqual(overtoppingOutput.WaveHeight, outputEntity.WaveHeight); Assert.AreEqual(overtoppingOutput.Reliability, outputEntity.Reliability); Assert.IsNull(outputEntity.GeneralResultFaultTreeIllustrationPointEntity); }
public void PropertyAttributes_HasGeneralResult_ReturnExpectedValues(double waveHeight) { // Setup var overtoppingOutput = new OvertoppingOutput(waveHeight, true, 0, new TestGeneralResultFaultTreeIllustrationPoint()); // Call var properties = new OvertoppingOutputProperties(overtoppingOutput); // Assert int propertiesCount = overtoppingOutput.HasWaveHeight ? 8 : 7; PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); Assert.AreEqual(propertiesCount, dynamicProperties.Count); PropertyDescriptor probabilityProperty = dynamicProperties[probabilityPropertyIndex]; PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(probabilityProperty, resultCategoryName, "Faalkans [1/jaar]", "De kans dat het faalmechanisme optreedt voor deze berekening.", true); PropertyDescriptor reliabilityProperty = dynamicProperties[reliabilityPropertyIndex]; PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(reliabilityProperty, resultCategoryName, "Betrouwbaarheidsindex faalkans [-]", "De betrouwbaarheidsindex van de faalkans voor deze berekening.", true); if (overtoppingOutput.HasWaveHeight) { PropertyDescriptor waveHeightProperty = dynamicProperties[waveHeightIndex]; PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(waveHeightProperty, resultCategoryName, "Indicatieve golfhoogte (Hs) [m]", "De golfhoogte van de overslag deelberekening.", true); } int waveHeightNotPresentOffset = overtoppingOutput.HasWaveHeight ? 0 : 1; PropertyDescriptor isDominantProperty = dynamicProperties[isDominantIndex - waveHeightNotPresentOffset]; PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(isDominantProperty, resultCategoryName, "Overslag dominant [-]", "Is het resultaat van de overslag deelberekening dominant over de overloop deelberekening.", true); PropertyDescriptor windDirectionProperty = dynamicProperties[windDirectionPropertyIndex - waveHeightNotPresentOffset]; PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(windDirectionProperty, illustrationPointsCategoryName, "Maatgevende windrichting", "De windrichting waarvoor de berekende betrouwbaarheidsindex het laagst is.", true); PropertyDescriptor alphaValuesProperty = dynamicProperties[alphaValuesPropertyIndex - waveHeightNotPresentOffset]; PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(alphaValuesProperty, illustrationPointsCategoryName, "Invloedscoëfficiënten [-]", "Berekende invloedscoëfficiënten voor alle beschouwde stochasten.", true); PropertyDescriptor durationsProperty = dynamicProperties[durationsPropertyIndex - waveHeightNotPresentOffset]; PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(durationsProperty, illustrationPointsCategoryName, "Tijdsduren [uur]", "Tijdsduren waarop de stochasten betrekking hebben.", true); PropertyDescriptor illustrationPointProperty = dynamicProperties[illustrationPointsPropertyIndex - waveHeightNotPresentOffset]; PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(illustrationPointProperty, illustrationPointsCategoryName, "Illustratiepunten", "De lijst van illustratiepunten voor de berekening.", true); }
/// <summary> /// Performs a grass cover erosion inwards calculation based on the supplied <see cref="GrassCoverErosionInwardsCalculation"/> /// and sets <see cref="GrassCoverErosionInwardsCalculation.Output"/> if the calculation was successful. Error and status /// information is logged during the execution of the operation. /// </summary> /// <param name="calculation">The <see cref="GrassCoverErosionInwardsCalculation"/> that holds all the information required to perform the calculation.</param> /// <param name="assessmentSection">The <see cref="IAssessmentSection"/> that holds information about the target probability used in the calculation.</param> /// <param name="generalInput">Calculation input parameters that apply to all <see cref="GrassCoverErosionInwardsCalculation"/> instances.</param> /// <exception cref="ArgumentNullException">Thrown when one of the following parameters is <c>null</c>: /// <list type="bullet"> /// <item><paramref name="calculation"/></item> /// <item><paramref name="assessmentSection"/></item> /// <item><paramref name="generalInput"/></item> /// </list></exception> /// <exception cref="ArgumentException">Thrown when the hydraulic boundary database file path contains invalid characters.</exception> /// <exception cref="CriticalFileReadException">Thrown when: /// <list type="bullet"> /// <item>No settings database file could be found at the location of the hydraulic boundary database file path /// with the same name.</item> /// <item>Unable to open settings database file.</item> /// <item>Unable to read required data from database file.</item> /// </list> /// </exception> /// <exception cref="SecurityException">Thrown when the temporary working directory can't be accessed due to missing permissions.</exception> /// <exception cref="IOException">Thrown when the specified path is not valid, the network name is not known /// or an I/O error occurred while opening the file.</exception> /// <exception cref="UnauthorizedAccessException">Thrown when the directory can't be created due to missing /// the required permissions.</exception> /// <exception cref="NotSupportedException">Thrown when <see cref="HydraRingCalculationInput.FailureMechanismType"/> /// is not the same with already added input.</exception> /// <exception cref="Win32Exception">Thrown when there was an error in opening the associated file /// or the wait setting could not be accessed.</exception> /// <exception cref="HydraRingFileParserException">Thrown when an error occurs during parsing of the Hydra-Ring output.</exception> /// <exception cref="HydraRingCalculationException">Thrown when an error occurs during the calculation.</exception> internal void Calculate(GrassCoverErosionInwardsCalculation calculation, IAssessmentSection assessmentSection, GeneralGrassCoverErosionInwardsInput generalInput) { if (calculation == null) { throw new ArgumentNullException(nameof(calculation)); } if (assessmentSection == null) { throw new ArgumentNullException(nameof(assessmentSection)); } if (generalInput == null) { throw new ArgumentNullException(nameof(generalInput)); } HydraulicBoundaryCalculationSettings calculationSettings = HydraulicBoundaryCalculationSettingsFactory.CreateSettings(assessmentSection.HydraulicBoundaryDatabase); int numberOfCalculators = CreateCalculators(calculation, calculationSettings); string hydraulicBoundaryDatabaseFilePath = calculationSettings.HydraulicBoundaryDatabaseFilePath; bool usePreprocessor = !string.IsNullOrEmpty(calculationSettings.PreprocessorDirectory); CalculationServiceHelper.LogCalculationBegin(); try { OvertoppingOutput overtoppingOutput = CalculateOvertopping(calculation, generalInput, hydraulicBoundaryDatabaseFilePath, usePreprocessor, numberOfCalculators); if (canceled) { return; } DikeHeightOutput dikeHeightOutput = CalculateDikeHeight(calculation, generalInput, hydraulicBoundaryDatabaseFilePath, usePreprocessor, numberOfCalculators); if (canceled) { return; } OvertoppingRateOutput overtoppingRateOutput = CalculateOvertoppingRate(calculation, generalInput, hydraulicBoundaryDatabaseFilePath, usePreprocessor, numberOfCalculators); if (canceled) { return; } calculation.Output = new GrassCoverErosionInwardsOutput( overtoppingOutput, dikeHeightOutput, overtoppingRateOutput); } finally { CalculationServiceHelper.LogCalculationEnd(); overtoppingCalculator = null; dikeHeightCalculator = null; overtoppingRateCalculator = null; } }
private static IEnumerable <TestCaseData> GetCalculations() { var overtoppingOutputWithoutGeneralResult = new TestOvertoppingOutput(1.0); var overtoppingOutputWithGeneralResult = new OvertoppingOutput(1.0, true, 1.0, new TestGeneralResultFaultTreeIllustrationPoint()); var dikeHeightOutputWithoutGeneralResult = new TestDikeHeightOutput(1.0); var dikeHeightOutputWithGeneralResult = new TestDikeHeightOutput(new TestGeneralResultFaultTreeIllustrationPoint()); var overtoppingRateOutputWithoutGeneralResult = new TestOvertoppingRateOutput(1.0); var overtoppingRateOutputWithGeneralResult = new TestOvertoppingRateOutput(new TestGeneralResultFaultTreeIllustrationPoint()); yield return(new TestCaseData(new GrassCoverErosionInwardsCalculation { InputParameters = { ShouldDikeHeightBeCalculated = true, ShouldOvertoppingRateBeCalculated = true, ShouldOvertoppingOutputIllustrationPointsBeCalculated = true, ShouldOvertoppingRateIllustrationPointsBeCalculated = true, ShouldDikeHeightIllustrationPointsBeCalculated = true }, Output = new GrassCoverErosionInwardsOutput(overtoppingOutputWithGeneralResult, dikeHeightOutputWithGeneralResult, overtoppingRateOutputWithGeneralResult) }, false) .SetName("OutputSufficientScenario1")); yield return(new TestCaseData(new GrassCoverErosionInwardsCalculation { InputParameters = { ShouldDikeHeightBeCalculated = true, ShouldOvertoppingRateBeCalculated = true }, Output = new GrassCoverErosionInwardsOutput(overtoppingOutputWithoutGeneralResult, dikeHeightOutputWithoutGeneralResult, overtoppingRateOutputWithoutGeneralResult) }, false) .SetName("OutputSufficientScenario2")); yield return(new TestCaseData(new GrassCoverErosionInwardsCalculation { Output = new GrassCoverErosionInwardsOutput(overtoppingOutputWithoutGeneralResult, null, null) }, false) .SetName("OutputSufficientScenario3")); yield return(new TestCaseData(new GrassCoverErosionInwardsCalculation(), true) .SetName("NoOutputScenario1")); yield return(new TestCaseData(new GrassCoverErosionInwardsCalculation { InputParameters = { ShouldDikeHeightBeCalculated = true, ShouldOvertoppingRateBeCalculated = true } }, true) .SetName("NoOutputScenario2")); yield return(new TestCaseData(new GrassCoverErosionInwardsCalculation { InputParameters = { ShouldDikeHeightBeCalculated = true, ShouldOvertoppingRateBeCalculated = true, ShouldOvertoppingOutputIllustrationPointsBeCalculated = true, ShouldOvertoppingRateIllustrationPointsBeCalculated = true, ShouldDikeHeightIllustrationPointsBeCalculated = true } }, true) .SetName("NoOutputScenario3")); yield return(new TestCaseData(new GrassCoverErosionInwardsCalculation { Output = new GrassCoverErosionInwardsOutput(overtoppingOutputWithGeneralResult, null, null) }, true) .SetName("OvertoppingOutputWithRedundantGeneralResult")); yield return(new TestCaseData(new GrassCoverErosionInwardsCalculation { InputParameters = { ShouldOvertoppingOutputIllustrationPointsBeCalculated = true }, Output = new GrassCoverErosionInwardsOutput(overtoppingOutputWithoutGeneralResult, null, null) }, true) .SetName("OvertoppingOutputWithMissingGeneralResult")); yield return(new TestCaseData(new GrassCoverErosionInwardsCalculation { InputParameters = { ShouldDikeHeightBeCalculated = true }, Output = new GrassCoverErosionInwardsOutput(overtoppingOutputWithoutGeneralResult, dikeHeightOutputWithGeneralResult, null) }, true) .SetName("DikeHeightOutputWithRedundantGeneralResult")); yield return(new TestCaseData(new GrassCoverErosionInwardsCalculation { InputParameters = { ShouldDikeHeightBeCalculated = true, ShouldDikeHeightIllustrationPointsBeCalculated = true }, Output = new GrassCoverErosionInwardsOutput(overtoppingOutputWithoutGeneralResult, dikeHeightOutputWithoutGeneralResult, null) }, true) .SetName("DikeHeightOutputWithMissingGeneralResult")); yield return(new TestCaseData(new GrassCoverErosionInwardsCalculation { InputParameters = { ShouldOvertoppingRateBeCalculated = true }, Output = new GrassCoverErosionInwardsOutput(overtoppingOutputWithoutGeneralResult, null, overtoppingRateOutputWithGeneralResult) }, true) .SetName("OvertoppingRateOutputWithRedundantGeneralResult")); yield return(new TestCaseData(new GrassCoverErosionInwardsCalculation { InputParameters = { ShouldOvertoppingRateBeCalculated = true, ShouldOvertoppingRateIllustrationPointsBeCalculated = true }, Output = new GrassCoverErosionInwardsOutput(overtoppingOutputWithoutGeneralResult, null, overtoppingRateOutputWithoutGeneralResult) }, true) .SetName("OvertoppingRateOutputWithMissingGeneralResult")); }
public void GetProperties_WithData_ReturnExpectedValues() { // Setup var random = new Random(39); double waveHeight = random.NextDouble(); bool isOvertoppingDominant = Convert.ToBoolean(random.Next(0, 2)); double reliability = random.NextDouble(); double dikeHeight = random.NextDouble(); double dikeHeightTargetProbability = random.NextDouble(); double dikeHeightTargetReliability = random.NextDouble(); double dikeHeightCalculatedProbability = random.NextDouble(); double dikeHeightCalculatedReliability = random.NextDouble(); var dikeHeightConvergence = random.NextEnumValue <CalculationConvergence>(); double overtoppingRate = random.NextDouble(); double overtoppingRateTargetProbability = random.NextDouble(); double overtoppingRateTargetReliability = random.NextDouble(); double overtoppingRateCalculatedProbability = random.NextDouble(); double overtoppingRateCalculatedReliability = random.NextDouble(); var overtoppingRateConvergence = random.NextEnumValue <CalculationConvergence>(); var resultOutput = new OvertoppingOutput(waveHeight, isOvertoppingDominant, reliability, null); var dikeHeightOutput = new DikeHeightOutput(dikeHeight, dikeHeightTargetProbability, dikeHeightTargetReliability, dikeHeightCalculatedProbability, dikeHeightCalculatedReliability, dikeHeightConvergence, null); var overtoppingRateOutput = new OvertoppingRateOutput(overtoppingRate, overtoppingRateTargetProbability, overtoppingRateTargetReliability, overtoppingRateCalculatedProbability, overtoppingRateCalculatedReliability, overtoppingRateConvergence, null); var output = new GrassCoverErosionInwardsOutput(resultOutput, dikeHeightOutput, overtoppingRateOutput); // Call var properties = new GrassCoverErosionInwardsOutputProperties(output); // Assert Assert.AreEqual(2, properties.WaveHeight.NumberOfDecimalPlaces); Assert.AreEqual(waveHeight, properties.WaveHeight, properties.WaveHeight.GetAccuracy()); Assert.AreEqual(reliability, properties.Reliability, properties.Reliability.GetAccuracy()); Assert.AreEqual(ProbabilityFormattingHelper.Format(0.5), properties.Probability); Assert.AreEqual(isOvertoppingDominant, properties.IsOvertoppingDominant); Assert.AreEqual(2, properties.DikeHeight.NumberOfDecimalPlaces); Assert.AreEqual(dikeHeight, properties.DikeHeight, properties.DikeHeight.GetAccuracy()); Assert.AreEqual(dikeHeightTargetProbability, properties.DikeHeightTargetProbability); TestHelper.AssertTypeConverter <GrassCoverErosionInwardsOutputProperties, NoProbabilityValueDoubleConverter>( nameof(GrassCoverErosionInwardsOutputProperties.DikeHeightTargetProbability)); Assert.AreEqual(dikeHeightTargetReliability, properties.DikeHeightTargetReliability, properties.DikeHeightTargetReliability.GetAccuracy()); TestHelper.AssertTypeConverter <GrassCoverErosionInwardsOutputProperties, NoValueRoundedDoubleConverter>( nameof(GrassCoverErosionInwardsOutputProperties.DikeHeightTargetReliability)); Assert.AreEqual(dikeHeightCalculatedProbability, properties.DikeHeightCalculatedProbability); TestHelper.AssertTypeConverter <GrassCoverErosionInwardsOutputProperties, NoProbabilityValueDoubleConverter>( nameof(GrassCoverErosionInwardsOutputProperties.DikeHeightCalculatedProbability)); Assert.AreEqual(dikeHeightCalculatedReliability, properties.DikeHeightCalculatedReliability, properties.DikeHeightCalculatedReliability.GetAccuracy()); TestHelper.AssertTypeConverter <GrassCoverErosionInwardsOutputProperties, NoValueRoundedDoubleConverter>( nameof(GrassCoverErosionInwardsOutputProperties.DikeHeightCalculatedReliability)); string dikeHeightConvergenceValue = EnumDisplayNameHelper.GetDisplayName(dikeHeightConvergence); Assert.AreEqual(dikeHeightConvergenceValue, properties.DikeHeightConvergence); Assert.AreEqual(2, properties.OvertoppingRate.NumberOfDecimalPlaces); Assert.AreEqual(overtoppingRate * 1000, properties.OvertoppingRate, properties.OvertoppingRate.GetAccuracy()); Assert.AreEqual(overtoppingRateTargetProbability, properties.OvertoppingRateTargetProbability); TestHelper.AssertTypeConverter <GrassCoverErosionInwardsOutputProperties, NoProbabilityValueDoubleConverter>( nameof(GrassCoverErosionInwardsOutputProperties.OvertoppingRateTargetProbability)); Assert.AreEqual(overtoppingRateTargetReliability, properties.OvertoppingRateTargetReliability, properties.OvertoppingRateTargetReliability.GetAccuracy()); TestHelper.AssertTypeConverter <GrassCoverErosionInwardsOutputProperties, NoValueRoundedDoubleConverter>( nameof(GrassCoverErosionInwardsOutputProperties.OvertoppingRateTargetReliability)); Assert.AreEqual(overtoppingRateCalculatedProbability, properties.OvertoppingRateCalculatedProbability); TestHelper.AssertTypeConverter <GrassCoverErosionInwardsOutputProperties, NoProbabilityValueDoubleConverter>( nameof(GrassCoverErosionInwardsOutputProperties.OvertoppingRateCalculatedProbability)); Assert.AreEqual(overtoppingRateCalculatedReliability, properties.OvertoppingRateCalculatedReliability, properties.OvertoppingRateCalculatedReliability.GetAccuracy()); TestHelper.AssertTypeConverter <GrassCoverErosionInwardsOutputProperties, NoValueRoundedDoubleConverter>( nameof(GrassCoverErosionInwardsOutputProperties.OvertoppingRateCalculatedReliability)); string overtoppingRateConvergenceValue = EnumDisplayNameHelper.GetDisplayName(overtoppingRateConvergence); Assert.AreEqual(overtoppingRateConvergenceValue, properties.OvertoppingRateConvergence); }