/// <summary>
 /// Creates a new instance of <see cref="SubMechanismIllustrationPointProperties"/>.
 /// </summary>
 /// <param name="illustrationPoint">The sub mechanism illustration point to use for the properties.</param>
 /// <param name="windDirection">The wind direction of the illustration point.</param>
 /// <param name="closingSituation">The closing situation of the illustration point.</param>
 /// <exception cref="ArgumentNullException">Thrown when any input parameter is <c>null</c>.</exception>
 public SubMechanismIllustrationPointProperties(SubMechanismIllustrationPoint illustrationPoint,
                                                string windDirection,
                                                string closingSituation)
     : base(illustrationPoint, windDirection, closingSituation)
 {
     subMechanismIllustrationPoint = illustrationPoint;
 }
        private IllustrationPointTreeNode BuildSubMechanism(Tuple <int, WindDirection, int, string> windDirectionClosingSituation, int subMechanismId)
        {
            var dataKey = new ThreeKeyIndex(windDirectionClosingSituation.Item1, windDirectionClosingSituation.Item3, subMechanismId);

            var illustrationPointStochasts = new List <SubMechanismIllustrationPointStochast>();
            var illustrationPointResults   = new List <IllustrationPointResult>();

            if (!subMechanismBetaValues.ContainsKey(dataKey))
            {
                return(null);
            }

            double subMechanismIllustrationPointBeta = subMechanismBetaValues[dataKey];

            if (subMechanismStochasts.ContainsKey(dataKey))
            {
                AddRange(illustrationPointStochasts, subMechanismStochasts[dataKey]);
            }

            if (subMechanismResults.ContainsKey(dataKey))
            {
                AddRange(illustrationPointResults, subMechanismResults[dataKey]);
            }

            string subMechanismIllustrationPointName = subMechanisms[subMechanismId];
            var    illustrationPoint = new SubMechanismIllustrationPoint(subMechanismIllustrationPointName,
                                                                         illustrationPointStochasts,
                                                                         illustrationPointResults,
                                                                         subMechanismIllustrationPointBeta);

            return(new IllustrationPointTreeNode(illustrationPoint));
        }
        public void Constructor_ValidData_ExpectedValues()
        {
            // Setup
            var random = new Random(15);

            const string windDirection     = "N";
            const string closingSituation  = "closing situation";
            var          illustrationPoint = new SubMechanismIllustrationPoint("NNE",
                                                                               random.NextDouble(),
                                                                               Enumerable.Empty <SubMechanismIllustrationPointStochast>(),
                                                                               Enumerable.Empty <IllustrationPointResult>());

            // Call
            var properties = new IllustrationPointProperties(illustrationPoint, windDirection, closingSituation);

            // Assert
            Assert.AreEqual(windDirection, properties.WindDirection);

            TestHelper.AssertTypeConverter <IllustrationPointProperties, NoValueRoundedDoubleConverter>(
                nameof(IllustrationPointProperties.Reliability));
            Assert.AreEqual(illustrationPoint.Beta, properties.Reliability, properties.Reliability.GetAccuracy());

            TestHelper.AssertTypeConverter <IllustrationPointProperties, NoProbabilityValueDoubleConverter>(
                nameof(IllustrationPointProperties.CalculatedProbability));
            Assert.AreEqual(StatisticsConverter.ReliabilityToProbability(illustrationPoint.Beta), properties.CalculatedProbability);
            Assert.AreEqual(closingSituation, properties.ClosingSituation);
        }
        protected override IEnumerable <IllustrationPointControlItem> GetIllustrationPointControlItems()
        {
            DataGridViewRow currentRow = dataGridViewControl.CurrentRow;

            if (currentRow == null)
            {
                return(Enumerable.Empty <IllustrationPointControlItem>());
            }

            HydraulicBoundaryLocationCalculation hydraulicBoundaryLocationCalculation = ((HydraulicBoundaryLocationCalculationRow)currentRow.DataBoundItem).CalculatableObject;

            HydraulicBoundaryLocationCalculationOutput hydraulicBoundaryLocationCalculationOutput = hydraulicBoundaryLocationCalculation.Output;

            if (hydraulicBoundaryLocationCalculation.HasOutput &&
                hydraulicBoundaryLocationCalculationOutput.HasGeneralResult)
            {
                return(hydraulicBoundaryLocationCalculationOutput.GeneralResult.TopLevelIllustrationPoints.Select(
                           topLevelSubMechanismIllustrationPoint =>
                {
                    SubMechanismIllustrationPoint subMechanismIllustrationPoint =
                        topLevelSubMechanismIllustrationPoint.SubMechanismIllustrationPoint;
                    return new IllustrationPointControlItem(topLevelSubMechanismIllustrationPoint,
                                                            topLevelSubMechanismIllustrationPoint.WindDirection.Name,
                                                            topLevelSubMechanismIllustrationPoint.ClosingSituation,
                                                            subMechanismIllustrationPoint.Stochasts,
                                                            subMechanismIllustrationPoint.Beta);
                }).ToArray());
            }

            return(Enumerable.Empty <IllustrationPointControlItem>());
        }
        public void GetProperties_WithValidData_ReturnsExpectedValues()
        {
            // Setup
            var random    = new Random(21);
            var stochasts = new[]
            {
                new SubMechanismIllustrationPointStochast("some name", "-", random.NextDouble(), random.NextDouble(), random.NextDouble())
            };
            var illustrationPointResults = new[]
            {
                new IllustrationPointResult("some description", "-", random.NextDouble())
            };

            var illustrationPoint = new SubMechanismIllustrationPoint("name",
                                                                      random.NextDouble(),
                                                                      stochasts,
                                                                      illustrationPointResults);

            // Call
            var properties = new SubMechanismIllustrationPointValuesProperties(illustrationPoint);

            // Assert
            CollectionAssert.AreEqual(illustrationPoint.Stochasts, properties.Realizations);
            CollectionAssert.AreEqual(illustrationPoint.IllustrationPointResults, properties.Results);
        }
        public void Create_ValidTopLevelSubMechanismIllustrationPoint_ReturnsEntityWithSubMechanismIllustrationPointEntity()
        {
            // Setup
            var random            = new Random(21);
            var illustrationPoint = new SubMechanismIllustrationPoint("Illustration point name",
                                                                      random.NextDouble(),
                                                                      Enumerable.Empty <SubMechanismIllustrationPointStochast>(),
                                                                      Enumerable.Empty <IllustrationPointResult>());

            var windDirection = new WindDirection("WindDirection Name", random.NextDouble());
            var topLevelSubMechanismIllustrationPoint = new TopLevelSubMechanismIllustrationPoint(windDirection,
                                                                                                  "Just a situation",
                                                                                                  illustrationPoint);
            int order = random.Next();

            // Call
            TopLevelSubMechanismIllustrationPointEntity entity =
                topLevelSubMechanismIllustrationPoint.Create(order);

            // Assert
            TestHelper.AssertAreEqualButNotSame(topLevelSubMechanismIllustrationPoint.ClosingSituation, entity.ClosingSituation);
            Assert.AreEqual(order, entity.Order);

            TestHelper.AssertAreEqualButNotSame(windDirection.Name, entity.WindDirectionName);
            Assert.AreEqual(windDirection.Angle, entity.WindDirectionAngle, windDirection.Angle.GetAccuracy());

            SubMechanismIllustrationPointEntity subMechanismIllustrationPointEntity = entity.SubMechanismIllustrationPointEntity;

            TestHelper.AssertAreEqualButNotSame(illustrationPoint.Name, subMechanismIllustrationPointEntity.Name);
            Assert.AreEqual(illustrationPoint.Beta, subMechanismIllustrationPointEntity.Beta, illustrationPoint.Beta.GetAccuracy());
            CollectionAssert.IsEmpty(subMechanismIllustrationPointEntity.IllustrationPointResultEntities);
            CollectionAssert.IsEmpty(subMechanismIllustrationPointEntity.SubMechanismIllustrationPointStochastEntities);
        }
