public void GetDesignValue_ValidLogNormalDistributionWithNonZeroShift_ReturnExpectedValue(
            double expectedValue, double variance, double shift, double percentile,
            double expectedResult)
        {
            // Setup
            const int numberOfDecimalPlaces = 4;
            var       logNormalDistribution = new VariationCoefficientLogNormalDistribution(numberOfDecimalPlaces)
            {
                Mean = (RoundedDouble)expectedValue,
                CoefficientOfVariation = (RoundedDouble)Math.Sqrt(variance),
                Shift = (RoundedDouble)shift
            };

            var designVariable = new VariationCoefficientLogNormalDistributionDesignVariable(logNormalDistribution)
            {
                Percentile = percentile
            };

            // Call
            RoundedDouble result = designVariable.GetDesignValue();

            // Assert
            Assert.AreEqual(numberOfDecimalPlaces, result.NumberOfDecimalPlaces);
            Assert.AreEqual(expectedResult, result, result.GetAccuracy());
        }
Exemplo n.º 2
0
 private static void AssertAreEqual(RoundedDouble expectedDouble, double?actualDouble)
 {
     if (double.IsNaN(expectedDouble))
     {
         Assert.IsNull(actualDouble);
     }
     else
     {
         Assert.AreEqual(expectedDouble, actualDouble, expectedDouble.GetAccuracy());
     }
 }
        public void GetSelectableHydraulicBoundaryLocations_InputWithLocationsStructure_CalculatesDistanceWithCorrectReferencePoint()
        {
            // Setup
            var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "A", 200643.312, 503347.25);

            assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(new HydraulicBoundaryDatabase
            {
                Locations =
                {
                    hydraulicBoundaryLocation
                }
            });

            mockRepository.ReplayAll();

            var calculation = new StructuresCalculation <SimpleStructureInput>
            {
                InputParameters =
                {
                    Structure = new TestStructure(new Point2D(200620.173572981, 503401.652985217))
                }
            };
            var inputContext = new SimpleInputContext(calculation.InputParameters,
                                                      calculation,
                                                      failureMechanism,
                                                      assessmentSection);

            var properties = new SimpleStructuresInputProperties(
                inputContext,
                new StructuresInputBaseProperties <TestStructure, SimpleStructureInput, StructuresCalculation <SimpleStructureInput>, IFailureMechanism> .ConstructionProperties(),
                handler);

            // Call
            IEnumerable <SelectableHydraulicBoundaryLocation> availableHydraulicBoundaryLocations =
                properties.GetSelectableHydraulicBoundaryLocations();

            // Assert
            double distanceToPropertiesStructureLocation =
                hydraulicBoundaryLocation.Location.GetEuclideanDistanceTo(properties.StructureLocation);
            double distanceToInputStructureLocation =
                hydraulicBoundaryLocation.Location.GetEuclideanDistanceTo(calculation.InputParameters.Structure.Location);

            Assert.AreEqual(59, distanceToPropertiesStructureLocation, 1);
            Assert.AreEqual(60, distanceToInputStructureLocation, 1);

            SelectableHydraulicBoundaryLocation hydraulicBoundaryLocationItem = availableHydraulicBoundaryLocations.ToArray()[0];
            RoundedDouble itemDistance = hydraulicBoundaryLocationItem.Distance;

            Assert.AreEqual(distanceToInputStructureLocation, itemDistance, itemDistance.GetAccuracy());

            mockRepository.VerifyAll();
        }
