Exemple #1
0
        public void Assign_SpecificInvalid_ReturnsFalse()
        {
            // Setup
            const string calculationName = "name";
            var          mocks           = new MockRepository();
            var          configuration   = mocks.Stub <StructuresCalculationConfiguration>(calculationName);

            mocks.ReplayAll();

            var calculation = new StructuresCalculation <SimpleStructuresInput>();

            var assigner = new SimpleStructuresCalculationStochastAssigner(
                configuration,
                calculation)
            {
                SpecificIsValid = false
            };

            // Call
            bool valid = assigner.Assign();

            // Assert
            Assert.IsFalse(valid);
            mocks.VerifyAll();
        }
Exemple #2
0
        public void Assign_SpreadDefinedForBaseStochast_LogsErrorAndReturnsFalse(Action <StructuresCalculationConfiguration> modify, string stochastName)
        {
            // Setup
            const string calculationName = "name";
            var          mocks           = new MockRepository();
            var          configuration   = mocks.Stub <StructuresCalculationConfiguration>(calculationName);

            mocks.ReplayAll();

            var calculation = new StructuresCalculation <SimpleStructuresInput>();

            modify(configuration);

            var assigner = new SimpleStructuresCalculationStochastAssigner(
                configuration,
                calculation);

            // Call
            var    valid    = true;
            Action validate = () => valid = assigner.Assign();

            // Assert
            string expectedMessage = $"Er kan geen spreiding voor stochast '{stochastName}' opgegeven worden. Berekening '{calculationName}' is overgeslagen.";

            TestHelper.AssertLogMessageWithLevelIsGenerated(validate, Tuple.Create(expectedMessage, LogLevelConstant.Error));
            Assert.IsFalse(valid);
            mocks.VerifyAll();
        }
Exemple #3
0
        public void Assign_WithoutStructureStochastDefinedWithParamter_LogsErrorReturnsFalse(
            Action <StochastConfiguration> modifyStandardDeviationStochast,
            Action <StochastConfiguration> modifyVariationCoefficientStochast,
            string stochastName)
        {
            // Setup
            const string calculationName = "name";
            var          mocks           = new MockRepository();
            var          configuration   = mocks.Stub <StructuresCalculationConfiguration>(calculationName);

            mocks.ReplayAll();

            var calculation = new StructuresCalculation <SimpleStructuresInput>();
            var standardDeviationStochastConfiguration    = new StochastConfiguration();
            var variationCoefficientStochastConfiguration = new StochastConfiguration();

            modifyStandardDeviationStochast(standardDeviationStochastConfiguration);
            modifyVariationCoefficientStochast(variationCoefficientStochastConfiguration);

            var assigner = new SimpleStructuresCalculationStochastAssigner(
                configuration,
                calculation)
            {
                StandardDeviationStochasts = new[]
                {
                    new StructuresCalculationStochastAssigner <StructuresCalculationConfiguration, SimpleStructuresInput, StructureBase> .StandardDeviationDefinition(stochastName,
                                                                                                                                                                      standardDeviationStochastConfiguration,
                                                                                                                                                                      input => null,
                                                                                                                                                                      (input, distribution) => {})
                },
                VariationCoefficientStochasts = new[]
                {
                    new StructuresCalculationStochastAssigner <StructuresCalculationConfiguration, SimpleStructuresInput, StructureBase> .VariationCoefficientDefinition(stochastName,
                                                                                                                                                                         variationCoefficientStochastConfiguration,
                                                                                                                                                                         input => null,
                                                                                                                                                                         (input, distribution) => {})
                }
            };

            // Call
            var    valid    = true;
            Action validate = () => valid = assigner.Assign();

            // Assert
            string expectedMessage = $"Er is geen kunstwerk opgegeven om de stochast '{stochastName}' aan toe te voegen. Berekening '{calculationName}' is overgeslagen.";

            TestHelper.AssertLogMessageWithLevelIsGenerated(validate, Tuple.Create(expectedMessage, LogLevelConstant.Error));
            Assert.IsFalse(valid);
            mocks.VerifyAll();
        }
Exemple #4
0
        public void Assign_WithStructure_ReturnsTrue(
            Action <StochastConfiguration> modifyStandardDeviationStochast,
            Action <StochastConfiguration> modifyVariationCoefficientStochast,
            string stochastName)
        {
            // Setup
            const string calculationName = "name";
            var          mocks           = new MockRepository();
            var          configuration   = mocks.Stub <StructuresCalculationConfiguration>(calculationName);

            mocks.ReplayAll();

            configuration.StructureId = "some ID";

            var calculation = new StructuresCalculation <SimpleStructuresInput>();

            var standardDeviationStochastConfiguration    = new StochastConfiguration();
            var variationCoefficientStochastConfiguration = new StochastConfiguration();

            modifyStandardDeviationStochast(standardDeviationStochastConfiguration);
            modifyVariationCoefficientStochast(variationCoefficientStochastConfiguration);

            var assigner = new SimpleStructuresCalculationStochastAssigner(
                configuration,
                calculation)
            {
                StandardDeviationStochasts = new[]
                {
                    new StructuresCalculationStochastAssigner <StructuresCalculationConfiguration, SimpleStructuresInput, StructureBase> .StandardDeviationDefinition(stochastName,
                                                                                                                                                                      standardDeviationStochastConfiguration,
                                                                                                                                                                      input => new LogNormalDistribution(),
                                                                                                                                                                      (input, distribution) => {})
                },
                VariationCoefficientStochasts = new[]
                {
                    new StructuresCalculationStochastAssigner <StructuresCalculationConfiguration, SimpleStructuresInput, StructureBase> .VariationCoefficientDefinition(stochastName,
                                                                                                                                                                         variationCoefficientStochastConfiguration,
                                                                                                                                                                         input => new VariationCoefficientLogNormalDistribution(),
                                                                                                                                                                         (input, distribution) => {})
                }
            };

            // Call
            bool valid = assigner.Assign();

            // Assert
            Assert.IsTrue(valid);
            mocks.VerifyAll();
        }