Esempio n. 7
0
        public void Clone_Always_ReturnNewInstanceWithCopiedValues()
        {
            // Setup
            var random   = new Random(21);
            var original = new SubMechanismIllustrationPoint("Random name",
                                                             random.NextDouble(),
                                                             new[]
            {
                new SubMechanismIllustrationPointStochast("Random name 1",
                                                          "-",
                                                          random.NextDouble(),
                                                          random.NextDouble(),
                                                          random.NextDouble()),
                new SubMechanismIllustrationPointStochast("Random name 2",
                                                          "-",
                                                          random.NextDouble(),
                                                          random.NextDouble(),
                                                          random.NextDouble())
            },
                                                             new[]
            {
                new IllustrationPointResult("Random description 1",
                                            "-",
                                            random.NextDouble()),
                new IllustrationPointResult("Random description 2",
                                            "-",
                                            random.NextDouble())
            });

            // Call
            object clone = original.Clone();

            // Assert
            CoreCloneAssert.AreObjectClones(original, clone, CommonCloneAssert.AreClones);
        }
        public void ToString_DifferentClosingSituations_ReturnsCombinationOfWindDirectionAndClosingSituation()
        {
            // Setup
            string illustrationPointName         = string.Empty;
            var    subMechanismIllustrationPoint =
                new SubMechanismIllustrationPoint(illustrationPointName,
                                                  3,
                                                  Enumerable.Empty <SubMechanismIllustrationPointStochast>(),
                                                  Enumerable.Empty <IllustrationPointResult>());

            const string  closingSituation = "direction";
            WindDirection windDirection    = WindDirectionTestFactory.CreateTestWindDirection();
            var           context          = new TopLevelSubMechanismIllustrationPoint(windDirection,
                                                                                       closingSituation,
                                                                                       subMechanismIllustrationPoint);

            // Call
            var properties = new TopLevelSubMechanismIllustrationPointProperties(
                context,
                new[]
            {
                closingSituation,
                closingSituation,
                "Different situation"
            });

            // Assert
            string expectedStringValue = $"{windDirection.Name} ({closingSituation})";

            Assert.AreEqual(expectedStringValue, properties.ToString());
        }
