Exemple #1
0
        public void GetUniqueStochasticSoilProfiles_DistinctSoilProfiles_ReturnsExpectedSoilProfiles()
        {
            // Setup
            var mocks          = new MockRepository();
            var soilProfileOne = mocks.Stub <ISoilProfile>();
            var soilProfileTwo = mocks.Stub <ISoilProfile>();

            mocks.ReplayAll();

            var profileOne = new StochasticSoilProfile(0.5, soilProfileOne);
            var profileTwo = new StochasticSoilProfile(0.8, soilProfileTwo);

            StochasticSoilProfile[] stochasticSoilProfiles =
            {
                profileOne,
                profileTwo
            };

            // Call
            IEnumerable <StochasticSoilProfile> profilesToTransform =
                StochasticSoilProfileHelper.GetUniqueStochasticSoilProfiles(stochasticSoilProfiles,
                                                                            string.Empty);

            // Assert
            CollectionAssert.AreEqual(stochasticSoilProfiles, profilesToTransform);
            mocks.VerifyAll();
        }
Exemple #2
0
        public void GetUniqueStochasticSoilProfiles_SameSoilProfile_ReturnsExpectedSoilProfiles()
        {
            // Setup
            const string soilProfileName = "A profile name";
            const string soilModelName   = "A model name";

            var mocks   = new MockRepository();
            var profile = mocks.Stub <ISoilProfile>();

            profile.Stub(p => p.Name).Return(soilProfileName);
            mocks.ReplayAll();

            const double probabilityOne = 0.5;
            const double probabilityTwo = 0.1;
            var          profileOne     = new StochasticSoilProfile(probabilityOne, profile);
            var          profileTwo     = new StochasticSoilProfile(probabilityTwo, profile);

            StochasticSoilProfile[] stochasticSoilProfiles =
            {
                profileOne,
                profileTwo
            };

            IEnumerable <StochasticSoilProfile> profilesToTransform = null;

            // Call
            Action call = () => profilesToTransform =
                StochasticSoilProfileHelper.GetUniqueStochasticSoilProfiles(stochasticSoilProfiles,
                                                                            soilModelName);

            // Assert
            string expectedMessage = $"Ondergrondschematisatie '{soilProfileName}' is meerdere keren gevonden in ondergrondmodel '{soilModelName}'. " +
                                     "Kansen van voorkomen worden opgeteld.";

            TestHelper.AssertLogMessageWithLevelIsGenerated(call, Tuple.Create(expectedMessage, LogLevelConstant.Warn));

            Assert.IsNotNull(profilesToTransform);

            StochasticSoilProfile profileToTransform = profilesToTransform.Single();

            Assert.AreSame(profile, profileToTransform.SoilProfile);
            const double expectedProbability = probabilityOne + probabilityTwo;

            Assert.AreEqual(expectedProbability, profileToTransform.Probability, 1e-6);

            mocks.VerifyAll();
        }
        public void Transform_SoilProfileNull_ThrowsArgumentNullException()
        {
            // Setup
            var mocks       = new MockRepository();
            var soilProfile = mocks.Stub <ISoilProfile>();

            mocks.ReplayAll();

            StochasticSoilProfile stochasticSoilProfile = StochasticSoilProfileTestFactory.CreateStochasticSoilProfileWithValidProbability(soilProfile);

            // Call
            TestDelegate call = () => MacroStabilityInwardsStochasticSoilProfileTransformer.Transform(stochasticSoilProfile, null);

            // Assert
            var exception = Assert.Throws <ArgumentNullException>(call);

            Assert.AreEqual("soilProfile", exception.ParamName);
            mocks.VerifyAll();
        }
        public void Constructor_WithValidArguments_ExpectedValues()
        {
            // Setup
            var    random      = new Random(21);
            double probability = random.NextDouble();

            var mockRepository = new MockRepository();
            var soilProfile    = mockRepository.Stub <ISoilProfile>();

            mockRepository.ReplayAll();

            // Call
            var profile = new StochasticSoilProfile(probability, soilProfile);

            // Assert
            Assert.AreEqual(probability, profile.Probability);
            Assert.AreSame(soilProfile, profile.SoilProfile);

            mockRepository.VerifyAll();
        }
        /// <summary>
        /// Transforms the generic <paramref name="stochasticSoilProfile"/> into <see cref="PipingStochasticSoilProfile"/>.
        /// </summary>
        /// <param name="stochasticSoilProfile">The stochastic soil profile to use in the transformation.</param>
        /// <param name="soilProfile">The transformed piping soil profile.</param>
        /// <returns>A new <paramref name="soilProfile"/> based on the given data.</returns>
        /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception>
        /// <exception cref="ImportedDataTransformException">Thrown when <see cref="StochasticSoilProfile"/>
        /// could not be transformed.</exception>
        public static PipingStochasticSoilProfile Transform(StochasticSoilProfile stochasticSoilProfile, PipingSoilProfile soilProfile)
        {
            if (stochasticSoilProfile == null)
            {
                throw new ArgumentNullException(nameof(stochasticSoilProfile));
            }

            if (soilProfile == null)
            {
                throw new ArgumentNullException(nameof(soilProfile));
            }

            try
            {
                return(new PipingStochasticSoilProfile(stochasticSoilProfile.Probability, soilProfile));
            }
            catch (ArgumentOutOfRangeException e)
            {
                throw new ImportedDataTransformException(e.Message, e);
            }
        }
        /// <summary>
        /// Transforms the generic <paramref name="stochasticSoilProfile"/> into
        /// <see cref="MacroStabilityInwardsStochasticSoilProfile"/>.
        /// </summary>
        /// <param name="stochasticSoilProfile">The stochastic soil profile to use
        /// in the transformation.</param>
        /// <param name="soilProfile">The transformed soil profile.</param>
        /// <returns>A new <paramref name="soilProfile"/> based on the given data.</returns>
        /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception>
        /// <exception cref="ImportedDataTransformException">Thrown when <see cref="StochasticSoilProfile"/>
        /// could not be transformed.</exception>
        public static MacroStabilityInwardsStochasticSoilProfile Transform(StochasticSoilProfile stochasticSoilProfile,
                                                                           IMacroStabilityInwardsSoilProfile <IMacroStabilityInwardsSoilLayer> soilProfile)
        {
            if (stochasticSoilProfile == null)
            {
                throw new ArgumentNullException(nameof(stochasticSoilProfile));
            }

            if (soilProfile == null)
            {
                throw new ArgumentNullException(nameof(soilProfile));
            }

            try
            {
                return(new MacroStabilityInwardsStochasticSoilProfile(stochasticSoilProfile.Probability, soilProfile));
            }
            catch (ArgumentOutOfRangeException e)
            {
                throw new ImportedDataTransformException(e.Message, e);
            }
        }
        public void Transform_InvalidStochasticSoilProfile_ThrowsImportedDataTransformException()
        {
            // Setup
            var mocks       = new MockRepository();
            var soilProfile = mocks.Stub <ISoilProfile>();
            var macroStabilityInwardsSoilProfile = mocks.Stub <IMacroStabilityInwardsSoilProfile <IMacroStabilityInwardsSoilLayer> >();

            mocks.ReplayAll();

            var stochasticSoilProfile = new StochasticSoilProfile(double.NaN, soilProfile);

            // Call
            TestDelegate call = () => MacroStabilityInwardsStochasticSoilProfileTransformer.Transform(stochasticSoilProfile, macroStabilityInwardsSoilProfile);

            // Assert
            var exception = Assert.Throws <ImportedDataTransformException>(call);

            Exception innerException = exception.InnerException;

            Assert.IsInstanceOf <ArgumentException>(innerException);
            Assert.AreEqual(innerException.Message, exception.Message);
        }
        public void Transform_ValidData_ReturnExpectedMacroStabilityInwardsStochasticSoilProfile()
        {
            // Setup
            var random = new Random(21);

            var mocks       = new MockRepository();
            var soilProfile = mocks.Stub <ISoilProfile>();
            var macroStabilityInwardsSoilProfile = mocks.Stub <IMacroStabilityInwardsSoilProfile <IMacroStabilityInwardsSoilLayer> >();

            mocks.ReplayAll();

            var stochasticSoilProfile = new StochasticSoilProfile(random.NextDouble(), soilProfile);

            // Call
            MacroStabilityInwardsStochasticSoilProfile macroStabilityInwardsStochasticSoilProfile
                = MacroStabilityInwardsStochasticSoilProfileTransformer.Transform(stochasticSoilProfile, macroStabilityInwardsSoilProfile);

            // Assert
            Assert.AreEqual(stochasticSoilProfile.Probability, macroStabilityInwardsStochasticSoilProfile.Probability);
            Assert.AreSame(macroStabilityInwardsSoilProfile, macroStabilityInwardsStochasticSoilProfile.SoilProfile);
            mocks.VerifyAll();
        }
        public void Transform_ValidStochasticSoilProfile_ReturnsExpectedPipingStochasticSoilProfile()
        {
            // Setup
            var random = new Random(21);

            var mockRepository = new MockRepository();
            var soilProfile    = mockRepository.Stub <ISoilProfile>();

            mockRepository.ReplayAll();

            PipingSoilProfile pipingSoilProfile = PipingSoilProfileTestFactory.CreatePipingSoilProfile();

            var stochasticSoilProfile = new StochasticSoilProfile(random.NextDouble(), soilProfile);

            // Call
            PipingStochasticSoilProfile pipingStochasticSoilProfile = PipingStochasticSoilProfileTransformer.Transform(stochasticSoilProfile, pipingSoilProfile);

            // Assert
            Assert.AreEqual(stochasticSoilProfile.Probability, pipingStochasticSoilProfile.Probability);
            Assert.AreSame(pipingSoilProfile, pipingStochasticSoilProfile.SoilProfile);
            mockRepository.VerifyAll();
        }
        public void Transform_ValidStochasticSoilModelWithSimilarProfileInTwoStochasticSoilProfiles_ReturnsExpectedPipingStochasticSoilModel()
        {
            // Setup
            var random = new Random(21);

            const string soilProfileName = "SoilProfile";
            const double intersectionX   = 1.0;

            var soilProfile2D = new SoilProfile2D(0, soilProfileName, new[]
            {
                SoilLayer2DTestFactory.CreateSoilLayer2D()
            }, Enumerable.Empty <PreconsolidationStress>())
            {
                IntersectionX = intersectionX
            };
            var stochasticSoilProfile2D = new StochasticSoilProfile(random.NextDouble(), soilProfile2D);

            var soilProfile1D = new SoilProfile1D(0, soilProfileName, 0, new[]
            {
                SoilLayer1DTestFactory.CreateSoilLayer1DWithValidAquifer()
            });
            var stochasticSoilProfile1D = new StochasticSoilProfile(random.NextDouble(), soilProfile1D);

            var transformer = new PipingStochasticSoilModelTransformer();
            StochasticSoilModel soilModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModelWithGeometry(new[]
            {
                stochasticSoilProfile2D,
                stochasticSoilProfile1D
            });

            // Call
            PipingStochasticSoilModel transformed = transformer.Transform(soilModel);

            // Assert
            PipingStochasticSoilProfile[] transformedStochasticSoilProfiles = transformed.StochasticSoilProfiles.ToArray();
            Assert.AreEqual(2, transformedStochasticSoilProfiles.Length);
            Assert.AreEqual(stochasticSoilProfile2D.Probability, transformedStochasticSoilProfiles[0].Probability, 1e-6);
            Assert.AreEqual(stochasticSoilProfile1D.Probability, transformedStochasticSoilProfiles[1].Probability, 1e-6);
        }
        public void Transform_ValidStochasticSoilModelWithStochasticProfileInvalidProbability_ThrowsImportedDataException(StochasticSoilProfile profile)
        {
            // Setup
            StochasticSoilModel soilModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModelWithGeometry(new[]
            {
                profile
            });

            var transformer = new PipingStochasticSoilModelTransformer();

            // Call
            TestDelegate call = () => transformer.Transform(soilModel);

            // Assert
            var          exception       = Assert.Throws <ImportedDataTransformException>(call);
            const string expectedMessage = "Het aandeel van de ondergrondschematisatie in het stochastische ondergrondmodel " +
                                           "moet in het bereik [0,0, 1,0] liggen.";

            StringAssert.StartsWith(expectedMessage, exception.Message);
        }