Exemplo n.º 4
0
        public void ToMacroStabilityInwardsLocationInputExtremeConfiguration_ValidMacroStabilityInwardsLocationInputExtreme_ReturnsNewMacroStabilityInwardsLocationInputExtremeConfigurationWithParametersSet()
        {
            // Setup
            var random = new Random(31);

            RoundedDouble penetrationLength = random.NextRoundedDouble();
            bool          useDefaultOffsets = random.NextBoolean();
            RoundedDouble waterLevelPolder  = random.NextRoundedDouble();
            RoundedDouble phreaticLineOffsetBelowDikeTopAtRiver     = random.NextRoundedDouble();
            RoundedDouble phreaticLineOffsetBelowDikeTopAtPolder    = random.NextRoundedDouble();
            RoundedDouble phreaticLineOffsetBelowShoulderBaseInside = random.NextRoundedDouble();
            RoundedDouble phreaticLineOffsetBelowDikeToeAtPolder    = random.NextRoundedDouble();

            var mockRepository = new MockRepository();
            var inputExtreme   = mockRepository.Stub <IMacroStabilityInwardsLocationInputExtreme>();

            inputExtreme.PenetrationLength = penetrationLength;
            inputExtreme.UseDefaultOffsets = useDefaultOffsets;
            inputExtreme.WaterLevelPolder  = waterLevelPolder;
            inputExtreme.PhreaticLineOffsetBelowDikeTopAtRiver     = phreaticLineOffsetBelowDikeTopAtRiver;
            inputExtreme.PhreaticLineOffsetBelowDikeTopAtPolder    = phreaticLineOffsetBelowDikeTopAtPolder;
            inputExtreme.PhreaticLineOffsetBelowShoulderBaseInside = phreaticLineOffsetBelowShoulderBaseInside;
            inputExtreme.PhreaticLineOffsetBelowDikeToeAtPolder    = phreaticLineOffsetBelowDikeToeAtPolder;
            mockRepository.ReplayAll();

            // Call
            MacroStabilityInwardsLocationInputExtremeConfiguration configuration = inputExtreme.ToMacroStabilityInwardsLocationInputExtremeConfiguration();

            // Assert
            Assert.AreEqual(penetrationLength,
                            configuration.PenetrationLength,
                            penetrationLength.GetAccuracy());
            Assert.AreEqual(useDefaultOffsets, configuration.UseDefaultOffsets);
            Assert.AreEqual(phreaticLineOffsetBelowDikeTopAtRiver,
                            configuration.PhreaticLineOffsetBelowDikeTopAtRiver,
                            phreaticLineOffsetBelowDikeTopAtRiver.GetAccuracy());
            Assert.AreEqual(phreaticLineOffsetBelowDikeTopAtPolder,
                            configuration.PhreaticLineOffsetBelowDikeTopAtPolder,
                            phreaticLineOffsetBelowDikeTopAtPolder.GetAccuracy());
            Assert.AreEqual(phreaticLineOffsetBelowShoulderBaseInside,
                            configuration.PhreaticLineOffsetBelowShoulderBaseInside,
                            phreaticLineOffsetBelowShoulderBaseInside.GetAccuracy());
            Assert.AreEqual(phreaticLineOffsetBelowDikeToeAtPolder,
                            configuration.PhreaticLineOffsetBelowDikeToeAtPolder,
                            phreaticLineOffsetBelowDikeToeAtPolder.GetAccuracy());
            mockRepository.VerifyAll();
        }
        public void GetDesignValue_Always_ReturnsDeterministicValueWithNumberOfDecimalsFromDistributionMean()
        {
            // Setup
            double    testValue             = new Random(21).NextDouble();
            const int numberOfDecimalPlaces = 2;

            var mocks        = new MockRepository();
            var distribution = mocks.Stub <IVariationCoefficientDistribution>();

            distribution.Mean = new RoundedDouble(numberOfDecimalPlaces);
            mocks.ReplayAll();

            var designVariable = new VariationCoefficientDeterministicDesignVariable <IVariationCoefficientDistribution>(distribution, testValue);

            // Call
            RoundedDouble designValue = designVariable.GetDesignValue();

            // Assert
            Assert.AreEqual(testValue, designValue.Value, designValue.GetAccuracy());
            Assert.AreEqual(numberOfDecimalPlaces, designValue.NumberOfDecimalPlaces);
            mocks.VerifyAll();
        }
Exemplo n.º 6
0
        public void GetDesignValue_ValidLogNormalDistribution_ReturnExpectedValue(
            double expectedValue, double variance, double percentile,
            double expectedResult)
        {
            // Setup
            const int numberOfDecimalPlaces = 4;
            var       logNormalDistribution = new LogNormalDistribution(numberOfDecimalPlaces)
            {
                Mean = (RoundedDouble)expectedValue,
                StandardDeviation = (RoundedDouble)Math.Sqrt(variance)
            };

            var designVariable = new LogNormalDistributionDesignVariable(logNormalDistribution)
            {
                Percentile = percentile
            };

            // Call
            RoundedDouble result = designVariable.GetDesignValue();

            // Assert
            Assert.AreEqual(numberOfDecimalPlaces, result.NumberOfDecimalPlaces);
            Assert.AreEqual(expectedResult, result, result.GetAccuracy());
        }
 private static void AssertAreEqual(double expectedValue, RoundedDouble actualValue)
 {
     Assert.AreEqual(expectedValue, actualValue, actualValue.GetAccuracy());
 }
        public void SelectedHydraulicBoundaryLocation_InputWithLocationsStructure_CalculatesDistanceWithCorrectReferencePoint()
        {
            // Setup
            mockRepository.ReplayAll();

            var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "A", 200643.312, 503347.25);
            var calculation = new StructuresCalculation <SimpleStructureInput>
            {
                InputParameters =
                {
                    HydraulicBoundaryLocation = hydraulicBoundaryLocation,
                    Structure                 = new TestStructure(new Point2D(200620.173572981, 503401.652985217))
                }
            };
            var inputContext = new SimpleInputContext(calculation.InputParameters,
                                                      calculation,
                                                      failureMechanism,
                                                      assessmentSection);

            var properties = new SimpleStructuresInputProperties(
                inputContext,
                new StructuresInputBaseProperties <TestStructure, SimpleStructureInput, StructuresCalculation <SimpleStructureInput>, IFailureMechanism> .ConstructionProperties(),
                handler);

            // Call
            SelectableHydraulicBoundaryLocation selectedHydraulicBoundaryLocation = properties.SelectedHydraulicBoundaryLocation;

            // Assert
            double distanceToPropertiesStructureLocation =
                hydraulicBoundaryLocation.Location.GetEuclideanDistanceTo(properties.StructureLocation);
            double distanceToInputStructureLocation =
                hydraulicBoundaryLocation.Location.GetEuclideanDistanceTo(calculation.InputParameters.Structure.Location);

            Assert.AreEqual(59, distanceToPropertiesStructureLocation, 1);
            Assert.AreEqual(60, distanceToInputStructureLocation, 1);

            RoundedDouble selectedLocationDistance = selectedHydraulicBoundaryLocation.Distance;

            Assert.AreEqual(distanceToInputStructureLocation, selectedLocationDistance, selectedLocationDistance.GetAccuracy());

            mockRepository.VerifyAll();
        }