Esempio n. 9
0
        public void Convert_ValidArguments_ExpectedProperties()
        {
            // Setup
            var random = new Random(21);
            var hydraRingWindDirection = new HydraRingWindDirection("Name", random.NextDouble());

            var hydraRingWindDirectionClosingSituation = new HydraRingWindDirectionClosingSituation(hydraRingWindDirection,
                                                                                                    "closing scenario");

            var hydraRingIllustrationPointResult = new HydraRingIllustrationPointResult("HydraIllustrationPointResult",
                                                                                        "-",
                                                                                        random.NextDouble());

            var hydraRingSubMechanismIllustrationPointStochast =
                new HydraRingSubMechanismIllustrationPointStochast("HydraSubMechanismIllustrationPointStochast",
                                                                   "-",
                                                                   random.NextDouble(),
                                                                   random.NextDouble(),
                                                                   random.NextDouble());

            var hydraRingSubMechanismIllustrationPoint = new HydraRingSubMechanismIllustrationPoint("name", new[]
            {
                hydraRingSubMechanismIllustrationPointStochast
            }, new[]
            {
                hydraRingIllustrationPointResult
            }, random.NextDouble());

            // Call
            TopLevelSubMechanismIllustrationPoint combination =
                TopLevelSubMechanismIllustrationPointConverter.Convert(
                    hydraRingWindDirectionClosingSituation, hydraRingSubMechanismIllustrationPoint);

            // Assert
            WindDirection windDirection = combination.WindDirection;

            Assert.AreEqual(hydraRingWindDirection.Angle, windDirection.Angle, windDirection.Angle.GetAccuracy());
            Assert.AreEqual(hydraRingWindDirection.Name, windDirection.Name);

            Assert.AreEqual(hydraRingWindDirectionClosingSituation.ClosingSituation, combination.ClosingSituation);

            SubMechanismIllustrationPoint subMechanismIllustrationPoint = combination.SubMechanismIllustrationPoint;

            Assert.AreEqual(hydraRingSubMechanismIllustrationPoint.Beta, subMechanismIllustrationPoint.Beta, subMechanismIllustrationPoint.Beta.GetAccuracy());
            Assert.AreEqual(hydraRingSubMechanismIllustrationPoint.Name, subMechanismIllustrationPoint.Name);

            IllustrationPointResult illustrationPointResult = subMechanismIllustrationPoint.IllustrationPointResults.Single();

            Assert.AreEqual(hydraRingIllustrationPointResult.Description, illustrationPointResult.Description);
            Assert.AreEqual(hydraRingIllustrationPointResult.Value, illustrationPointResult.Value, illustrationPointResult.Value.GetAccuracy());

            SubMechanismIllustrationPointStochast stochast = subMechanismIllustrationPoint.Stochasts.Single();

            Assert.AreEqual(hydraRingSubMechanismIllustrationPointStochast.Alpha, stochast.Alpha, stochast.Alpha.GetAccuracy());
            Assert.AreEqual(hydraRingSubMechanismIllustrationPointStochast.Duration, stochast.Duration, stochast.Duration.GetAccuracy());
            Assert.AreEqual(hydraRingSubMechanismIllustrationPointStochast.Name, stochast.Name);
            Assert.AreEqual(hydraRingSubMechanismIllustrationPointStochast.Unit, stochast.Unit);
            Assert.AreEqual(hydraRingSubMechanismIllustrationPointStochast.Realization, stochast.Realization, stochast.Realization.GetAccuracy());
        }
        public void Constructor_ExpectedValues()
        {
            // Setup
            const string windDirection     = "N";
            const string closingSituation  = "closing situation";
            var          illustrationPoint = new SubMechanismIllustrationPoint("Sub mechanism A",
                                                                               5.4,
                                                                               new[]
            {
                new SubMechanismIllustrationPointStochast("Test", "-", 2.0, 4.5, 0.1)
            },
                                                                               new[]
            {
                new IllustrationPointResult("result A", "-", 2.3)
            });

            // Call
            var properties = new SubMechanismIllustrationPointProperties(illustrationPoint,
                                                                         windDirection,
                                                                         closingSituation);

            // Assert
            Assert.IsInstanceOf <IllustrationPointProperties>(properties);
            PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties);

            PropertyDescriptor alphasProperty = dynamicProperties[alphasPropertyIndex];

            Assert.NotNull(alphasProperty.Attributes[typeof(KeyValueElementAttribute)]);

            PropertyDescriptor durationsProperty = dynamicProperties[durationsPropertyIndex];

            Assert.NotNull(durationsProperty.Attributes[typeof(KeyValueElementAttribute)]);

            Assert.AreEqual(windDirection, properties.WindDirection);

            TestHelper.AssertTypeConverter <SubMechanismIllustrationPointProperties, NoValueRoundedDoubleConverter>(
                nameof(SubMechanismIllustrationPointProperties.Reliability));
            Assert.AreEqual(illustrationPoint.Beta, properties.Reliability, properties.Reliability.GetAccuracy());
            Assert.AreEqual(5, properties.Reliability.NumberOfDecimalPlaces);

            TestHelper.AssertTypeConverter <SubMechanismIllustrationPointProperties, NoProbabilityValueDoubleConverter>(
                nameof(SubMechanismIllustrationPointProperties.CalculatedProbability));
            Assert.AreEqual(StatisticsConverter.ReliabilityToProbability(illustrationPoint.Beta), properties.CalculatedProbability);
            Assert.AreEqual(closingSituation, properties.ClosingSituation);

            TestHelper.AssertTypeConverter <SubMechanismIllustrationPointProperties, KeyValueExpandableArrayConverter>(
                nameof(SubMechanismIllustrationPointProperties.AlphaValues));
            CollectionAssert.AreEqual(illustrationPoint.Stochasts, properties.AlphaValues);

            TestHelper.AssertTypeConverter <SubMechanismIllustrationPointProperties, KeyValueExpandableArrayConverter>(
                nameof(SubMechanismIllustrationPointProperties.Durations));
            CollectionAssert.AreEqual(illustrationPoint.Stochasts, properties.Durations);

            TestHelper.AssertTypeConverter <SubMechanismIllustrationPointProperties, ExpandableObjectConverter>(
                nameof(SubMechanismIllustrationPointProperties.SubMechanismIllustrationPointValues));
            Assert.AreSame(illustrationPoint, properties.SubMechanismIllustrationPointValues.Data);
        }
        public void ConvertToGeneralResultTopLevelSubMechanismIllustrationPoint_HydraGeneralResultWithSubMechanismIllustrationPointsOnly_ExpectedProperties()
        {
            // Setup
            const string closingSituation = "Closing situation";

            var random = new Random(21);
            var hydraRingWindDirection = new HydraRingWindDirection("SSE", random.NextDouble());
            var hydraRingWindDirectionClosingSituation = new HydraRingWindDirectionClosingSituation(
                hydraRingWindDirection, closingSituation);

            var hydraRingIllustrationPoint = new HydraRingSubMechanismIllustrationPoint(
                "Illustration Point",
                Enumerable.Empty <HydraRingSubMechanismIllustrationPointStochast>(),
                Enumerable.Empty <HydraRingIllustrationPointResult>(),
                random.NextDouble());
            var hydraRingIllustrationTreeNode = new HydraRingIllustrationPointTreeNode(hydraRingIllustrationPoint);

            var governingHydraWindDirection = new HydraRingWindDirection("Name", random.NextDouble());
            var hydraGeneralResult          = new HydraRingGeneralResult(
                random.NextDouble(),
                governingHydraWindDirection,
                Enumerable.Empty <HydraRingStochast>(),
                new Dictionary <HydraRingWindDirectionClosingSituation, HydraRingIllustrationPointTreeNode>
            {
                {
                    hydraRingWindDirectionClosingSituation, hydraRingIllustrationTreeNode
                }
            });

            // Call
            GeneralResult <TopLevelSubMechanismIllustrationPoint> generalResult =
                GeneralResultConverter.ConvertToGeneralResultTopLevelSubMechanismIllustrationPoint(hydraGeneralResult);

            // Assert
            WindDirection generalResultGoverningWindDirection = generalResult.GoverningWindDirection;

            AssertWindDirection(governingHydraWindDirection, generalResultGoverningWindDirection);

            CollectionAssert.IsEmpty(generalResult.Stochasts);

            TopLevelSubMechanismIllustrationPoint combination = generalResult.TopLevelIllustrationPoints.Single();

            AssertWindDirection(hydraRingWindDirection, combination.WindDirection);
            Assert.AreEqual(closingSituation, combination.ClosingSituation);

            SubMechanismIllustrationPoint subMechanismIllustrationPoint = combination.SubMechanismIllustrationPoint;

            Assert.AreEqual(hydraRingIllustrationPoint.Name, subMechanismIllustrationPoint.Name);
            Assert.AreEqual(hydraRingIllustrationPoint.Beta, subMechanismIllustrationPoint.Beta, subMechanismIllustrationPoint.Beta.GetAccuracy());
            CollectionAssert.IsEmpty(subMechanismIllustrationPoint.Stochasts);
            CollectionAssert.IsEmpty(subMechanismIllustrationPoint.IllustrationPointResults);
        }
        public void Create_ValidIllustrationPointWithStochasts_ReturnSubMechanismIllustrationPointEntityWithStochastEntities()
        {
            // Setup
            var random      = new Random(21);
            var stochastOne = new SubMechanismIllustrationPointStochast("stochast name",
                                                                        "-",
                                                                        random.NextDouble(),
                                                                        random.NextDouble(),
                                                                        random.NextDouble());
            var stochastTwo = new SubMechanismIllustrationPointStochast("Stochast name two",
                                                                        "-",
                                                                        random.NextDouble(),
                                                                        random.NextDouble(),
                                                                        random.NextDouble());

            SubMechanismIllustrationPointStochast[] stochasts =
            {
                stochastOne,
                stochastTwo
            };

            var illustrationPoint = new SubMechanismIllustrationPoint("Illustration point name",
                                                                      random.NextDouble(),
                                                                      stochasts,
                                                                      Enumerable.Empty <IllustrationPointResult>());
            int order = random.Next();

            // Call
            SubMechanismIllustrationPointEntity entity = illustrationPoint.Create(order);

            // Assert
            AssertCommonProperties(illustrationPoint, entity);
            Assert.AreEqual(order, entity.Order);
            SubMechanismIllustrationPointStochastEntity[] stochastEntities =
                entity.SubMechanismIllustrationPointStochastEntities.ToArray();
            int expectedNrOfStochasts = stochasts.Length;

            Assert.AreEqual(expectedNrOfStochasts, stochastEntities.Length);
            for (var i = 0; i < expectedNrOfStochasts; i++)
            {
                SubMechanismIllustrationPointStochast       stochast       = stochasts[i];
                SubMechanismIllustrationPointStochastEntity stochastEntity = stochastEntities[i];

                TestHelper.AssertAreEqualButNotSame(stochast.Name, stochastEntity.Name);
                TestHelper.AssertAreEqualButNotSame(stochast.Unit, stochastEntity.Unit);
                Assert.AreEqual(stochast.Duration, stochastEntity.Duration, stochast.Duration.GetAccuracy());
                Assert.AreEqual(stochast.Alpha, stochastEntity.Alpha, stochast.Alpha.GetAccuracy());
                Assert.AreEqual(stochast.Realization, stochastEntity.Realization, stochast.Realization.GetAccuracy());
                Assert.AreEqual(i, stochastEntity.Order);
            }
        }
