コード例 #1
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());
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        public void Convert_HydraWindDirectionNull_ThrowsArgumentNullException()
        {
            // Setup
            var hydraRingSubMechanismIllustrationPoint =
                new HydraRingSubMechanismIllustrationPoint("name",
                                                           Enumerable.Empty <HydraRingSubMechanismIllustrationPointStochast>(),
                                                           Enumerable.Empty <HydraRingIllustrationPointResult>(),
                                                           double.NaN);

            // Call
            void Call() => TopLevelSubMechanismIllustrationPointConverter.Convert(null, hydraRingSubMechanismIllustrationPoint);

            // Assert
            string paramName = Assert.Throws <ArgumentNullException>(Call).ParamName;

            Assert.AreEqual("hydraRingWindDirectionClosingSituation", paramName);
        }
コード例 #4
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());
        }
コード例 #5
0
        /// <summary>
        /// Creates a new instance of <see cref="SubMechanismIllustrationPoint"/> based on the
        /// information of <paramref name="hydraRingSubMechanismIllustrationPoint"/>.
        /// </summary>
        /// <param name="hydraRingSubMechanismIllustrationPoint">The <see cref="HydraRingSubMechanismIllustrationPoint"/>
        /// to base the <see cref="SubMechanismIllustrationPoint"/> to create on.</param>
        /// <returns>The newly created <see cref="SubMechanismIllustrationPoint"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="hydraRingSubMechanismIllustrationPoint"/>
        /// is <c>null</c>.</exception>
        public static SubMechanismIllustrationPoint Convert(HydraRingSubMechanismIllustrationPoint hydraRingSubMechanismIllustrationPoint)
        {
            if (hydraRingSubMechanismIllustrationPoint == null)
            {
                throw new ArgumentNullException(nameof(hydraRingSubMechanismIllustrationPoint));
            }

            IEnumerable <SubMechanismIllustrationPointStochast> stochasts = hydraRingSubMechanismIllustrationPoint.Stochasts
                                                                            .Select(StochastConverter.Convert)
                                                                            .ToArray();
            IEnumerable <IllustrationPointResult> illustrationPointResults = hydraRingSubMechanismIllustrationPoint.Results
                                                                             .Select(IllustrationPointResultConverter.Convert)
                                                                             .ToArray();

            return(new SubMechanismIllustrationPoint(hydraRingSubMechanismIllustrationPoint.Name,
                                                     hydraRingSubMechanismIllustrationPoint.Beta,
                                                     stochasts,
                                                     illustrationPointResults));
        }
コード例 #6
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));
        }