Exemple #5
0
        public void Constructor_WithParameters_ReturnsNewInstance()
        {
            // Setup
            var mocks         = new MockRepository();
            var configuration = mocks.Stub <StructuresCalculationConfiguration>("name");

            mocks.ReplayAll();

            var calculation = new StructuresCalculation <SimpleStructuresInput>();

            // Call
            var assigner = new SimpleStructuresCalculationStochastAssigner(
                configuration,
                calculation);

            // Assert
            Assert.NotNull(assigner);
            mocks.VerifyAll();
        }
Exemple #6
0
        public void ValidateSpecificStochasts_Always_ReturnsTrue()
        {
            // Setup
            var mocks         = new MockRepository();
            var configuration = mocks.Stub <StructuresCalculationConfiguration>("name");

            mocks.ReplayAll();

            var calculation = new StructuresCalculation <SimpleStructuresInput>();

            var assigner = new SimpleStructuresCalculationStochastAssigner(
                configuration,
                calculation);

            // Call
            bool valid = assigner.PublicValidateSpecificStochasts();

            // Assert
            Assert.IsTrue(valid);
            mocks.VerifyAll();
        }
Exemple #7
0
        public void SetAllStochasts_Always_CallsGettersAndSetters(
            bool setStandardDeviationStochastSuccessful,
            bool setVariationCoefficientStochastSuccessful)
        {
            // Setup
            const string calculationName = "name";
            var          mocks           = new MockRepository();
            var          configuration   = mocks.Stub <StructuresCalculationConfiguration>(calculationName);

            mocks.ReplayAll();

            configuration.StructureId = "some ID";

            var    random = new Random(21);
            double allowedLevelIncreaseStorageMean = setStandardDeviationStochastSuccessful ? random.NextDouble() : -1;
            double allowedLevelIncreaseStorageStandardDeviation       = random.NextDouble();
            double criticalOvertoppingDischargeMean                   = setVariationCoefficientStochastSuccessful ? random.NextDouble() : -1;
            double criticalOvertoppingDischargeCoefficientOfVariation = random.NextDouble();

            var calculation = new StructuresCalculation <SimpleStructuresInput>();

            var standardDeviationStochastConfiguration = new StochastConfiguration
            {
                Mean = allowedLevelIncreaseStorageMean,
                StandardDeviation = allowedLevelIncreaseStorageStandardDeviation
            };
            var variationCoefficientStochastConfiguration = new StochastConfiguration
            {
                Mean = criticalOvertoppingDischargeMean,
                VariationCoefficient = criticalOvertoppingDischargeCoefficientOfVariation
            };

            var definitionA =
                new StructuresCalculationStochastAssigner <StructuresCalculationConfiguration, SimpleStructuresInput, StructureBase> .StandardDeviationDefinition("stochastA",
                                                                                                                                                                  standardDeviationStochastConfiguration,
                                                                                                                                                                  input => input.AllowedLevelIncreaseStorage,
                                                                                                                                                                  (input, distribution) =>
            {
                input.AllowedLevelIncreaseStorage = (LogNormalDistribution)distribution;
            });

            var definitionB =
                new StructuresCalculationStochastAssigner <StructuresCalculationConfiguration, SimpleStructuresInput, StructureBase> .VariationCoefficientDefinition("stochastB",
                                                                                                                                                                     variationCoefficientStochastConfiguration,
                                                                                                                                                                     input => input.CriticalOvertoppingDischarge,
                                                                                                                                                                     (input, distribution) =>
            {
                input.CriticalOvertoppingDischarge = (VariationCoefficientLogNormalDistribution)distribution;
            });

            var assigner = new SimpleStructuresCalculationStochastAssigner(
                configuration,
                calculation)
            {
                StandardDeviationStochasts = new[]
                {
                    definitionA
                },
                VariationCoefficientStochasts = new[]
                {
                    definitionB
                }
            };

            // Call
            bool valid = assigner.Assign();

            // Assert
            Assert.AreEqual(setStandardDeviationStochastSuccessful && setVariationCoefficientStochastSuccessful, valid);
            if (valid)
            {
                Assert.AreEqual(allowedLevelIncreaseStorageMean,
                                calculation.InputParameters.AllowedLevelIncreaseStorage.Mean,
                                calculation.InputParameters.AllowedLevelIncreaseStorage.Mean.GetAccuracy());
                Assert.AreEqual(allowedLevelIncreaseStorageStandardDeviation,
                                calculation.InputParameters.AllowedLevelIncreaseStorage.StandardDeviation,
                                calculation.InputParameters.AllowedLevelIncreaseStorage.StandardDeviation.GetAccuracy());
                Assert.AreEqual(criticalOvertoppingDischargeMean,
                                calculation.InputParameters.CriticalOvertoppingDischarge.Mean,
                                calculation.InputParameters.CriticalOvertoppingDischarge.Mean.GetAccuracy());
                Assert.AreEqual(criticalOvertoppingDischargeCoefficientOfVariation,
                                calculation.InputParameters.CriticalOvertoppingDischarge.CoefficientOfVariation,
                                calculation.InputParameters.CriticalOvertoppingDischarge.CoefficientOfVariation.GetAccuracy());
            }

            mocks.VerifyAll();
        }