Esempio n. 13
0
 private static IEnumerable <IllustrationPointControlItem> CreateControlItems(
     GeneralResult <TopLevelSubMechanismIllustrationPoint> generalResult)
 {
     return(generalResult.TopLevelIllustrationPoints
            .Select(topLevelIllustrationPoint =>
     {
         SubMechanismIllustrationPoint illustrationPoint = topLevelIllustrationPoint.SubMechanismIllustrationPoint;
         return new IllustrationPointControlItem(topLevelIllustrationPoint,
                                                 topLevelIllustrationPoint.WindDirection.Name,
                                                 topLevelIllustrationPoint.ClosingSituation,
                                                 illustrationPoint.Stochasts,
                                                 illustrationPoint.Beta);
     }));
 }
        public void Parse_ValidDesignWaterLevelData_SetsGeneralResultAndSubMechanismOutputForAWindDirectionAsExpected()
        {
            // Setup
            string path   = Path.Combine(testDirectory, "ValidDesignWaterLevelOutputSection1");
            var    parser = new IllustrationPointsParser();

            // Call
            parser.Parse(path, 1);

            // Assert
            GeneralResult generalResult = parser.Output;

            Assert.NotNull(generalResult);
            Assert.NotNull(generalResult.GoverningWindDirection);
            Assert.AreEqual(112.5, generalResult.GoverningWindDirection.Angle);
            Assert.AreEqual("OZO", generalResult.GoverningWindDirection.Name);
            Assert.AreEqual(3.4037, generalResult.Beta);
            Assert.AreEqual(6, generalResult.Stochasts.Count());
            Dictionary <WindDirectionClosingSituation, IllustrationPointTreeNode> illustrationPointNodes = generalResult.IllustrationPoints;

            Assert.AreEqual(16, illustrationPointNodes.Count);
            CollectionAssert.AllItemsAreInstancesOfType(illustrationPointNodes.Values.Select(ip => ip.Data), typeof(SubMechanismIllustrationPoint));

            ICollection <FaultTreeIllustrationPoint>    faultTrees    = new List <FaultTreeIllustrationPoint>();
            ICollection <SubMechanismIllustrationPoint> subMechanisms = new List <SubMechanismIllustrationPoint>();

            GetAllNodes(illustrationPointNodes.Values.ElementAt(4), faultTrees, subMechanisms);

            CollectionAssert.IsEmpty(faultTrees);
            SubMechanismIllustrationPoint subMechanismIllustrationPoint = subMechanisms.Single();

            Assert.AreEqual(5.30273, subMechanismIllustrationPoint.Beta);
            Assert.AreEqual("Reference water level", subMechanismIllustrationPoint.Name);
            Assert.AreEqual(new[]
            {
                Tuple.Create("Windrichting", 0.0, 12.0, 0.0),
                Tuple.Create("Waterstand IJsselmeer", -0.575813, 96.0, 0.464036),
                Tuple.Create("Windsnelheid Schiphol 16 richtingen", -0.749296, 12.0, 19.289),
                Tuple.Create("Onzekerheid waterstand IJsselmeer", -0.0695709, 96.0, 0.0146771),
                Tuple.Create("Onzekerheid windsnelheid Schiphol 16 richtingen", -0.121567, 12.0, 1.0303),
                Tuple.Create("Modelonzekerheid lokale waterstand", -0.295595, 4383.0, 0.235119)
            }, subMechanismIllustrationPoint.Stochasts.Select(s => Tuple.Create(s.Name, s.Alpha, s.Duration, s.Realization)));
            Assert.AreEqual(new[]
            {
                Tuple.Create("Z", -0.00136652, "-"),
                Tuple.Create("Considered water level", 1.24846, "m+NAP"),
                Tuple.Create("Computed local water level", 1.24983, "m+NAP")
            }, subMechanismIllustrationPoint.Results.Select(s => Tuple.Create(s.Description, s.Value, s.Unit)));
        }