Exemplo n.º 9
0
 /// <summary>
 /// Asserts whether <paramref name="expectedValue"/> matches <paramref name="actualValue"/>.
 /// </summary>
 /// <param name="expectedValue">The expected <c>double</c> value.</param>
 /// <param name="actualValue">The actual <see cref="RoundedDouble"/> instance.</param>
 /// <exception cref="AssertionException">Thrown when <paramref name="expectedValue"/> doesn't match
 /// <paramref name="actualValue"/>.</exception>
 public static void AssertRoundedDouble(double?expectedValue, RoundedDouble actualValue)
 {
     Assert.IsTrue(expectedValue.HasValue);
     Assert.AreEqual(expectedValue.Value, actualValue, actualValue.GetAccuracy());
 }
Exemplo n.º 10
0
        public void CreateFailureMechanismSectionFeatures_GivenSections_ReturnsSectionFeaturesCollection()
        {
            // Setup
            const string sectionName1 = "section 1";
            const string sectionName2 = "section 2";

            var pointsOne = new[]
            {
                new Point2D(1.2, 2.3),
                new Point2D(2.7, 2.0)
            };
            var pointsTwo = new[]
            {
                new Point2D(3.2, 23.3),
                new Point2D(7.7, 12.6)
            };

            var sections = new[]
            {
                new FailureMechanismSection(sectionName1, pointsOne),
                new FailureMechanismSection(sectionName2, pointsTwo)
            };

            // Call
            IEnumerable <MapFeature> features = RiskeerMapDataFeaturesFactory.CreateFailureMechanismSectionFeatures(sections);

            // Assert
            Assert.AreEqual(2, features.Count());
            for (var i = 0; i < features.Count(); i++)
            {
                Assert.AreEqual(1, features.ElementAt(i).MapGeometries.Count());
                Assert.AreEqual(2, features.ElementAt(i).MetaData.Keys.Count);

                Assert.AreEqual(sections[i].Name, features.ElementAt(i).MetaData["Naam"]);
                var expectedLength = new RoundedDouble(2, Math2D.Length(sections[i].Points));
                Assert.AreEqual(expectedLength, (RoundedDouble)features.ElementAt(i).MetaData["Lengte*"], expectedLength.GetAccuracy());

                AssertEqualPointCollections(sections[i].Points, features.ElementAt(i).MapGeometries.First());
            }
        }
Exemplo n.º 11
0
        public void CreateReferenceLineFeatures_GivenReferenceLine_ReturnsReferenceLineFeature()
        {
            // Setup
            const string id   = "1";
            const string name = "Traject 1";

            var points = new[]
            {
                new Point2D(1.2, 2.3),
                new Point2D(2.7, 2.0)
            };
            var referenceLine = new ReferenceLine();

            referenceLine.SetGeometry(points);

            // Call
            IEnumerable <MapFeature> features = RiskeerMapDataFeaturesFactory.CreateReferenceLineFeatures(referenceLine, id, name);

            // Assert
            MapFeature mapFeature = features.Single();

            Assert.AreEqual(3, mapFeature.MetaData.Keys.Count);
            Assert.AreEqual(id, mapFeature.MetaData["ID"]);
            Assert.AreEqual(name, mapFeature.MetaData["Naam"]);

            var expectedLength = new RoundedDouble(2, Math2D.Length(points));

            Assert.AreEqual(expectedLength, (RoundedDouble)mapFeature.MetaData["Lengte*"], expectedLength.GetAccuracy());
            AssertEqualPointCollections(points, mapFeature.MapGeometries.ElementAt(0));
        }
 private static void AssertAreEqual(double expected, RoundedDouble actual)
 {
     Assert.AreEqual(expected, actual, actual.GetAccuracy());
 }