public void Convert_HydraRingIllustrationPointTreeNodeNull_ThrowsArgumentNullException()
        {
            // Setup
            var hydraRingWindDirectionClosingSituation = new HydraRingWindDirectionClosingSituation(WindDirectionTestFactory.CreateWindDirection(),
                                                                                                    "random closing situation");

            // Call
            TestDelegate call = () => TopLevelFaultTreeIllustrationPointConverter.Convert(hydraRingWindDirectionClosingSituation, null);

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

            Assert.AreEqual("hydraRingIllustrationPointTreeNode", exception.ParamName);
        }
        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);
        }
        public void Convert_HydraRingWindDirectionClosingSituationNull_ThrowsArgumentNullException()
        {
            // Setup
            var hydraRingFaultTreeIllustrationPoint = new HydraRingFaultTreeIllustrationPoint("fault tree",
                                                                                              double.NaN,
                                                                                              Enumerable.Empty <HydraRingStochast>(),
                                                                                              HydraRingCombinationType.And);

            var treeNode = new HydraRingIllustrationPointTreeNode(hydraRingFaultTreeIllustrationPoint);

            // Call
            TestDelegate call = () => TopLevelFaultTreeIllustrationPointConverter.Convert(null, treeNode);

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

            Assert.AreEqual("hydraRingWindDirectionClosingSituation", exception.ParamName);
        }
        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());
        }