Esempio n. 15
0
        public void Read_ValidEntityWithStochasts_ReturnsSubMechanismIllustrationPointWithStochasts()
        {
            // Setup
            var random = new Random(21);

            var stochastEntityOne = new SubMechanismIllustrationPointStochastEntity
            {
                Name        = "Stochast",
                Unit        = "-",
                Alpha       = random.NextDouble(),
                Duration    = random.NextDouble(),
                Realization = random.NextDouble(),
                Order       = 0
            };
            var stochastEntityTwo = new SubMechanismIllustrationPointStochastEntity
            {
                Name        = "Stochast_Two",
                Unit        = "m",
                Alpha       = random.NextDouble(),
                Duration    = random.NextDouble(),
                Realization = random.NextDouble(),
                Order       = 1
            };

            const string illustrationPointName = "Name";
            double       beta   = random.NextDouble();
            var          entity = new SubMechanismIllustrationPointEntity
            {
                Name = illustrationPointName,
                Beta = beta,
                SubMechanismIllustrationPointStochastEntities = new[]
                {
                    stochastEntityTwo,
                    stochastEntityOne
                }
            };

            // Call
            SubMechanismIllustrationPoint illustrationPoint = entity.Read();

            // Assert
            AssertCommonProperties(entity, illustrationPoint);

            SubMechanismIllustrationPointStochast[] stochasts = illustrationPoint.Stochasts.ToArray();
            Assert.AreEqual(2, stochasts.Length);
            AssertReadStochast(stochastEntityOne, stochasts[0]);
            AssertReadStochast(stochastEntityTwo, stochasts[1]);
        }
        /// <summary>
        /// Reads the <see cref="TopLevelSubMechanismIllustrationPointEntity"/> and
        /// uses the information to construct a <see cref="TopLevelSubMechanismIllustrationPoint"/>.
        /// </summary>
        /// <param name="entity">The <see cref="TopLevelSubMechanismIllustrationPointEntity"/>
        /// to create a <see cref="TopLevelSubMechanismIllustrationPoint"/> for.</param>
        /// <returns>A new <see cref="TopLevelSubMechanismIllustrationPoint"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="entity"/>
        /// is <c>null</c>.</exception>
        internal static TopLevelSubMechanismIllustrationPoint Read(this TopLevelSubMechanismIllustrationPointEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            WindDirection windDirection = GetWindDirection(entity);

            SubMechanismIllustrationPoint subMechanismIllustrationPoint =
                entity.SubMechanismIllustrationPointEntity.Read();

            return(new TopLevelSubMechanismIllustrationPoint(windDirection,
                                                             entity.ClosingSituation,
                                                             subMechanismIllustrationPoint));
        }
