public void Validate_AssessmentLevelNaN_ReturnsFalseAndLogsValidationError() { // Setup var isValid = false; var input = new WaveConditionsInput { HydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, string.Empty, 0, 0) }; // Call void Call() => isValid = WaveConditionsCalculationServiceBase.Validate(input, RoundedDouble.NaN, GetValidHydraulicBoundaryDatabase()); // Assert TestHelper.AssertLogMessages(Call, messages => { string[] msgs = messages.ToArray(); Assert.AreEqual(3, msgs.Length); CalculationServiceTestHelper.AssertValidationStartMessage(msgs[0]); StringAssert.StartsWith("Kan waterstand bij doelkans niet afleiden op basis van de invoer", msgs[1]); CalculationServiceTestHelper.AssertValidationEndMessage(msgs[2]); }); Assert.IsFalse(isValid); }
public void Data_SetInputContextInstanceWithData_ReturnCorrectPropertyValues() { // Setup var input = new WaveConditionsInput { ForeshoreProfile = new TestForeshoreProfile(new[] { new Point2D(1.1, 2.2), new Point2D(3.3, 4.4) }) }; var properties = new WaveConditionsInputForeshoreProfileProperties(); // Call properties.Data = input; // Assert var expectedCoordinates = new[] { new Point2D(1.1, 2.2), new Point2D(3.3, 4.4) }; Assert.IsTrue(properties.UseForeshore); CollectionAssert.AreEqual(expectedCoordinates, properties.Coordinates); }
public void SetProperties_IndividualProperties_UpdateDataAndNotifyObservers() { // Setup var mockRepository = new MockRepository(); var observer = mockRepository.StrictMock <IObserver>(); const int numberOfChangedProperties = 1; observer.Expect(o => o.UpdateObserver()).Repeat.Times(numberOfChangedProperties); mockRepository.ReplayAll(); var input = new WaveConditionsInput(); var properties = new WaveConditionsInputForeshoreProfileProperties { Data = input }; input.Attach(observer); // Call properties.UseForeshore = false; // Assert Assert.IsFalse(input.UseForeshore); mockRepository.VerifyAll(); }
public void Constructor_ExpectedValues() { // Call var input = new WaveConditionsInput(); // Assert Assert.IsInstanceOf <CloneableObservable>(input); Assert.IsInstanceOf <ICalculationInputWithHydraulicBoundaryLocation>(input); Assert.IsInstanceOf <IUseBreakWater>(input); Assert.IsInstanceOf <IUseForeshore>(input); Assert.IsInstanceOf <IHasForeshoreProfile>(input); Assert.IsNull(input.HydraulicBoundaryLocation); Assert.IsNull(input.ForeshoreProfile); Assert.IsFalse(input.UseBreakWater); Assert.AreEqual(BreakWaterType.Dam, input.BreakWater.Type); Assert.AreEqual(new RoundedDouble(2), input.BreakWater.Height); Assert.IsFalse(input.UseForeshore); CollectionAssert.IsEmpty(input.ForeshoreGeometry); Assert.IsNaN(input.Orientation); Assert.AreEqual(2, input.Orientation.NumberOfDecimalPlaces); Assert.IsNaN(input.LowerBoundaryRevetment.Value); Assert.AreEqual(2, input.LowerBoundaryRevetment.NumberOfDecimalPlaces); Assert.IsNaN(input.UpperBoundaryRevetment.Value); Assert.AreEqual(2, input.UpperBoundaryRevetment.NumberOfDecimalPlaces); Assert.IsNaN(input.LowerBoundaryWaterLevels.Value); Assert.AreEqual(2, input.LowerBoundaryWaterLevels.NumberOfDecimalPlaces); Assert.IsNaN(input.UpperBoundaryWaterLevels.Value); Assert.AreEqual(2, input.UpperBoundaryWaterLevels.NumberOfDecimalPlaces); Assert.AreEqual(WaveConditionsInputStepSize.Half, input.StepSize); Assert.AreEqual(WaveConditionsInputWaterLevelType.None, input.WaterLevelType); Assert.IsNull(input.CalculationsTargetProbability); }
private static void AssertForeshoreProfileInputProperties(ForeshoreProfile expectedForeshoreProfile, WaveConditionsInput input) { var defaultInput = new WaveConditionsInput(); if (expectedForeshoreProfile == null) { Assert.AreEqual(defaultInput.UseBreakWater, input.UseBreakWater); Assert.AreEqual(defaultInput.UseForeshore, input.UseForeshore); } else { Assert.AreEqual(expectedForeshoreProfile.Orientation, input.Orientation); Assert.AreEqual(expectedForeshoreProfile.Geometry.Count() > 1, input.UseForeshore); Assert.AreEqual(expectedForeshoreProfile.HasBreakWater, input.UseBreakWater); } if (expectedForeshoreProfile?.BreakWater == null) { Assert.AreEqual(defaultInput.BreakWater.Type, input.BreakWater.Type); Assert.AreEqual(defaultInput.BreakWater.Height, input.BreakWater.Height); } else { Assert.AreEqual(expectedForeshoreProfile.BreakWater.Type, input.BreakWater.Type); Assert.AreEqual(expectedForeshoreProfile.BreakWater.Height, input.BreakWater.Height); } }
/// <summary> /// Performs validation over the given input parameters. Error and status information is logged /// during the execution of the operation. /// </summary> /// <param name="waveConditionsInput">The input of the calculation.</param> /// <param name="assessmentLevel">The assessment level to use for determining water levels.</param> /// <param name="hydraulicBoundaryDatabase">The hydraulic boundary database to validate.</param> /// <returns><c>true</c> if there were no validation errors; <c>false</c> otherwise.</returns> /// <exception cref="ArgumentNullException">Thrown when <paramref name="waveConditionsInput"/> or /// <paramref name="hydraulicBoundaryDatabase"/> is <c>null</c>.</exception> public static bool Validate(WaveConditionsInput waveConditionsInput, RoundedDouble assessmentLevel, HydraulicBoundaryDatabase hydraulicBoundaryDatabase) { if (waveConditionsInput == null) { throw new ArgumentNullException(nameof(waveConditionsInput)); } if (hydraulicBoundaryDatabase == null) { throw new ArgumentNullException(nameof(hydraulicBoundaryDatabase)); } CalculationServiceHelper.LogValidationBegin(); string[] messages = ValidateInput(hydraulicBoundaryDatabase, waveConditionsInput, assessmentLevel); CalculationServiceHelper.LogMessagesAsError(messages); CalculationServiceHelper.LogValidationEnd(); return(!messages.Any()); }
public void SynchronizeForeshoreProfileInput_ChangedForeshoreProfile_ExpectedValues() { // Setup var differentProfile = new ForeshoreProfile(new Point2D(9, 9), new[] { new Point2D(3.3, 4.4), new Point2D(5.5, 6.6) }, new BreakWater(BreakWaterType.Caisson, 2), new ForeshoreProfile.ConstructionProperties { Id = "id", Name = "Some name", Orientation = 123.0 }); var input = new WaveConditionsInput { ForeshoreProfile = new TestForeshoreProfile() }; input.ForeshoreProfile.CopyProperties(differentProfile); // Precondition AssertForeshoreProfileInputProperties(new TestForeshoreProfile(), input); // Call input.SynchronizeForeshoreProfileInput(); // Assert AssertForeshoreProfileInputProperties(differentProfile, input); }
/// <summary> /// Creates the input for a calculation for the given <paramref name="waterLevel"/>. /// </summary> /// <param name="waterLevel">The level of the water.</param> /// <param name="a">The 'a' factor decided on failure mechanism level.</param> /// <param name="b">The 'b' factor decided on failure mechanism level.</param> /// <param name="c">The 'c' factor decided on failure mechanism level.</param> /// <param name="targetProbability">The target probability to use.</param> /// <param name="input">The input that is different per calculation.</param> /// <param name="calculationSettings">The <see cref="HydraulicBoundaryCalculationSettings"/> containing all data /// to perform a hydraulic boundary calculation.</param> /// <returns>A <see cref="WaveConditionsCalculationInput"/>.</returns> /// <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> private static WaveConditionsCosineCalculationInput CreateInput(RoundedDouble waterLevel, RoundedDouble a, RoundedDouble b, RoundedDouble c, double targetProbability, WaveConditionsInput input, HydraulicBoundaryCalculationSettings calculationSettings) { var waveConditionsCosineCalculationInput = new WaveConditionsCosineCalculationInput( 1, input.Orientation, input.HydraulicBoundaryLocation.Id, targetProbability, HydraRingInputParser.ParseForeshore(input), HydraRingInputParser.ParseBreakWater(input), waterLevel, a, b, c); HydraRingSettingsDatabaseHelper.AssignSettingsFromDatabase(waveConditionsCosineCalculationInput, calculationSettings.HydraulicBoundaryDatabaseFilePath, !string.IsNullOrEmpty(calculationSettings.PreprocessorDirectory)); return(waveConditionsCosineCalculationInput); }
private static IEnumerable <string> ValidateWaveConditionsInput(WaveConditionsInput input, RoundedDouble assessmentLevel) { var messages = new List <string>(); if (input.HydraulicBoundaryLocation == null) { messages.Add(RiskeerCommonServiceResources.CalculationService_ValidateInput_No_hydraulic_boundary_location_selected); } else if (double.IsNaN(assessmentLevel)) { messages.Add(Resources.WaveConditionsCalculationService_ValidateInput_No_AssessmentLevel_calculated); } else { if (!input.GetWaterLevels(assessmentLevel).Any()) { messages.Add(Resources.WaveConditionsCalculationService_ValidateInput_No_derived_WaterLevels); } messages.AddRange(new UseBreakWaterRule(input).Validate()); messages.AddRange(new NumericInputRule(input.Orientation, ParameterNameExtractor.GetFromDisplayName(RiskeerCommonFormsResources.Orientation_DisplayName)).Validate()); } return(messages); }
private static string[] ValidateInput(HydraulicBoundaryDatabase hydraulicBoundaryDatabase, WaveConditionsInput input, RoundedDouble assessmentLevel) { var validationResults = new List <string>(); string databaseFilePathValidationProblem = HydraulicBoundaryDatabaseConnectionValidator.Validate(hydraulicBoundaryDatabase); if (!string.IsNullOrEmpty(databaseFilePathValidationProblem)) { validationResults.Add(databaseFilePathValidationProblem); } string preprocessorDirectoryValidationProblem = HydraulicBoundaryDatabaseHelper.ValidatePreprocessorDirectory(hydraulicBoundaryDatabase.EffectivePreprocessorDirectory()); if (!string.IsNullOrEmpty(preprocessorDirectoryValidationProblem)) { validationResults.Add(preprocessorDirectoryValidationProblem); } if (validationResults.Any()) { return(validationResults.ToArray()); } validationResults.AddRange(ValidateWaveConditionsInput(input, assessmentLevel)); return(validationResults.ToArray()); }
private static void SetInputParameters(WaveImpactAsphaltCoverWaveConditionsCalculationEntity entity, WaveConditionsInput calculationInput, PersistenceRegistry registry) { HydraulicBoundaryLocation hydraulicBoundaryLocation = calculationInput.HydraulicBoundaryLocation; if (hydraulicBoundaryLocation != null) { entity.HydraulicLocationEntity = hydraulicBoundaryLocation.Create(registry, 0); } if (calculationInput.ForeshoreProfile != null) { entity.ForeshoreProfileEntity = calculationInput.ForeshoreProfile.Create(registry, 0); } if (calculationInput.CalculationsTargetProbability != null) { entity.HydraulicLocationCalculationForTargetProbabilityCollectionEntity = calculationInput.CalculationsTargetProbability.Create(HydraulicBoundaryLocationCalculationType.WaterLevel, 0, registry); } entity.Orientation = calculationInput.Orientation.ToNaNAsNull(); entity.UseBreakWater = Convert.ToByte(calculationInput.UseBreakWater); entity.BreakWaterType = Convert.ToByte(calculationInput.BreakWater.Type); entity.BreakWaterHeight = calculationInput.BreakWater.Height.ToNaNAsNull(); entity.UseForeshore = Convert.ToByte(calculationInput.UseForeshore); entity.UpperBoundaryRevetment = calculationInput.UpperBoundaryRevetment.ToNaNAsNull(); entity.LowerBoundaryRevetment = calculationInput.LowerBoundaryRevetment.ToNaNAsNull(); entity.UpperBoundaryWaterLevels = calculationInput.UpperBoundaryWaterLevels.ToNaNAsNull(); entity.LowerBoundaryWaterLevels = calculationInput.LowerBoundaryWaterLevels.ToNaNAsNull(); entity.StepSize = Convert.ToByte(calculationInput.StepSize); entity.WaterLevelType = Convert.ToByte(calculationInput.WaterLevelType); }
public void Read_EntityWithNullValues_ReturnCalculationWithNaNValues() { // Setup var entity = new WaveImpactAsphaltCoverWaveConditionsCalculationEntity(); var collector = new ReadConversionCollector(); // Call WaveImpactAsphaltCoverWaveConditionsCalculation calculation = entity.Read(collector); // Assert Assert.IsNull(calculation.Name); Assert.IsNull(calculation.Comments.Body); WaveConditionsInput calculationInput = calculation.InputParameters; Assert.IsNaN(calculationInput.BreakWater.Height); Assert.IsNaN(calculationInput.Orientation); Assert.IsNaN(calculationInput.UpperBoundaryRevetment); Assert.IsNaN(calculationInput.LowerBoundaryRevetment); Assert.IsNaN(calculationInput.UpperBoundaryWaterLevels); Assert.IsNaN(calculationInput.LowerBoundaryWaterLevels); Assert.IsNull(calculationInput.HydraulicBoundaryLocation); Assert.IsNull(calculationInput.ForeshoreProfile); Assert.IsNull(calculation.Output); }
public void Validate_NoWaterLevels_ReturnsFalseAndLogsValidationError(double lowerBoundaryRevetments, double upperBoundaryRevetments, double assessmentLevel) { // Setup var isValid = false; var input = new WaveConditionsInput { HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(), Orientation = (RoundedDouble)0, LowerBoundaryRevetment = (RoundedDouble)lowerBoundaryRevetments, UpperBoundaryRevetment = (RoundedDouble)upperBoundaryRevetments, StepSize = WaveConditionsInputStepSize.One, LowerBoundaryWaterLevels = (RoundedDouble)1.0, UpperBoundaryWaterLevels = (RoundedDouble)10.0 }; // Call void Call() => isValid = WaveConditionsCalculationServiceBase.Validate(input, (RoundedDouble)assessmentLevel, GetValidHydraulicBoundaryDatabase()); // Assert TestHelper.AssertLogMessages(Call, messages => { string[] msgs = messages.ToArray(); Assert.AreEqual(3, msgs.Length); CalculationServiceTestHelper.AssertValidationStartMessage(msgs[0]); Assert.AreEqual("Kan geen waterstanden afleiden op basis van de invoer. Controleer de opgegeven boven- en ondergrenzen.", msgs[1]); CalculationServiceTestHelper.AssertValidationEndMessage(msgs[2]); }); Assert.IsFalse(isValid); }
public void Validate_ForeshoreProfileUseBreakWaterAndHasInvalidBreakWaterHeight_ReturnsFalseAndLogsValidationMessages(double breakWaterHeight) { // Setup var isValid = false; WaveConditionsInput input = GetDefaultValidationInput(); input.ForeshoreProfile = new TestForeshoreProfile(new BreakWater(BreakWaterType.Dam, breakWaterHeight)); input.UseBreakWater = true; // Call void Call() => isValid = WaveConditionsCalculationServiceBase.Validate(input, GetValidAssessmentLevel(), GetValidHydraulicBoundaryDatabase()); // Assert TestHelper.AssertLogMessages(Call, messages => { string[] msgs = messages.ToArray(); Assert.AreEqual(3, msgs.Length); CalculationServiceTestHelper.AssertValidationStartMessage(msgs[0]); StringAssert.StartsWith("De waarde voor 'hoogte' van de dam moet een concreet getal zijn.", msgs[1]); CalculationServiceTestHelper.AssertValidationEndMessage(msgs[2]); }); Assert.IsFalse(isValid); }
private static double GetPointXOnRevetmentLine(WaveConditionsInput input, double valueY) { Point2D baseStartPoint = GetBaseStartPoint(input); double endPointX = ((valueY - baseStartPoint.Y) / 3) + baseStartPoint.X; return(endPointX); }
/// <summary> /// Create assessment level geometry points in 2D space based on the provided <paramref name="input"/>. /// </summary> /// <param name="input">The <see cref="WaveConditionsInput"/> to create the assessment level geometry points for.</param> /// <param name="assessmentLevel">The assessment level to use while determining water levels.</param> /// <returns>A collection of points in 2D space or an empty collection when: /// <list type="bullet"> /// <item><paramref name="input"/> is <c>null</c>;</item> /// <item><see cref="WaveConditionsInput.HydraulicBoundaryLocation"/> is <c>null</c>;</item> /// <item>the assessment level is <see cref="RoundedDouble.NaN"/>.</item> /// </list> /// </returns> public static IEnumerable <Point2D> CreateAssessmentLevelGeometryPoints(WaveConditionsInput input, RoundedDouble assessmentLevel) { return(input != null ? CreateGeometryPoints(input, () => assessmentLevel) : new Point2D[0]); }
/// <summary> /// Creates a collection of <see cref="ExportableWaveConditions"/>. /// </summary> /// <param name="name">The name of the calculation to which the <see cref="WaveConditionsOutput"/> belong.</param> /// <param name="waveConditionsInput">The <see cref="WaveConditionsInput"/> used in the calculations.</param> /// <param name="output">The <see cref="WaveConditionsOutput"/> resulting from the calculations.</param> /// <param name="coverType">The <see cref="CoverType"/> that the <paramref name="output"/> represents.</param> /// <param name="getTargetProbabilityFunc"><see cref="Func{TResult}"/> for getting the target probability to use.</param> /// <returns>A collection of <see cref="ExportableWaveConditions"/>.</returns> /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception> /// <exception cref="ArgumentException">Thrown when <see cref="WaveConditionsInput.HydraulicBoundaryLocation"/> /// is <c>null</c> in <paramref name="waveConditionsInput"/>.</exception> public static IEnumerable <ExportableWaveConditions> CreateExportableWaveConditionsCollection( string name, WaveConditionsInput waveConditionsInput, IEnumerable <WaveConditionsOutput> output, CoverType coverType, Func <WaveConditionsInput, string> getTargetProbabilityFunc) { if (name == null) { throw new ArgumentNullException(nameof(name)); } if (waveConditionsInput == null) { throw new ArgumentNullException(nameof(waveConditionsInput)); } if (output == null) { throw new ArgumentNullException(nameof(output)); } if (coverType == null) { throw new ArgumentNullException(nameof(coverType)); } if (getTargetProbabilityFunc == null) { throw new ArgumentNullException(nameof(getTargetProbabilityFunc)); } return(output.Select(waveConditionsOutput => new ExportableWaveConditions(name, waveConditionsInput, waveConditionsOutput, coverType, getTargetProbabilityFunc(waveConditionsInput))).ToArray()); }
public void CreateAssessmentLevelGeometryPoints_WithForeshoreProfile_ReturnsAssessmentLevelGeometryPointsCollection( IEnumerable <Point2D> foreshoreProfileGeometry) { // Setup RoundedDouble assessmentLevel = GetValidAssessmentLevel(); var input = new WaveConditionsInput { ForeshoreProfile = new TestForeshoreProfile(foreshoreProfileGeometry) }; // Call IEnumerable <Point2D> points = WaveConditionsChartDataPointsFactory.CreateAssessmentLevelGeometryPoints(input, assessmentLevel); // Assert Point2D lastGeometryPoint = foreshoreProfileGeometry.Last(); double endPointX = (assessmentLevel - lastGeometryPoint.Y) / 3; var expectedPoints = new[] { new Point2D(foreshoreProfileGeometry.First().X, 6), new Point2D(endPointX + lastGeometryPoint.X, 6) }; CollectionAssert.AreEqual(expectedPoints, points); }
public void CreateWaterLevelsGeometryPoints_NoForeshoreProfile_ReturnsWaterLevelsGeometryPointsCollection() { // Setup var input = new WaveConditionsInput { LowerBoundaryRevetment = (RoundedDouble)5, UpperBoundaryRevetment = (RoundedDouble)7, StepSize = WaveConditionsInputStepSize.One }; // Call IEnumerable <IEnumerable <Point2D> > lines = WaveConditionsChartDataPointsFactory.CreateWaterLevelsGeometryPoints(input, (RoundedDouble)6.01); // Assert var expectedLines = new[] { new[] { new Point2D(-10, 6), new Point2D(2, 6) }, new[] { new Point2D(-10, 5), new Point2D(1.666667, 5) } }; AssertWaterLevelGeometries(expectedLines, lines); }
public void CreateUpperBoundaryWaterLevelsGeometryPoints_WithForeshoreProfile_ReturnsUpperBoundaryWaterLevelsGeometryPointsCollection( IEnumerable <Point2D> foreshoreProfileGeometry) { // Setup var input = new WaveConditionsInput { UpperBoundaryWaterLevels = (RoundedDouble)9, ForeshoreProfile = new TestForeshoreProfile(foreshoreProfileGeometry) }; // Call IEnumerable <Point2D> points = WaveConditionsChartDataPointsFactory.CreateUpperBoundaryWaterLevelsGeometryPoints(input); // Assert Point2D lastGeometryPoint = foreshoreProfileGeometry.Last(); double endPointX = (input.UpperBoundaryWaterLevels - lastGeometryPoint.Y) / 3; var expectedPoints = new[] { new Point2D(foreshoreProfileGeometry.First().X, 9), new Point2D(endPointX + lastGeometryPoint.X, 9) }; CollectionAssert.AreEqual(expectedPoints, points); }
public void CreateAssessmentLevelGeometryPoints_UseForeshoreProfileFalse_ReturnsAssessmentLevelGeometryPointsCollection() { // Setup var input = new WaveConditionsInput { ForeshoreProfile = new TestForeshoreProfile(new[] { new Point2D(0, 0), new Point2D(3, 4) }), UseForeshore = false }; // Call IEnumerable <Point2D> points = WaveConditionsChartDataPointsFactory.CreateAssessmentLevelGeometryPoints(input, GetValidAssessmentLevel()); // Assert var expectedPoints = new[] { new Point2D(-10, 6), new Point2D(2, 6) }; CollectionAssert.AreEqual(expectedPoints, points); }
public void CreateRevetmentBaseGeometryPoints_InputWithForeshoreProfileAndLowerBoundaryWaterLevelsBelowForeshoreProfile_ReturnRevetmentBaseGeometryPointsCollection( IEnumerable <Point2D> foreshoreProfileGeometry) { // Setup const double lowerBoundaryRevetment = 2; const double upperBoundaryRevetment = 8; const double lowerBoundaryWaterLevels = -3; var input = new WaveConditionsInput { LowerBoundaryWaterLevels = (RoundedDouble)lowerBoundaryWaterLevels, LowerBoundaryRevetment = (RoundedDouble)lowerBoundaryRevetment, UpperBoundaryRevetment = (RoundedDouble)upperBoundaryRevetment, ForeshoreProfile = new TestForeshoreProfile(foreshoreProfileGeometry) }; // Call IEnumerable <Point2D> points = WaveConditionsChartDataPointsFactory.CreateRevetmentBaseGeometryPoints(input); // Assert Point2D lastGeometryPoint = foreshoreProfileGeometry.Last(); var expectedGeometry = new[] { new Point2D((lowerBoundaryWaterLevels - lastGeometryPoint.Y) / 3 + lastGeometryPoint.X, lowerBoundaryWaterLevels), new Point2D(lastGeometryPoint), new Point2D((lowerBoundaryRevetment - lastGeometryPoint.Y) / 3 + lastGeometryPoint.X, lowerBoundaryRevetment) }; CollectionAssert.AreEqual(expectedGeometry, points); }
public void CreateUpperBoundaryWaterLevelsGeometryPoints_UseForeshoreProfileFalse_ReturnsUpperBoundaryWaterLevelsGeometryPointsCollection() { // Setup var input = new WaveConditionsInput { UpperBoundaryWaterLevels = (RoundedDouble)9, ForeshoreProfile = new TestForeshoreProfile(new[] { new Point2D(0, 0), new Point2D(3, 4) }), UseForeshore = false }; // Call IEnumerable <Point2D> points = WaveConditionsChartDataPointsFactory.CreateUpperBoundaryWaterLevelsGeometryPoints(input); // Assert var expectedPoints = new[] { new Point2D(-10, 9), new Point2D(3, 9) }; CollectionAssert.AreEqual(expectedPoints, points); }
public void GetAssessmentLevel_ValidInputWithHydraulicBoundaryLocation_ReturnsExpectedValue( WaveConditionsInputWaterLevelType waterLevelType, Func <WaveConditionsInput, IAssessmentSection, double> getExpectedAssessmentLevel) { // Setup var assessmentSection = new AssessmentSectionStub(); var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { hydraulicBoundaryLocation }, true); var input = new WaveConditionsInput { HydraulicBoundaryLocation = hydraulicBoundaryLocation, WaterLevelType = waterLevelType, CalculationsTargetProbability = assessmentSection.WaterLevelCalculationsForUserDefinedTargetProbabilities.First() }; // Call double assessmentLevel = WaveConditionsInputHelper.GetAssessmentLevel(input, assessmentSection); // Assert Assert.AreEqual(getExpectedAssessmentLevel(input, assessmentSection), assessmentLevel); }
public void CreateRevetmentBaseGeometryPoints_InputUseForeshoreProfileFalse_ReturnRevetmentBaseGeometryPointsCollection() { // Setup const double lowerBoundaryRevetment = 2; const double upperBoundaryRevetment = 8; var input = new WaveConditionsInput { LowerBoundaryRevetment = (RoundedDouble)lowerBoundaryRevetment, UpperBoundaryRevetment = (RoundedDouble)upperBoundaryRevetment, ForeshoreProfile = new TestForeshoreProfile(new[] { new Point2D(1, 1), new Point2D(3, 5), new Point2D(10, 7) }), UseForeshore = false }; // Call IEnumerable <Point2D> points = WaveConditionsChartDataPointsFactory.CreateRevetmentBaseGeometryPoints(input); // Assert CollectionAssert.AreEqual(new[] { new Point2D(0, 0), new Point2D(lowerBoundaryRevetment / 3, 2) }, points); }
public void Validate_StructureNormalOrientationInvalid_ReturnsFalse() { // Setup var isValid = false; WaveConditionsInput input = GetDefaultValidationInput(); input.Orientation = RoundedDouble.NaN; // Call void Call() => isValid = WaveConditionsCalculationServiceBase.Validate(input, GetValidAssessmentLevel(), GetValidHydraulicBoundaryDatabase()); // Assert TestHelper.AssertLogMessages(Call, messages => { string[] msgs = messages.ToArray(); Assert.AreEqual(3, msgs.Length); CalculationServiceTestHelper.AssertValidationStartMessage(msgs[0]); Assert.AreEqual("De waarde voor 'Oriëntatie' moet een concreet getal zijn.", msgs[1]); CalculationServiceTestHelper.AssertValidationEndMessage(msgs[2]); }); Assert.IsFalse(isValid); }
public void Validate_ForeshoreProfileDoesNotUseBreakWaterAndHasInvalidBreakwaterHeight_ReturnsTrueAndLogsValidationStartAndEnd(double breakWaterHeight) { // Setup var isValid = false; WaveConditionsInput input = GetDefaultValidationInput(); input.ForeshoreProfile = new TestForeshoreProfile(new BreakWater(BreakWaterType.Wall, breakWaterHeight)); input.UseBreakWater = false; // Call void Call() => isValid = WaveConditionsCalculationServiceBase.Validate(input, GetValidAssessmentLevel(), GetValidHydraulicBoundaryDatabase()); // Assert TestHelper.AssertLogMessages(Call, messages => { string[] msgs = messages.ToArray(); Assert.AreEqual(2, msgs.Length); CalculationServiceTestHelper.AssertValidationStartMessage(msgs[0]); CalculationServiceTestHelper.AssertValidationEndMessage(msgs[1]); }); Assert.IsTrue(isValid); }
public void Calculate_VariousHydraulicBoundaryDatabaseConfigurations_StartsCalculationWithRightParameters( HydraulicBoundaryDatabase hydraulicBoundaryDatabase) { // Setup var waterLevel = (RoundedDouble)4.20; var a = (RoundedDouble)1.0; var b = (RoundedDouble)0.8; var c = (RoundedDouble)0.4; const double targetProbability = 0.2; var input = new WaveConditionsInput { HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(), ForeshoreProfile = new TestForeshoreProfile(true), UpperBoundaryRevetment = (RoundedDouble)4, LowerBoundaryRevetment = (RoundedDouble)3, StepSize = WaveConditionsInputStepSize.Two, Orientation = (RoundedDouble)0 }; var calculator = new TestWaveConditionsCosineCalculator(); int nrOfCalculators = input.GetWaterLevels(waterLevel).Count(); var mockRepository = new MockRepository(); var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>(); calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(Arg <HydraRingCalculationSettings> .Is.NotNull)) .WhenCalled(invocation => { HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings( HydraulicBoundaryCalculationSettingsFactory.CreateSettings(hydraulicBoundaryDatabase), (HydraRingCalculationSettings)invocation.Arguments[0]); }) .Return(calculator) .Repeat .Times(nrOfCalculators); mockRepository.ReplayAll(); using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { // Call new TestWaveConditionsCalculationService().PublicCalculate(a, b, c, targetProbability, input, waterLevel, hydraulicBoundaryDatabase); // Assert for (var i = 0; i < nrOfCalculators; i++) { Assert.AreEqual(hydraulicBoundaryDatabase.HydraulicLocationConfigurationSettings.UsePreprocessor, calculator.ReceivedInputs.ElementAt(i).PreprocessorSetting.RunPreprocessor); } } mockRepository.VerifyAll(); }
public void Calculate_Always_InputPropertiesCorrectlySentToCalculator(BreakWaterType breakWaterType) { // Setup IAssessmentSection assessmentSection = CreateAssessmentSectionWithHydraulicBoundaryOutput(); WaveImpactAsphaltCoverWaveConditionsCalculation calculation = GetValidCalculation(assessmentSection.HydraulicBoundaryDatabase.Locations.First()); calculation.InputParameters.BreakWater.Type = breakWaterType; var waveImpactAsphaltCoverFailureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); var calculator = new TestWaveConditionsCosineCalculator(); var mockRepository = new MockRepository(); var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>(); calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(null)) .IgnoreArguments() .Return(calculator) .Repeat .Times(3); mockRepository.ReplayAll(); using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { // Call new WaveImpactAsphaltCoverWaveConditionsCalculationService().Calculate( calculation, assessmentSection, waveImpactAsphaltCoverFailureMechanism.GeneralInput); // Assert WaveConditionsCosineCalculationInput[] waveConditionsInputs = calculator.ReceivedInputs.ToArray(); Assert.AreEqual(3, waveConditionsInputs.Length); var waterLevelIndex = 0; foreach (WaveConditionsCosineCalculationInput actualInput in waveConditionsInputs) { GeneralWaveConditionsInput generalInput = waveImpactAsphaltCoverFailureMechanism.GeneralInput; WaveConditionsInput input = calculation.InputParameters; var expectedInput = new WaveConditionsCosineCalculationInput(1, input.Orientation, input.HydraulicBoundaryLocation.Id, assessmentSection.FailureMechanismContribution.MaximumAllowableFloodingProbability, input.ForeshoreProfile.Geometry.Select(c => new HydraRingForelandPoint(c.X, c.Y)), new HydraRingBreakWater(BreakWaterTypeHelper.GetHydraRingBreakWaterType(breakWaterType), input.BreakWater.Height), GetWaterLevels(calculation, assessmentSection).ElementAt(waterLevelIndex++), generalInput.A, generalInput.B, generalInput.C); HydraRingDataEqualityHelper.AreEqual(expectedInput, actualInput); } } mockRepository.VerifyAll(); }
public void Calculate_WithoutBreakWater_StartsCalculationWithRightParameters(bool useForeshore) { // Setup var waterLevel = (RoundedDouble)4.20; var a = (RoundedDouble)1.0; var b = (RoundedDouble)0.8; var c = (RoundedDouble)0.4; const double targetProbability = 0.2; var input = new WaveConditionsInput { HydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(), ForeshoreProfile = new TestForeshoreProfile(true), UpperBoundaryRevetment = (RoundedDouble)4, LowerBoundaryRevetment = (RoundedDouble)3, StepSize = WaveConditionsInputStepSize.Two, UseBreakWater = false, UseForeshore = useForeshore, Orientation = (RoundedDouble)0 }; var calculator = new TestWaveConditionsCosineCalculator(); RoundedDouble[] waterLevels = input.GetWaterLevels(waterLevel).ToArray(); int nrOfCalculators = waterLevels.Length; var mockRepository = new MockRepository(); var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>(); calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(null)) .IgnoreArguments() .Return(calculator) .Repeat .Times(nrOfCalculators); mockRepository.ReplayAll(); using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { // Call new TestWaveConditionsCalculationService().PublicCalculate(a, b, c, targetProbability, input, waterLevel, GetValidHydraulicBoundaryDatabase()); // Assert for (var i = 0; i < nrOfCalculators; i++) { WaveConditionsCosineCalculationInput expectedInput = CreateInput(waterLevels[i], a, b, c, targetProbability, input, useForeshore, false); HydraRingDataEqualityHelper.AreEqual(expectedInput, calculator.ReceivedInputs.ElementAt(i)); } } mockRepository.VerifyAll(); }