Пример #1
0
        public void Convert_ValidArguments_ExpectedProperties()
        {
            // Setup
            var random            = new Random(21);
            var hydraRingStochast = new HydraRingStochast("hydraRingStochast",
                                                          random.NextDouble(),
                                                          random.NextDouble());

            var hydraRingFaultTreeIllustrationPoint =
                new HydraRingFaultTreeIllustrationPoint("name", random.NextDouble(), new[]
            {
                hydraRingStochast
            }, HydraRingCombinationType.And);

            // Call
            FaultTreeIllustrationPoint faultTreeIllustrationPoint =
                FaultTreeIllustrationPointConverter.Convert(hydraRingFaultTreeIllustrationPoint);

            // Assert
            Assert.AreEqual(hydraRingFaultTreeIllustrationPoint.Beta, faultTreeIllustrationPoint.Beta,
                            faultTreeIllustrationPoint.Beta.GetAccuracy());
            Assert.AreEqual(hydraRingFaultTreeIllustrationPoint.Name, faultTreeIllustrationPoint.Name);
            Assert.AreEqual(CombinationType.And, faultTreeIllustrationPoint.CombinationType);

            Stochast stochast = faultTreeIllustrationPoint.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);
        }
Пример #2
0
        /// <summary>
        /// Creates a new instance of <see cref="Stochast"/> based on the information of <paramref name="hydraRingStochast"/>.
        /// </summary>
        /// <param name="hydraRingStochast">The <see cref="HydraRingStochast"/> to base the
        /// <see cref="Stochast"/> to create on.</param>
        /// <returns>The newly created <see cref="Stochast"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="hydraRingStochast"/>
        /// is <c>null</c>.</exception>
        public static Stochast Convert(HydraRingStochast hydraRingStochast)
        {
            if (hydraRingStochast == null)
            {
                throw new ArgumentNullException(nameof(hydraRingStochast));
            }

            return(new Stochast(hydraRingStochast.Name,
                                hydraRingStochast.Duration,
                                hydraRingStochast.Alpha));
        }
        public void Convert_ValidHydraRingFaultTreeIllustrationPointWithoutChildren_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 hydraRingFaultTreeIllustrationPoint = new HydraRingFaultTreeIllustrationPoint("fault tree", random.NextDouble(),
                                                                                              new[]
            {
                hydraRingStochast
            }, HydraRingCombinationType.And);

            var treeNode = new HydraRingIllustrationPointTreeNode(hydraRingFaultTreeIllustrationPoint);

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

            // 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 illustrationPointNode = topLevelIllustrationPoint.FaultTreeNodeRoot;

            CollectionAssert.IsEmpty(illustrationPointNode.Children);

            var illustrationPointData = (FaultTreeIllustrationPoint)illustrationPointNode.Data;

            Assert.AreEqual(hydraRingFaultTreeIllustrationPoint.Name, illustrationPointData.Name);
            Assert.AreEqual(hydraRingFaultTreeIllustrationPoint.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);
        }
Пример #4
0
        public void Convert_ValidHydraRingStochastArgument_ExpectedProperties()
        {
            // Setup
            const string name = "name";

            var    random            = new Random(21);
            double duration          = random.NextDouble();
            double alpha             = random.NextDouble();
            var    hydraRingStochast = new HydraRingStochast(name, duration, alpha);

            // Call
            Stochast stochast = StochastConverter.Convert(hydraRingStochast);

            // Assert
            Assert.AreEqual(hydraRingStochast.Alpha, stochast.Alpha, stochast.Alpha.GetAccuracy());
            Assert.AreEqual(duration, stochast.Duration, stochast.Duration.GetAccuracy());
            Assert.AreEqual(hydraRingStochast.Name, stochast.Name);
        }
        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());
        }