Esempio n. 17
0
        public void Convert_ValidArguments_ExpectedProperties()
        {
            // Setup
            var random = new Random(21);
            var hydraIllustrationPointResult = new HydraRingIllustrationPointResult("HydraIllustrationPointResult",
                                                                                    "-",
                                                                                    random.NextDouble());

            const string name        = "hydraRingSubMechanismIllustrationPointStochast";
            const string unit        = "-";
            double       alpha       = random.NextDouble();
            double       duration    = random.NextDouble();
            double       realization = random.NextDouble();
            var          hydraRingSubMechanismIllustrationPointStochast =
                new HydraRingSubMechanismIllustrationPointStochast(name, unit, duration, alpha, realization);

            double beta = random.NextDouble();
            var    hydraSubMechanismIllustrationPoint = new HydraRingSubMechanismIllustrationPoint("name", new[]
            {
                hydraRingSubMechanismIllustrationPointStochast
            }, new[]
            {
                hydraIllustrationPointResult
            }, beta);

            // Call
            SubMechanismIllustrationPoint subMechanismIllustrationPoint =
                SubMechanismIllustrationPointConverter.Convert(hydraSubMechanismIllustrationPoint);

            // Assert
            Assert.AreEqual(subMechanismIllustrationPoint.Beta, subMechanismIllustrationPoint.Beta, subMechanismIllustrationPoint.Beta.GetAccuracy());
            Assert.AreEqual(subMechanismIllustrationPoint.Name, subMechanismIllustrationPoint.Name);

            IllustrationPointResult illustrationPointResult = subMechanismIllustrationPoint.IllustrationPointResults.Single();

            Assert.AreEqual(hydraIllustrationPointResult.Description, illustrationPointResult.Description);
            Assert.AreEqual(hydraIllustrationPointResult.Value, illustrationPointResult.Value, illustrationPointResult.Value.GetAccuracy());

            SubMechanismIllustrationPointStochast stochast = subMechanismIllustrationPoint.Stochasts.Single();

            Assert.AreEqual(hydraRingSubMechanismIllustrationPointStochast.Alpha, stochast.Alpha, stochast.Alpha.GetAccuracy());
            Assert.AreEqual(hydraRingSubMechanismIllustrationPointStochast.Duration, stochast.Duration, stochast.Duration.GetAccuracy());
            Assert.AreEqual(hydraRingSubMechanismIllustrationPointStochast.Name, stochast.Name);
            Assert.AreEqual(hydraRingSubMechanismIllustrationPointStochast.Unit, stochast.Unit);
            Assert.AreEqual(hydraRingSubMechanismIllustrationPointStochast.Realization, stochast.Realization, stochast.Realization.GetAccuracy());
        }
Esempio n. 18
0
        public void CreateGraphNode_WithSubMechanismIllustrationPointButChildrenNull_ThrowsArgumentNullException()
        {
            // Setup
            var illustrationPoint = new SubMechanismIllustrationPoint(
                "Illustration Point",
                new Random(31).NextRoundedDouble(),
                Enumerable.Empty <SubMechanismIllustrationPointStochast>(),
                Enumerable.Empty <IllustrationPointResult>());

            // Call
            void Call() => RiskeerGraphNodeFactory.CreateGraphNode(illustrationPoint, null);

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

            Assert.AreEqual("childNodes", exception.ParamName);
        }
        public void ToString_WithValidData_ReturnsEmptyString()
        {
            // Setup
            var random            = new Random(21);
            var illustrationPoint = new SubMechanismIllustrationPoint("Not an empty string",
                                                                      random.NextDouble(),
                                                                      Enumerable.Empty <SubMechanismIllustrationPointStochast>(),
                                                                      Enumerable.Empty <IllustrationPointResult>());

            var properties = new SubMechanismIllustrationPointValuesProperties(illustrationPoint);

            // Call
            string toStringValue = properties.ToString();

            // Assert
            Assert.IsEmpty(toStringValue);
        }
Esempio n. 20
0
        public void Read_ValidEntityWithoutStochastsAndIllustrationPointResults_ReturnsSubMechanismIllustrationPoint()
        {
            // Setup
            var random = new Random(21);
            var entity = new SubMechanismIllustrationPointEntity
            {
                Name = "Name",
                Beta = random.NextDouble()
            };

            // Call
            SubMechanismIllustrationPoint illustrationPoint = entity.Read();

            // Assert
            AssertCommonProperties(entity, illustrationPoint);

            CollectionAssert.IsEmpty(illustrationPoint.IllustrationPointResults);
            CollectionAssert.IsEmpty(illustrationPoint.Stochasts);
        }
        public void Create_MultipleResultsAndValidIllustrationPoint_ReturnSubMechanismIllustrationPointEntityWithResultEntities()
        {
            // Setup
            var random = new Random(21);

            var illustrationPointResultOne = new IllustrationPointResult("result description", "-", random.NextDouble());
            var illustrationPointResultTwo = new IllustrationPointResult("result description two", "kN", random.NextDouble());

            IllustrationPointResult[] illustrationPointResults =
            {
                illustrationPointResultOne,
                illustrationPointResultTwo
            };

            var illustrationPoint = new SubMechanismIllustrationPoint("Illustration point name",
                                                                      random.NextDouble(),
                                                                      Enumerable.Empty <SubMechanismIllustrationPointStochast>(),
                                                                      illustrationPointResults);
            int order = random.Next();

            // Call
            SubMechanismIllustrationPointEntity entity = illustrationPoint.Create(order);

            // Assert
            AssertCommonProperties(illustrationPoint, entity);
            Assert.AreEqual(order, entity.Order);
            IllustrationPointResultEntity[] resultEntities = entity.IllustrationPointResultEntities.ToArray();
            int expectedNrOfIllustrationPoints             = illustrationPointResults.Length;

            Assert.AreEqual(expectedNrOfIllustrationPoints, resultEntities.Length);
            for (var i = 0; i < expectedNrOfIllustrationPoints; i++)
            {
                IllustrationPointResult       illustrationPointResult       = illustrationPointResults[i];
                IllustrationPointResultEntity illustrationPointResultEntity = resultEntities[i];

                TestHelper.AssertAreEqualButNotSame(illustrationPointResult.Description, illustrationPointResultEntity.Description);
                TestHelper.AssertAreEqualButNotSame(illustrationPointResult.Unit, illustrationPointResultEntity.Unit);
                Assert.AreEqual(illustrationPointResult.Value, illustrationPointResultEntity.Value,
                                illustrationPointResult.Value.GetAccuracy());
                Assert.AreEqual(i, illustrationPointResultEntity.Order);
            }
        }
