private bool SetStandardDeviationStochast(StandardDeviationDefinition definition) { return(ConfigurationImportHelper.TrySetStandardDeviationStochast( definition.StochastName, calculation.Name, calculation.InputParameters, definition.Configuration, definition.Getter, definition.Setter, Log)); }
/// <summary> /// Assigns the critical flow rate. /// </summary> /// <param name="calculationConfiguration">The calculation read from the imported file.</param> /// <param name="calculation">The calculation to configure.</param> /// <returns><c>true</c> if reading all required critical flow rate parameters was successful, /// <c>false</c> otherwise.</returns> private bool TrySetCriticalFlowRate(GrassCoverErosionInwardsCalculationConfiguration calculationConfiguration, GrassCoverErosionInwardsCalculation calculation) { return(ConfigurationImportHelper.TrySetStandardDeviationStochast( GrassCoverErosionInwardsCalculationConfigurationSchemaIdentifiers.CriticalFlowRateStochastName, calculation.Name, calculation.InputParameters, calculationConfiguration.CriticalFlowRate, i => i.CriticalFlowRate, (i, s) => i.CriticalFlowRate = s, Log)); }
private bool TrySetPhreaticLevelExit(PipingCalculationConfiguration calculationConfiguration, IPipingCalculationScenario <PipingInput> pipingCalculation) { return(ConfigurationImportHelper.TrySetStandardDeviationStochast( PipingCalculationConfigurationSchemaIdentifiers.PhreaticLevelExitStochastName, pipingCalculation.Name, pipingCalculation.InputParameters, calculationConfiguration.PhreaticLevelExit, i => i.PhreaticLevelExit, (i, s) => i.PhreaticLevelExit = s, Log)); }
public void TrySetStandardDeviationStochast_ValidStochastConfiguration_ReturnsTrueParametersSet(bool setMean, bool setStandardDeviation) { // Setup var mocks = new MockRepository(); var log = mocks.StrictMock <ILog>(); mocks.ReplayAll(); var configuration = new StochastConfiguration(); var input = new TestInputWithStochasts(); var random = new Random(21); double mean = random.NextDouble(); double standardDeviation = random.NextDouble(); if (setMean) { configuration.Mean = mean; } if (setStandardDeviation) { configuration.StandardDeviation = standardDeviation; } // Call bool valid = ConfigurationImportHelper.TrySetStandardDeviationStochast( "some stochast name", "some calculation name", input, configuration, i => i.Distribution, (i, s) => i.Distribution = s, log); // Assert Assert.IsTrue(valid); var defaultLogNormal = new LogNormalDistribution(); Assert.AreEqual( setMean ? mean : defaultLogNormal.Mean, input.Distribution.Mean, input.Distribution.Mean.GetAccuracy()); Assert.AreEqual( setStandardDeviation ? standardDeviation : defaultLogNormal.StandardDeviation, input.Distribution.StandardDeviation, input.Distribution.StandardDeviation.GetAccuracy()); mocks.VerifyAll(); }
public void TrySetStandardDeviationStochast_StochastConfigurationWithStandardDeviation_LogsErrorReturnsFalse() { // Setup const string stochastName = "some stochast name"; const string calculationName = "some calculation name"; const string expectedFormat = "{0} Berekening '{1}' is overgeslagen."; string expectedError = $"Indien voor parameter '{stochastName}' de spreiding wordt opgegeven, moet dit door middel van een standaardafwijking. " + $"Voor berekening '{calculationName}' is een variatiecoëfficiënt gevonden."; var mocks = new MockRepository(); var log = mocks.StrictMock <ILog>(); log.Expect(l => l.ErrorFormat(expectedFormat, expectedError, calculationName)); mocks.ReplayAll(); var configuration = new StochastConfiguration { VariationCoefficient = new Random(21).NextDouble() }; var input = new TestInputWithStochasts(); // Call bool valid = ConfigurationImportHelper.TrySetStandardDeviationStochast( stochastName, calculationName, input, configuration, i => i.Distribution, (i, s) => i.Distribution = s, log); // Assert Assert.IsFalse(valid); mocks.VerifyAll(); }