public void Constructor_ExpectedValues() { // Call var generalInput = new GeneralStabilityStoneCoverWaveConditionsInput(); // Assert Assert.AreEqual(2, generalInput.GeneralBlocksWaveConditionsInput.A.NumberOfDecimalPlaces); Assert.AreEqual(1.0, generalInput.GeneralBlocksWaveConditionsInput.A, generalInput.GeneralBlocksWaveConditionsInput.A.GetAccuracy()); Assert.AreEqual(2, generalInput.GeneralBlocksWaveConditionsInput.B.NumberOfDecimalPlaces); Assert.AreEqual(1.0, generalInput.GeneralBlocksWaveConditionsInput.B, generalInput.GeneralBlocksWaveConditionsInput.B.GetAccuracy()); Assert.AreEqual(2, generalInput.GeneralBlocksWaveConditionsInput.C.NumberOfDecimalPlaces); Assert.AreEqual(1.0, generalInput.GeneralBlocksWaveConditionsInput.C, generalInput.GeneralBlocksWaveConditionsInput.C.GetAccuracy()); Assert.AreEqual(2, generalInput.GeneralColumnsWaveConditionsInput.A.NumberOfDecimalPlaces); Assert.AreEqual(1.0, generalInput.GeneralColumnsWaveConditionsInput.A, generalInput.GeneralColumnsWaveConditionsInput.A.GetAccuracy()); Assert.AreEqual(2, generalInput.GeneralColumnsWaveConditionsInput.B.NumberOfDecimalPlaces); Assert.AreEqual(0.4, generalInput.GeneralColumnsWaveConditionsInput.B, generalInput.GeneralColumnsWaveConditionsInput.B.GetAccuracy()); Assert.AreEqual(2, generalInput.GeneralColumnsWaveConditionsInput.C.NumberOfDecimalPlaces); Assert.AreEqual(0.8, generalInput.GeneralColumnsWaveConditionsInput.C, generalInput.GeneralColumnsWaveConditionsInput.C.GetAccuracy()); Assert.AreEqual(2, generalInput.N.NumberOfDecimalPlaces); Assert.AreEqual(4.0, generalInput.N, generalInput.N.GetAccuracy()); Assert.IsFalse(generalInput.ApplyLengthEffectInSection); }
public void Constructor_ExpectedValues() { // Setup var random = new Random(21); var failureMechanism = new StabilityStoneCoverFailureMechanism { InAssembly = random.NextBoolean() }; // Call var properties = new StabilityStoneCoverFailureMechanismProperties(failureMechanism); // Assert Assert.IsInstanceOf <StabilityStoneCoverFailureMechanismPropertiesBase>(properties); Assert.AreEqual(failureMechanism.Name, properties.Name); Assert.AreEqual(failureMechanism.Code, properties.Code); Assert.AreEqual(failureMechanism.InAssembly, properties.InAssembly); GeneralStabilityStoneCoverWaveConditionsInput generalInput = failureMechanism.GeneralInput; Assert.AreEqual(2, properties.N.NumberOfDecimalPlaces); Assert.AreEqual(generalInput.N, properties.N, properties.N.GetAccuracy()); Assert.AreEqual(generalInput.ApplyLengthEffectInSection, properties.ApplyLengthEffectInSection); }
public void N_SetValidValue_UpdatesValue(double value) { // Setup var generalInput = new GeneralStabilityStoneCoverWaveConditionsInput(); // Call generalInput.N = (RoundedDouble)value; // Assert Assert.AreEqual(value, generalInput.N, generalInput.N.GetAccuracy()); }
public void N_SetValueOutsideValidRange_ThrowArgumentOutOfRangeException(double value) { // Setup var generalInput = new GeneralStabilityStoneCoverWaveConditionsInput(); // Call TestDelegate call = () => generalInput.N = (RoundedDouble)value; // Assert var expectedMessage = "De waarde voor 'N' moet in het bereik [1,00, 20,00] liggen."; TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentOutOfRangeException>(call, expectedMessage); }
public void Read_WithAllData_SetsGeneralInputProperties() { // Setup var random = new Random(); var entity = new StabilityStoneCoverFailureMechanismMetaEntity { N = random.NextDouble(1, 20), ApplyLengthEffectInSection = Convert.ToByte(random.NextBoolean()) }; var generalInput = new GeneralStabilityStoneCoverWaveConditionsInput(); // Call entity.Read(generalInput); // Assert Assert.AreEqual(entity.N, generalInput.N, generalInput.N.GetAccuracy()); Assert.AreEqual(Convert.ToBoolean(entity.ApplyLengthEffectInSection), generalInput.ApplyLengthEffectInSection); }
public void Constructor_ExpectedValues() { // Setup var failureMechanism = new StabilityStoneCoverFailureMechanism(); // Call var properties = new StabilityStoneCoverFailureMechanismProperties(failureMechanism); // Assert Assert.IsInstanceOf <StabilityStoneCoverFailureMechanismPropertiesBase>(properties); TestHelper.AssertTypeConverter <StabilityStoneCoverFailureMechanismProperties, ExpandableObjectConverter>( nameof(StabilityStoneCoverFailureMechanismProperties.Columns)); TestHelper.AssertTypeConverter <StabilityStoneCoverFailureMechanismProperties, ExpandableObjectConverter>( nameof(StabilityStoneCoverFailureMechanismProperties.Blocks)); Assert.AreSame(failureMechanism, properties.Data); Assert.AreEqual(failureMechanism.Name, properties.Name); Assert.AreEqual(failureMechanism.Code, properties.Code); GeneralStabilityStoneCoverWaveConditionsInput generalInput = failureMechanism.GeneralInput; Assert.AreSame(generalInput.GeneralBlocksWaveConditionsInput, properties.Blocks.Data); Assert.AreSame(generalInput.GeneralColumnsWaveConditionsInput, properties.Columns.Data); }
/// <summary> /// Performs a wave conditions calculation for the stability of stone revetment failure mechanism based on the supplied /// <see cref="StabilityStoneCoverWaveConditionsCalculation"/> and sets /// <see cref="StabilityStoneCoverWaveConditionsCalculation.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="StabilityStoneCoverWaveConditionsCalculation"/> 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="generalWaveConditionsInput">Calculation input parameters that apply to all <see cref="StabilityStoneCoverWaveConditionsCalculation"/> instances.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="calculation"/>, <paramref name="assessmentSection"/> /// or <paramref name="generalWaveConditionsInput"/> is <c>null</c>.</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="ArgumentOutOfRangeException">Thrown when the target probability or /// calculated probability falls outside the [0.0, 1.0] range and is not <see cref="double.NaN"/>.</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> public void Calculate(StabilityStoneCoverWaveConditionsCalculation calculation, IAssessmentSection assessmentSection, GeneralStabilityStoneCoverWaveConditionsInput generalWaveConditionsInput) { if (calculation == null) { throw new ArgumentNullException(nameof(calculation)); } if (assessmentSection == null) { throw new ArgumentNullException(nameof(assessmentSection)); } if (generalWaveConditionsInput == null) { throw new ArgumentNullException(nameof(generalWaveConditionsInput)); } StabilityStoneCoverWaveConditionsInput calculationInput = calculation.InputParameters; StabilityStoneCoverWaveConditionsCalculationType calculationType = calculationInput.CalculationType; if (!Enum.IsDefined(typeof(StabilityStoneCoverWaveConditionsCalculationType), calculationType)) { throw new InvalidEnumArgumentException(nameof(calculationType), (int)calculationType, typeof(StabilityStoneCoverWaveConditionsCalculationType)); } CalculationServiceHelper.LogCalculationBegin(); double targetProbability = WaveConditionsInputHelper.GetTargetProbability(calculationInput, assessmentSection); RoundedDouble assessmentLevel = WaveConditionsInputHelper.GetAssessmentLevel(calculationInput, assessmentSection); int waterLevelCount = calculationInput.GetWaterLevels(assessmentLevel).Count(); TotalWaterLevelCalculations = calculationType == StabilityStoneCoverWaveConditionsCalculationType.Both ? waterLevelCount * 2 : waterLevelCount; try { IEnumerable <WaveConditionsOutput> blocksOutputs = null; if (calculationType == StabilityStoneCoverWaveConditionsCalculationType.Both || calculationType == StabilityStoneCoverWaveConditionsCalculationType.Blocks) { CurrentCalculationType = Resources.StabilityStoneCoverWaveConditions_Blocks_DisplayName; blocksOutputs = CalculateBlocks(calculation, assessmentSection, assessmentLevel, generalWaveConditionsInput.GeneralBlocksWaveConditionsInput, targetProbability); } if (Canceled) { return; } IEnumerable <WaveConditionsOutput> columnsOutputs = null; if (calculationType == StabilityStoneCoverWaveConditionsCalculationType.Both || calculationType == StabilityStoneCoverWaveConditionsCalculationType.Columns) { CurrentCalculationType = Resources.StabilityStoneCoverWaveConditions_Columns_DisplayName; columnsOutputs = CalculateColumns(calculation, assessmentSection, assessmentLevel, generalWaveConditionsInput.GeneralColumnsWaveConditionsInput, targetProbability); } if (!Canceled) { calculation.Output = CreateOutput(calculationType, blocksOutputs, columnsOutputs); } } finally { CalculationServiceHelper.LogCalculationEnd(); } }
/// <summary> /// Read the <see cref="StabilityStoneCoverFailureMechanismMetaEntity"/> and use the information to /// update the <see cref="GeneralStabilityStoneCoverWaveConditionsInput"/>. /// </summary> /// <param name="entity">The <see cref="StabilityStoneCoverFailureMechanismMetaEntity"/> to update /// <see cref="GeneralStabilityStoneCoverWaveConditionsInput"/> for.</param> /// <param name="generalInput">The <see cref="GeneralStabilityStoneCoverWaveConditionsInput"/> to update.</param> /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception> internal static void Read(this StabilityStoneCoverFailureMechanismMetaEntity entity, GeneralStabilityStoneCoverWaveConditionsInput generalInput) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } if (generalInput == null) { throw new ArgumentNullException(nameof(generalInput)); } generalInput.N = (RoundedDouble)entity.N; generalInput.ApplyLengthEffectInSection = Convert.ToBoolean(entity.ApplyLengthEffectInSection); }
public void Run_Always_InputPropertiesCorrectlySentToService(BreakWaterType breakWaterType) { // Setup IAssessmentSection assessmentSection = CreateAssessmentSectionWithHydraulicBoundaryOutput(); StabilityStoneCoverWaveConditionsCalculation calculation = CreateValidCalculation(assessmentSection.HydraulicBoundaryDatabase.Locations.First()); calculation.InputParameters.BreakWater.Type = breakWaterType; var stabilityStoneCoverFailureMechanism = new StabilityStoneCoverFailureMechanism(); CalculatableActivity activity = StabilityStoneCoverWaveConditionsCalculationActivityFactory.CreateCalculationActivity(calculation, stabilityStoneCoverFailureMechanism, assessmentSection); var mockRepository = new MockRepository(); var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>(); var calculator = new TestWaveConditionsCosineCalculator(); RoundedDouble[] waterLevels = GetWaterLevels(calculation, assessmentSection).ToArray(); int nrOfCalculators = waterLevels.Length * 2; calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(null)) .IgnoreArguments() .Return(calculator) .Repeat .Times(nrOfCalculators); mockRepository.ReplayAll(); using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { // Call activity.Run(); // Assert WaveConditionsCosineCalculationInput[] waveConditionsInputs = calculator.ReceivedInputs.ToArray(); Assert.AreEqual(nrOfCalculators, waveConditionsInputs.Length); GeneralStabilityStoneCoverWaveConditionsInput generalInput = stabilityStoneCoverFailureMechanism.GeneralInput; WaveConditionsInput input = calculation.InputParameters; double targetProbability = assessmentSection.FailureMechanismContribution.MaximumAllowableFloodingProbability; var waterLevelIndex = 0; for (var i = 0; i < waveConditionsInputs.Length / 2; i++) { var expectedInput = new WaveConditionsCosineCalculationInput(1, input.Orientation, input.HydraulicBoundaryLocation.Id, targetProbability, input.ForeshoreProfile.Geometry.Select(c => new HydraRingForelandPoint(c.X, c.Y)), new HydraRingBreakWater(BreakWaterTypeHelper.GetHydraRingBreakWaterType(breakWaterType), input.BreakWater.Height), waterLevels[waterLevelIndex++], generalInput.GeneralBlocksWaveConditionsInput.A, generalInput.GeneralBlocksWaveConditionsInput.B, generalInput.GeneralBlocksWaveConditionsInput.C); HydraRingDataEqualityHelper.AreEqual(expectedInput, waveConditionsInputs[i]); } waterLevelIndex = 0; for (int i = waveConditionsInputs.Length / 2; i < waveConditionsInputs.Length; i++) { var expectedInput = new WaveConditionsCosineCalculationInput(1, input.Orientation, input.HydraulicBoundaryLocation.Id, targetProbability, input.ForeshoreProfile.Geometry.Select(c => new HydraRingForelandPoint(c.X, c.Y)), new HydraRingBreakWater(BreakWaterTypeHelper.GetHydraRingBreakWaterType(breakWaterType), input.BreakWater.Height), waterLevels[waterLevelIndex++], generalInput.GeneralColumnsWaveConditionsInput.A, generalInput.GeneralColumnsWaveConditionsInput.B, generalInput.GeneralColumnsWaveConditionsInput.C); HydraRingDataEqualityHelper.AreEqual(expectedInput, waveConditionsInputs[i]); } } mockRepository.VerifyAll(); }