Esempio n. 22
0
        public void Read_ValidEntityWithIllustrationPointResults_ReturnsSubMechanismIllustrationPointWithResults()
        {
            // Setup
            var random = new Random(21);

            var illustrationPointResultEntityOne = new IllustrationPointResultEntity
            {
                Description = "Description",
                Unit        = "-",
                Value       = random.NextDouble(),
                Order       = 0
            };
            var illustrationPointResultEntityTwo = new IllustrationPointResultEntity
            {
                Description = "Description_Two",
                Unit        = "m",
                Value       = random.NextDouble(),
                Order       = 1
            };

            var entity = new SubMechanismIllustrationPointEntity
            {
                Name = "Name",
                Beta = random.NextDouble(),
                IllustrationPointResultEntities = new[]
                {
                    illustrationPointResultEntityTwo,
                    illustrationPointResultEntityOne
                }
            };

            // Call
            SubMechanismIllustrationPoint illustrationPoint = entity.Read();

            // Assert
            AssertCommonProperties(entity, illustrationPoint);

            IllustrationPointResult[] illustrationPointResults = illustrationPoint.IllustrationPointResults.ToArray();
            Assert.AreEqual(2, illustrationPointResults.Length);
            AssertReadIllustrationPointResult(illustrationPointResultEntityOne, illustrationPointResults[0]);
            AssertReadIllustrationPointResult(illustrationPointResultEntityTwo, illustrationPointResults[1]);
        }
        public void Constructor_WithParameters_ReturnsNewInstance()
        {
            // Setup
            const string name = "Name";

            var    random = new Random(21);
            double beta   = random.NextDouble();

            IEnumerable <SubMechanismIllustrationPointStochast> stochasts  = Enumerable.Empty <SubMechanismIllustrationPointStochast>();
            IEnumerable <IllustrationPointResult> illustrationPointResults = Enumerable.Empty <IllustrationPointResult>();

            // Call
            var illustrationPoint = new SubMechanismIllustrationPoint(name, stochasts, illustrationPointResults, beta);

            // Assert
            Assert.IsInstanceOf <IIllustrationPoint>(illustrationPoint);
            Assert.AreSame(stochasts, illustrationPoint.Stochasts);
            Assert.AreSame(illustrationPointResults, illustrationPoint.Results);
            Assert.AreEqual(beta, illustrationPoint.Beta);
        }
        public void Create_SubMechanismIllustrationPointWithoutResultsAndStochasts_ReturnSubMechanismIllustrationPointEntityWithoutResultsAndStochastsEntities()
        {
            // Setup
            var random = new Random(21);

            var illustrationPoint = new SubMechanismIllustrationPoint("Illustration point name",
                                                                      random.NextDouble(),
                                                                      Enumerable.Empty <SubMechanismIllustrationPointStochast>(),
                                                                      Enumerable.Empty <IllustrationPointResult>());
            int order = random.Next();

            // Call
            SubMechanismIllustrationPointEntity entity = illustrationPoint.Create(order);

            // Assert
            AssertCommonProperties(illustrationPoint, entity);
            Assert.AreEqual(order, entity.Order);
            CollectionAssert.IsEmpty(entity.IllustrationPointResultEntities);
            CollectionAssert.IsEmpty(entity.SubMechanismIllustrationPointStochastEntities);
        }
        protected override IEnumerable <IllustrationPointControlItem> GetIllustrationPointControlItems()
        {
            GeneralResult <TopLevelSubMechanismIllustrationPoint> generalResult = GetGeneralResultFunc();

            if (generalResult == null)
            {
                return(Enumerable.Empty <IllustrationPointControlItem>());
            }

            return(generalResult.TopLevelIllustrationPoints.Select(topLevelSubMechanismIllustrationPoint =>
            {
                SubMechanismIllustrationPoint illustrationPoint = topLevelSubMechanismIllustrationPoint.SubMechanismIllustrationPoint;

                return new IllustrationPointControlItem(topLevelSubMechanismIllustrationPoint,
                                                        topLevelSubMechanismIllustrationPoint.WindDirection.Name,
                                                        topLevelSubMechanismIllustrationPoint.ClosingSituation,
                                                        illustrationPoint.Stochasts,
                                                        illustrationPoint.Beta);
            }).ToArray());
        }
Esempio n. 26
0
        /// <summary>
        /// Creates a new instance of <see cref="TopLevelSubMechanismIllustrationPoint"/>
        /// based on the information of <paramref name="hydraRingWindDirectionClosingSituation"/>
        /// and <paramref name="hydraRingSubMechanismIllustrationPoint"/>.
        /// </summary>
        /// <param name="hydraRingWindDirectionClosingSituation">The <see cref="HydraRingWindDirectionClosingSituation"/>
        /// to base the <see cref="TopLevelSubMechanismIllustrationPoint"/> on.</param>
        /// <param name="hydraRingSubMechanismIllustrationPoint">The <see cref="HydraRingSubMechanismIllustrationPoint"/>
        /// to base the <see cref="TopLevelSubMechanismIllustrationPoint"/> on.</param>
        /// <returns>A <see cref="TopLevelSubMechanismIllustrationPoint"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception>
        public static TopLevelSubMechanismIllustrationPoint Convert(HydraRingWindDirectionClosingSituation hydraRingWindDirectionClosingSituation,
                                                                    HydraRingSubMechanismIllustrationPoint hydraRingSubMechanismIllustrationPoint)
        {
            if (hydraRingWindDirectionClosingSituation == null)
            {
                throw new ArgumentNullException(nameof(hydraRingWindDirectionClosingSituation));
            }

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

            WindDirection windDirection = WindDirectionConverter.Convert(hydraRingWindDirectionClosingSituation.WindDirection);
            SubMechanismIllustrationPoint subMechanismIllustrationPoint =
                SubMechanismIllustrationPointConverter.Convert(hydraRingSubMechanismIllustrationPoint);

            return(new TopLevelSubMechanismIllustrationPoint(windDirection,
                                                             hydraRingWindDirectionClosingSituation.ClosingSituation,
                                                             subMechanismIllustrationPoint));
        }