コード例 #7
0
        public void ConvertToGeneralResultTopLevelFaultTreeIllustrationPoint_HydraGeneralResultWithSubMechanismIllustrationPointsOnly_ThrowsIllustrationPointConversionException()
        {
            // 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);

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

            // Call
            TestDelegate call = () => GeneralResultConverter.ConvertToGeneralResultTopLevelFaultTreeIllustrationPoint(hydraGeneralResult);

            // Assert
            var    exception       = Assert.Throws <IllustrationPointConversionException>(call);
            string expectedMessage = $"Expected a fault tree node with data of type {typeof(HydraRingFaultTreeIllustrationPoint)} as root, but got {hydraRingIllustrationPoint.GetType()}";

            Assert.AreEqual(expectedMessage, exception.Message);
        }
        public void Convert_ValidHydraRingFaultTreeIllustrationPointWithChildren_ExpectedProperties()
        {
            // Setup
            var random = new Random(21);
            var hydraRingWindDirection = new HydraRingWindDirection("random name", random.NextDouble());

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

            var hydraRingStochast = new HydraRingStochast("random stochast",
                                                          random.NextDouble(),
                                                          random.NextDouble());

            var hydraRingFaultTreeIllustrationPointRoot = new HydraRingFaultTreeIllustrationPoint("fault tree root", random.NextDouble(),
                                                                                                  new[]
            {
                hydraRingStochast
            }, HydraRingCombinationType.And);

            var hydraRingFaultTreeIllustrationPointChildOne = new HydraRingFaultTreeIllustrationPoint("fault tree child one",
                                                                                                      random.NextDouble(),
                                                                                                      new[]
            {
                hydraRingStochast
            },
                                                                                                      HydraRingCombinationType.Or);

            var hydraRingFaultTreeIllustrationPointChildTwo = new HydraRingSubMechanismIllustrationPoint("fault tree child two",
                                                                                                         Enumerable.Empty <HydraRingSubMechanismIllustrationPointStochast>(),
                                                                                                         Enumerable.Empty <HydraRingIllustrationPointResult>(),
                                                                                                         random.NextDouble());

            var treeNodeRoot = new HydraRingIllustrationPointTreeNode(hydraRingFaultTreeIllustrationPointRoot);

            treeNodeRoot.SetChildren(new[]
            {
                new HydraRingIllustrationPointTreeNode(hydraRingFaultTreeIllustrationPointChildOne),
                new HydraRingIllustrationPointTreeNode(hydraRingFaultTreeIllustrationPointChildTwo)
            });

            // Call
            TopLevelFaultTreeIllustrationPoint topLevelIllustrationPoint =
                TopLevelFaultTreeIllustrationPointConverter.Convert(hydraRingWindDirectionClosingSituation, treeNodeRoot);

            // Assert
            WindDirection windDirection = topLevelIllustrationPoint.WindDirection;

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

            Assert.AreEqual(hydraRingWindDirectionClosingSituation.ClosingSituation, topLevelIllustrationPoint.ClosingSituation);
            IllustrationPointNode illustrationPoint = topLevelIllustrationPoint.FaultTreeNodeRoot;

            var illustrationPointData = (FaultTreeIllustrationPoint)illustrationPoint.Data;

            Assert.AreEqual(hydraRingFaultTreeIllustrationPointRoot.Name, illustrationPointData.Name);
            Assert.AreEqual(hydraRingFaultTreeIllustrationPointRoot.Beta, illustrationPointData.Beta, illustrationPointData.Beta.GetAccuracy());
            Assert.AreEqual(CombinationType.And, illustrationPointData.CombinationType);

            Stochast stochast = illustrationPointData.Stochasts.Single();

            Assert.AreEqual(hydraRingStochast.Alpha, stochast.Alpha, stochast.Alpha.GetAccuracy());
            Assert.AreEqual(hydraRingStochast.Duration, stochast.Duration, stochast.Duration.GetAccuracy());
            Assert.AreEqual(hydraRingStochast.Name, stochast.Name);

            Assert.AreEqual(treeNodeRoot.Children.Count(), illustrationPoint.Children.Count());
            IllustrationPointNode[] children = illustrationPoint.Children.ToArray();
            CollectionAssert.IsEmpty(children[0].Children);
            CollectionAssert.IsEmpty(children[1].Children);

            var      childOne      = (FaultTreeIllustrationPoint)children[0].Data;
            Stochast childStochast = illustrationPointData.Stochasts.Single();

            Assert.AreEqual(hydraRingStochast.Alpha, childStochast.Alpha, childStochast.Alpha.GetAccuracy());
            Assert.AreEqual(hydraRingStochast.Duration, childStochast.Duration, childStochast.Duration.GetAccuracy());
            Assert.AreEqual(hydraRingStochast.Name, childStochast.Name);
            Assert.AreEqual(hydraRingFaultTreeIllustrationPointChildOne.Name, childOne.Name);
            Assert.AreEqual(hydraRingFaultTreeIllustrationPointChildOne.Beta, childOne.Beta, childOne.Beta.GetAccuracy());
            Assert.AreEqual(CombinationType.Or, childOne.CombinationType);

            var childTwo = (SubMechanismIllustrationPoint)children[1].Data;

            CollectionAssert.IsEmpty(childTwo.Stochasts);
            CollectionAssert.IsEmpty(childTwo.IllustrationPointResults);
            Assert.AreEqual(hydraRingFaultTreeIllustrationPointChildTwo.Name, childTwo.Name);
            Assert.AreEqual(hydraRingFaultTreeIllustrationPointChildTwo.Beta, childTwo.Beta, childTwo.Beta.GetAccuracy());
        }