Esempio n. 27
0
        /// <summary>
        /// Creates a <see cref="SubMechanismIllustrationPointEntity"/> based on
        /// the information of <paramref name="subMechanismIllustrationPoint"/>.
        /// </summary>
        /// <param name="subMechanismIllustrationPoint">The sub mechanism illustration
        /// point to create a database entity for.</param>
        /// <param name="order">The index at which <paramref name="subMechanismIllustrationPoint"/>
        /// resides within its parent.</param>
        /// <returns>A new <see cref="SubMechanismIllustrationPointEntity"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when
        /// <paramref name="subMechanismIllustrationPoint"/> is <c>null</c>.</exception>
        internal static SubMechanismIllustrationPointEntity Create(
            this SubMechanismIllustrationPoint subMechanismIllustrationPoint,
            int order)
        {
            if (subMechanismIllustrationPoint == null)
            {
                throw new ArgumentNullException(nameof(subMechanismIllustrationPoint));
            }

            var entity = new SubMechanismIllustrationPointEntity
            {
                Beta  = subMechanismIllustrationPoint.Beta,
                Name  = subMechanismIllustrationPoint.Name.DeepClone(),
                Order = order
            };

            AddEntitiesForSubMechanismIllustrationPointsStochasts(entity, subMechanismIllustrationPoint.Stochasts);
            AddEntitiesForIllustrationPointResults(entity, subMechanismIllustrationPoint.IllustrationPointResults);

            return(entity);
        }
        public void Read_ValidEntity_ReturnsTopLevelSubMechanismIllustrationPoint()
        {
            // Setup
            var random = new Random(21);

            var subMechanismIllustrationPointEntity = new SubMechanismIllustrationPointEntity
            {
                Name = "Illustration point name",
                Beta = random.NextDouble()
            };

            var entity = new TopLevelSubMechanismIllustrationPointEntity
            {
                ClosingSituation   = "closingSituation",
                WindDirectionName  = "WindDirectionName",
                WindDirectionAngle = random.NextDouble(),
                SubMechanismIllustrationPointEntity = subMechanismIllustrationPointEntity
            };

            // Call
            TopLevelSubMechanismIllustrationPoint topLevelSubMechanismIllustrationPoint = entity.Read();

            // Assert
            Assert.AreEqual(entity.ClosingSituation, topLevelSubMechanismIllustrationPoint.ClosingSituation);

            WindDirection actualWindDirection = topLevelSubMechanismIllustrationPoint.WindDirection;

            Assert.AreEqual(entity.WindDirectionName, actualWindDirection.Name);
            Assert.AreEqual(entity.WindDirectionAngle, actualWindDirection.Angle,
                            actualWindDirection.Angle.GetAccuracy());

            SubMechanismIllustrationPoint actualIllustrationPoint = topLevelSubMechanismIllustrationPoint.SubMechanismIllustrationPoint;

            Assert.AreEqual(subMechanismIllustrationPointEntity.Name, actualIllustrationPoint.Name);
            Assert.AreEqual(subMechanismIllustrationPointEntity.Beta, actualIllustrationPoint.Beta,
                            actualIllustrationPoint.Beta.GetAccuracy());
            CollectionAssert.IsEmpty(actualIllustrationPoint.Stochasts);
            CollectionAssert.IsEmpty(actualIllustrationPoint.IllustrationPointResults);
        }
        public void GetProperties_ValidData_ReturnsExpectedValues()
        {
            var    random    = new Random(21);
            double beta      = random.NextDouble();
            var    stochasts = new[]
            {
                new SubMechanismIllustrationPointStochast("some name", "-", random.NextDouble(), random.NextDouble(), random.NextDouble())
            };
            var illustrationPointResults = new[]
            {
                new IllustrationPointResult("some description", "-", random.NextDouble())
            };

            const string illustrationPointName         = "name";
            var          subMechanismIllustrationPoint = new SubMechanismIllustrationPoint(illustrationPointName,
                                                                                           beta,
                                                                                           stochasts,
                                                                                           illustrationPointResults);

            const string closingSituation  = "closingSituation";
            const string windDirectionName = "windDirection";
            var          illustrationPoint = new TopLevelSubMechanismIllustrationPoint(WindDirectionTestFactory.CreateTestWindDirection(windDirectionName),
                                                                                       closingSituation,
                                                                                       subMechanismIllustrationPoint);

            // Call
            var properties = new TopLevelSubMechanismIllustrationPointProperties(illustrationPoint, Enumerable.Empty <string>());

            // Assert
            Assert.AreEqual(illustrationPointName, properties.Name);
            Assert.AreEqual(windDirectionName, properties.WindDirection);
            Assert.AreEqual(closingSituation, properties.ClosingSituation);
            CollectionAssert.AreEqual(subMechanismIllustrationPoint.Stochasts, properties.AlphaValues);
            CollectionAssert.AreEqual(subMechanismIllustrationPoint.Stochasts, properties.Durations);

            Assert.AreSame(illustrationPoint.SubMechanismIllustrationPoint,
                           properties.SubMechanismIllustrationPointValues.Data);
        }
Esempio n. 30
0
        public void Constructor_ValidArguments_ReturnsExpectedValues()
        {
            // Setup
            const string name   = "Illustration Point";
            var          random = new Random(21);
            double       beta   = random.NextDouble();

            var stochasts = new List <SubMechanismIllustrationPointStochast>();
            var illustrationPointResults = new List <IllustrationPointResult>();

            // Call
            var illustrationPoint = new SubMechanismIllustrationPoint(name,
                                                                      beta,
                                                                      stochasts,
                                                                      illustrationPointResults);

            // Assert
            Assert.IsInstanceOf <IllustrationPointBase>(illustrationPoint);
            Assert.AreEqual(name, illustrationPoint.Name);
            Assert.AreEqual(beta, illustrationPoint.Beta, illustrationPoint.Beta.GetAccuracy());
            Assert.AreSame(stochasts, illustrationPoint.Stochasts);
            Assert.AreSame(illustrationPointResults, illustrationPoint.IllustrationPointResults);
        }