コード例 #1
0
        public void GivenControlWithData_WhenDataSetToNull_ThenPointedTreeGraphUpdated()
        {
            // Given
            using (var control = new IllustrationPointsFaultTreeControl())
            {
                var rootNode = new IllustrationPointNode(new TestFaultTreeIllustrationPoint());
                rootNode.SetChildren(new[]
                {
                    new IllustrationPointNode(new TestSubMechanismIllustrationPoint("A")),
                    new IllustrationPointNode(new TestSubMechanismIllustrationPoint("B"))
                });

                control.Data = new TopLevelFaultTreeIllustrationPoint(
                    WindDirectionTestFactory.CreateTestWindDirection(),
                    "closing situation",
                    rootNode);

                PointedTreeGraph graph = GetPointedTreeGraph(control);

                // Precondition
                Assert.AreEqual(4, graph.VertexCount);
                Assert.AreEqual(3, graph.EdgeCount);

                // When
                control.Data = null;

                // Then
                graph = GetPointedTreeGraph(control);

                Assert.IsNull(control.Selection);
                Assert.AreEqual(0, graph.VertexCount);
                Assert.AreEqual(0, graph.EdgeCount);
            }
        }
コード例 #2
0
        public void GivenControlWithData_WhenVertexSelected_SelectionSetToCorrespondingIllustrationPointNodeSelectionChangedFired()
        {
            // Given
            using (var control = new IllustrationPointsFaultTreeControl())
            {
                var illustrationPointNode = new IllustrationPointNode(new TestSubMechanismIllustrationPoint());

                var rootNode = new IllustrationPointNode(new TestFaultTreeIllustrationPoint("A"));
                rootNode.SetChildren(new[]
                {
                    illustrationPointNode,
                    new IllustrationPointNode(new TestSubMechanismIllustrationPoint("B"))
                });

                control.Data = new TopLevelFaultTreeIllustrationPoint(
                    WindDirectionTestFactory.CreateTestWindDirection(),
                    "closing situation",
                    rootNode);

                var selectionChanged = 0;
                control.SelectionChanged += (sender, args) => selectionChanged++;

                PointedTreeElementVertex selectedVertex = GetPointedTreeGraph(control).Vertices.ElementAt(2);

                // When
                selectedVertex.IsSelected = true;

                // Then
                object selection = control.Selection;
                Assert.AreSame(illustrationPointNode, selection);
                Assert.AreEqual(1, selectionChanged);
            }
        }
コード例 #3
0
        public void GetStochastNames_IllustrationPointNodeWithSubMechanismIllustrationPointWithStochast_ReturnStochastNames()
        {
            // Setup
            var          random                = new Random(21);
            const string stochastNameA         = "Stochast A";
            const string stochastNameB         = "Stochast B";
            var          illustrationPointNode = new IllustrationPointNode(new TestSubMechanismIllustrationPoint(new[]
            {
                new SubMechanismIllustrationPointStochast(stochastNameA,
                                                          "-",
                                                          random.NextDouble(),
                                                          random.NextDouble(),
                                                          random.NextDouble()),
                new SubMechanismIllustrationPointStochast(stochastNameB,
                                                          "-",
                                                          random.NextDouble(),
                                                          random.NextDouble(),
                                                          random.NextDouble())
            }));

            // Call
            IEnumerable <string> names = illustrationPointNode.GetStochastNames();

            // Assert
            CollectionAssert.AreEqual(new[]
            {
                stochastNameA,
                stochastNameB
            }, names);
        }
コード例 #4
0
        public void Create_IllustrationPointNodeWithFaultTreeIllustrationPoint_ReturnFaultTreeIllustrationPointEntity()
        {
            // Setup
            var random = new Random(21);

            var illustrationPoint = new FaultTreeIllustrationPoint("Illustration point name",
                                                                   random.NextDouble(),
                                                                   Enumerable.Empty <Stochast>(),
                                                                   random.NextEnumValue <CombinationType>());
            int order = random.Next();

            var node = new IllustrationPointNode(illustrationPoint);

            // Call
            FaultTreeIllustrationPointEntity entity = node.Create(order);

            // Assert
            Assert.IsNull(entity.FaultTreeIllustrationPointEntity2);
            TestHelper.AssertAreEqualButNotSame(illustrationPoint.Name, entity.Name);
            Assert.AreEqual(illustrationPoint.Beta, entity.Beta, illustrationPoint.Beta.GetAccuracy());
            byte expectedCombinationType = Convert.ToByte(illustrationPoint.CombinationType);

            Assert.AreEqual(expectedCombinationType, entity.CombinationType);
            CollectionAssert.IsEmpty(entity.FaultTreeIllustrationPointEntity1);
            CollectionAssert.IsEmpty(entity.StochastEntities);
            CollectionAssert.IsEmpty(entity.SubMechanismIllustrationPointEntities);
            CollectionAssert.IsEmpty(entity.TopLevelFaultTreeIllustrationPointEntities);
            Assert.AreEqual(order, entity.Order);
        }
コード例 #5
0
        public void GivenControl_WhenDataSetWithInvalidIllustrationPointChildType_ThenThrowsNotSupportedException()
        {
            // Given
            using (var control = new IllustrationPointsFaultTreeControl())
            {
                var rootNode = new IllustrationPointNode(new TestFaultTreeIllustrationPoint());
                rootNode.SetChildren(new[]
                {
                    new IllustrationPointNode(new TestIllustrationPoint()),
                    new IllustrationPointNode(new TestSubMechanismIllustrationPoint())
                });

                var topLevelFaultTreeIllustrationPoint = new TopLevelFaultTreeIllustrationPoint(
                    WindDirectionTestFactory.CreateTestWindDirection(),
                    "closing situation",
                    rootNode);

                // When
                TestDelegate test = () => control.Data = topLevelFaultTreeIllustrationPoint;

                // Then
                var exception = Assert.Throws <NotSupportedException>(test);
                Assert.AreEqual($"IllustrationPointNode of type {nameof(TestIllustrationPoint)} is not supported. " +
                                $"Supported types: {nameof(FaultTreeIllustrationPoint)} and {nameof(SubMechanismIllustrationPoint)}", exception.Message);
            }
        }
コード例 #6
0
        public void Convert_ValidTreeNodeRootWithUnsupportedTreeNodeDataChildren_ThrowsIllustrationPointConversionException()
        {
            // Setup
            var hydraRingFaultTreeIllustrationPoint = new TestHydraRingFaultTreeIllustrationPoint();
            var hydraRingIllustrationPointTreeNode  = new HydraRingIllustrationPointTreeNode(hydraRingFaultTreeIllustrationPoint);

            var nestedUnsupportedIllustrationPointData  = new HydraRingIllustrationPointTreeNode(new TestHydraRingIllustrationPointData());
            var nestedUnsupportedIllustrationPointData2 = new HydraRingIllustrationPointTreeNode(new TestHydraRingIllustrationPointData());

            hydraRingIllustrationPointTreeNode.SetChildren(new[]
            {
                nestedUnsupportedIllustrationPointData,
                nestedUnsupportedIllustrationPointData2
            });

            IllustrationPointNode illustrationPointNode = null;

            // Call
            void Call() => illustrationPointNode = IllustrationPointNodeConverter.Convert(hydraRingIllustrationPointTreeNode);

            // Assert
            Assert.IsNull(illustrationPointNode);

            var    exception       = Assert.Throws <IllustrationPointConversionException>(Call);
            string expectedMessage = $"An illustration point containing a Hydra-Ring data type of {typeof(TestHydraRingIllustrationPointData)} is not supported.";

            Assert.AreEqual(expectedMessage, exception.Message);

            string    expectedMessageInnerException = $"Cannot convert {typeof(TestHydraRingIllustrationPointData)}.";
            Exception innerException = exception.InnerException;

            Assert.IsInstanceOf <NotSupportedException>(innerException);
            Assert.AreEqual(expectedMessageInnerException, innerException.Message);
        }
コード例 #7
0
        public void GetStochastNamesRecursively_IllustrationPointNodeWithFaultTreeIllustrationPointAndChildrenContainingStochasts_ReturnStochastNames()
        {
            // Setup
            const string stochastNameA         = "Stochast A";
            const string stochastNameB         = "Stochast B";
            var          illustrationPointNode = new IllustrationPointNode(new TestFaultTreeIllustrationPoint(new[]
            {
                new Stochast(stochastNameA, 2, 4),
                new Stochast(stochastNameB, 1, 5)
            }));

            illustrationPointNode.SetChildren(new[]
            {
                new IllustrationPointNode(new FaultTreeIllustrationPoint("Point A", 0.0, new[]
                {
                    new Stochast(stochastNameA, 2, 3)
                }, CombinationType.And)),
                new IllustrationPointNode(new FaultTreeIllustrationPoint("Point B", 0.0, new[]
                {
                    new Stochast(stochastNameB, 2, 3)
                }, CombinationType.And))
            });

            // Call
            IEnumerable <string> names = illustrationPointNode.GetStochastNamesRecursively();

            // Assert
            CollectionAssert.AreEqual(new[]
            {
                stochastNameA,
                stochastNameB,
                stochastNameA,
                stochastNameB
            }, names);
        }
コード例 #8
0
        public void Convert_TreeNodeWithoutChildrenAndFaultTreeIllustrationPointData_ReturnIllustrationPointNode()
        {
            // Setup
            var hydraRingStochast = new HydraRingStochast("stochast", 1, 2);
            var hydraRingFaultTreeIllustrationPoint = new HydraRingFaultTreeIllustrationPoint("point", 3, new[]
            {
                hydraRingStochast
            }, HydraRingCombinationType.And);
            var hydraRingIllustrationPointTreeNode = new HydraRingIllustrationPointTreeNode(hydraRingFaultTreeIllustrationPoint);

            // Call
            IllustrationPointNode illustrationPointNode = IllustrationPointNodeConverter.Convert(hydraRingIllustrationPointTreeNode);

            // Assert
            CollectionAssert.IsEmpty(illustrationPointNode.Children);
            var faultTreeIllustrationPointTreeNodeData = (FaultTreeIllustrationPoint)illustrationPointNode.Data;

            Assert.AreEqual(hydraRingFaultTreeIllustrationPoint.Name, faultTreeIllustrationPointTreeNodeData.Name);
            Assert.AreEqual(hydraRingFaultTreeIllustrationPoint.Beta, faultTreeIllustrationPointTreeNodeData.Beta);
            Assert.AreEqual(CombinationType.And, faultTreeIllustrationPointTreeNodeData.CombinationType);
            Assert.AreEqual(hydraRingFaultTreeIllustrationPoint.Stochasts.Count(), faultTreeIllustrationPointTreeNodeData.Stochasts.Count());
            Stochast stochast = faultTreeIllustrationPointTreeNodeData.Stochasts.First();

            Assert.AreEqual(hydraRingStochast.Name, stochast.Name);
            Assert.AreEqual(hydraRingStochast.Duration, stochast.Duration, stochast.Duration.GetAccuracy());
            Assert.AreEqual(hydraRingStochast.Alpha, stochast.Alpha, stochast.Alpha.GetAccuracy());
        }
コード例 #9
0
ファイル: GeneralResultTest.cs プロジェクト: Deltares/Riskeer
        public void Constructor_ChildStochastsNotEqualToTopLevelIllustrationPointStochasts_ThrowArgumentException()
        {
            // Setup
            WindDirection windDirection = WindDirectionTestFactory.CreateTestWindDirection();

            var illustrationPointNode = new IllustrationPointNode(new TestFaultTreeIllustrationPoint(new[]
            {
                new Stochast("Stochast 2", 0, 0)
            }));

            IEnumerable <TopLevelIllustrationPointBase> topLevelIllustrationPoints = new List <TopLevelIllustrationPointBase>
            {
                new TopLevelFaultTreeIllustrationPoint(windDirection, "closing", illustrationPointNode)
            };

            IEnumerable <Stochast> stochasts = new[]
            {
                new Stochast("Stochast 1", 0, 0)
            };

            // Call
            TestDelegate test = () => new GeneralResult <TopLevelIllustrationPointBase>(windDirection,
                                                                                        stochasts,
                                                                                        topLevelIllustrationPoints);

            // Assert
            const string expectedMessage = "De stochasten van een illustratiepunt bevatten niet dezelfde stochasten als in de onderliggende illustratiepunten.";

            TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentException>(test, expectedMessage);
        }
コード例 #10
0
        public void Create_IllustrationPointNodeWithValidChildren_ReturnFaultTreeIllustrationPointEntity(
            IEnumerable <IllustrationPointNode> children)
        {
            // Setup
            var random = new Random(21);

            var illustrationPoint = new FaultTreeIllustrationPoint("Illustration point name A",
                                                                   random.NextDouble(),
                                                                   Enumerable.Empty <Stochast>(),
                                                                   random.NextEnumValue <CombinationType>());
            int order = random.Next();

            var node = new IllustrationPointNode(illustrationPoint);

            node.SetChildren(children.ToArray());

            // Call
            FaultTreeIllustrationPointEntity entity = node.Create(order);

            // Assert
            AssertFaultTreeIllustrationPointEntity(illustrationPoint, entity);
            AssertIllustrationPointEntities(node.Children.ToArray(),
                                            entity.SubMechanismIllustrationPointEntities.ToArray(),
                                            entity.FaultTreeIllustrationPointEntity1.ToArray());

            Assert.AreEqual(order, entity.Order);
        }
コード例 #11
0
        /// <summary>
        /// Creates a new instance of <see cref="IllustrationPointContext{T}"/>.
        /// </summary>
        /// <param name="illustrationPoint">The illustration point.</param>
        /// <param name="illustrationPointNode">The illustration point node.</param>
        /// <param name="windDirectionName">The name of the wind direction.</param>
        /// <param name="closingSituation">The closing situation of the illustration point.</param>
        /// <exception cref="ArgumentNullException">Thrown when any of the input parameters is <c>null</c>.</exception>
        public IllustrationPointContext(T illustrationPoint,
                                        IllustrationPointNode illustrationPointNode,
                                        string windDirectionName,
                                        string closingSituation)
        {
            if (illustrationPoint == null)
            {
                throw new ArgumentNullException(nameof(illustrationPoint));
            }

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

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

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

            IllustrationPoint     = illustrationPoint;
            IllustrationPointNode = illustrationPointNode;
            WindDirectionName     = windDirectionName;
            ClosingSituation      = closingSituation;
        }
コード例 #12
0
        private static IEnumerable <TestCaseData> GetValidIllustrationPointNodes()
        {
            yield return(new TestCaseData(new List <IllustrationPointNode>
            {
                new IllustrationPointNode(new TestSubMechanismIllustrationPoint("A")),
                new IllustrationPointNode(new TestSubMechanismIllustrationPoint("B"))
            }).SetName("SubMechanismIllustrationPoints"));

            yield return(new TestCaseData(new List <IllustrationPointNode>
            {
                new IllustrationPointNode(new TestSubMechanismIllustrationPoint("A")),
                new IllustrationPointNode(FaultTreeIllustrationPointTestFactory.CreateTestFaultTreeIllustrationPointCombinationTypeAnd("B"))
            }).SetName("SubMechanismAndFaultTreeIllustrationPoints"));

            yield return(new TestCaseData(new List <IllustrationPointNode>
            {
                new IllustrationPointNode(FaultTreeIllustrationPointTestFactory.CreateTestFaultTreeIllustrationPointCombinationTypeAnd("A")),
                new IllustrationPointNode(FaultTreeIllustrationPointTestFactory.CreateTestFaultTreeIllustrationPointCombinationTypeAnd("B"))
            }).SetName("FaultTreeIllustrationPoints"));

            var node = new IllustrationPointNode(FaultTreeIllustrationPointTestFactory.CreateTestFaultTreeIllustrationPointCombinationTypeAnd("A"));

            node.SetChildren(new[]
            {
                new IllustrationPointNode(new TestSubMechanismIllustrationPoint("B")),
                new IllustrationPointNode(FaultTreeIllustrationPointTestFactory.CreateTestFaultTreeIllustrationPointCombinationTypeAnd("C"))
            });

            yield return(new TestCaseData(new List <IllustrationPointNode>
            {
                new IllustrationPointNode(FaultTreeIllustrationPointTestFactory.CreateTestFaultTreeIllustrationPointCombinationTypeAnd("AA")),
                node
            }).SetName("FaultTreeIllustrationPointsWithChildren"));
        }
コード例 #13
0
        private static void AssertIllustrationPointEntities(
            IllustrationPointNode[] children,
            IEnumerable <SubMechanismIllustrationPointEntity> subMechanismIllustrationPointEntities,
            IEnumerable <FaultTreeIllustrationPointEntity> faultTreeIllustrationPointEntity
            )
        {
            for (var i = 0; i < children.Length; i++)
            {
                int nrOfTotalCreatedEntities = subMechanismIllustrationPointEntities.Count() + faultTreeIllustrationPointEntity.Count();
                Assert.AreEqual(nrOfTotalCreatedEntities, children.Length);

                IllustrationPointNode child = children[i];

                var subMechanismIllustrationPoint = child.Data as SubMechanismIllustrationPoint;
                if (subMechanismIllustrationPoint != null)
                {
                    SubMechanismIllustrationPointEntity illustrationPointEntity = subMechanismIllustrationPointEntities.Single(s => s.Order == i);
                    AssertSubMechanismIllustrationPointEntity(subMechanismIllustrationPoint, illustrationPointEntity);
                }

                var faultTreeIllustrationPoint = child.Data as FaultTreeIllustrationPoint;
                if (faultTreeIllustrationPoint != null)
                {
                    FaultTreeIllustrationPointEntity illustrationPointEntity = faultTreeIllustrationPointEntity.Single(f => f.Order == i);
                    AssertFaultTreeIllustrationPointEntity(faultTreeIllustrationPoint, illustrationPointEntity);

                    AssertIllustrationPointEntities(child.Children.ToArray(),
                                                    illustrationPointEntity.SubMechanismIllustrationPointEntities.ToArray(),
                                                    illustrationPointEntity.FaultTreeIllustrationPointEntity1.ToArray());
                }
            }
        }
コード例 #14
0
        public void SetChildren_ParentDoesNotContainSameStochastsAsChild_ThrowArgumentException()
        {
            // Setup
            var illustrationPointNode = new IllustrationPointNode(new FaultTreeIllustrationPoint("Top",
                                                                                                 0.0,
                                                                                                 new[]
            {
                new Stochast("Stochast A", 0, 0)
            },
                                                                                                 CombinationType.And));
            var childrenToBeAdded = new[]
            {
                new IllustrationPointNode(new TestFaultTreeIllustrationPoint(new[]
                {
                    new Stochast("Stochast B", 0, 0)
                })),
                new IllustrationPointNode(new TestFaultTreeIllustrationPoint("B"))
            };

            // Call
            TestDelegate test = () => illustrationPointNode.SetChildren(childrenToBeAdded);

            // Assert
            const string expectedMessage = "De stochasten van een illustratiepunt bevatten niet dezelfde stochasten als in de onderliggende illustratiepunten.";

            TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentException>(test, expectedMessage);
        }
コード例 #15
0
        public void Convert_TreeNodeWithChildren_ReturnIllustrationPointNode()
        {
            // Setup
            var nestedHydraRingIllustrationPointTreeNodes = new HydraRingIllustrationPointTreeNode(new TestHydraRingFaultTreeIllustrationPoint());

            nestedHydraRingIllustrationPointTreeNodes.SetChildren(new[]
            {
                new HydraRingIllustrationPointTreeNode(new TestHydraRingSubMechanismIllustrationPoint("Point A")),
                new HydraRingIllustrationPointTreeNode(new TestHydraRingSubMechanismIllustrationPoint("Point B"))
            });

            var hydraRingIllustrationPointRootTreeNode = new HydraRingIllustrationPointTreeNode(new TestHydraRingFaultTreeIllustrationPoint());

            hydraRingIllustrationPointRootTreeNode.SetChildren(new[]
            {
                new HydraRingIllustrationPointTreeNode(new TestHydraRingSubMechanismIllustrationPoint("Point C")),
                nestedHydraRingIllustrationPointTreeNodes
            });

            // Call
            IllustrationPointNode illustrationPointNode = IllustrationPointNodeConverter.Convert(hydraRingIllustrationPointRootTreeNode);

            // Assert
            IllustrationPointNode[] children = illustrationPointNode.Children.ToArray();
            Assert.AreEqual(2, children.Length);
            Assert.IsInstanceOf <SubMechanismIllustrationPoint>(children[0].Data);
            Assert.IsInstanceOf <FaultTreeIllustrationPoint>(children[1].Data);
            CollectionAssert.IsEmpty(children[0].Children);
            Assert.AreEqual(2, children[1].Children.Count());
        }
コード例 #16
0
        /// <summary>
        /// Creates a new instance of <see cref="IllustrationPointNode"/> based on the
        /// information of <paramref name="hydraRingIllustrationPointTreeNode"/>.
        /// </summary>
        /// <param name="hydraRingIllustrationPointTreeNode">The <see cref="HydraRingIllustrationPointTreeNode"/>
        /// to base the <see cref="IllustrationPointNode"/> to create on.</param>
        /// <returns>The created <see cref="IllustrationPointNode"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when
        /// <paramref name="hydraRingIllustrationPointTreeNode"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">Thrown when <paramref name="hydraRingIllustrationPointTreeNode"/>
        /// does not contain 0 or 2 children.</exception>
        /// <exception cref="IllustrationPointConversionException">Thrown when <paramref name="hydraRingIllustrationPointTreeNode"/>
        /// cannot be converted to a <see cref="IllustrationPointNode"/></exception>
        public static IllustrationPointNode Convert(HydraRingIllustrationPointTreeNode hydraRingIllustrationPointTreeNode)
        {
            if (hydraRingIllustrationPointTreeNode == null)
            {
                throw new ArgumentNullException(nameof(hydraRingIllustrationPointTreeNode));
            }

            IllustrationPointBase data;

            try
            {
                data = ConvertIllustrationPointTreeNodeData(hydraRingIllustrationPointTreeNode.Data);
            }
            catch (NotSupportedException e)
            {
                string errorMessage = "An illustration point containing a Hydra-Ring data type of " +
                                      $"{hydraRingIllustrationPointTreeNode.Data.GetType()} is not supported.";
                throw new IllustrationPointConversionException(errorMessage, e);
            }

            var illustrationPointNode = new IllustrationPointNode(data);

            illustrationPointNode.SetChildren(hydraRingIllustrationPointTreeNode.Children.Select(Convert).ToArray());

            return(illustrationPointNode);
        }
コード例 #17
0
        public void ConvertToGeneralResultTopLevelFaultTreeIllustrationPoint_HydraRingGeneralResultWithFaultTreeIllustrationPointsOnly_ExpectedProperties()
        {
            // Setup
            var random = new Random(21);

            const string closingSituation       = "Closing situation";
            var          hydraRingWindDirection = new HydraRingWindDirection("SSE", random.NextDouble());
            var          hydraRingWindDirectionClosingSituation = new HydraRingWindDirectionClosingSituation(
                hydraRingWindDirection,
                closingSituation);

            var hydraRingIllustrationPoint = new HydraRingFaultTreeIllustrationPoint(
                "IllustrationPoint",
                random.NextDouble(),
                Enumerable.Empty <HydraRingStochast>(),
                HydraRingCombinationType.Or);
            var hydraRingIllustrationTreeNode = new HydraRingIllustrationPointTreeNode(hydraRingIllustrationPoint);

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

            // Call
            GeneralResult <TopLevelFaultTreeIllustrationPoint> generalResult =
                GeneralResultConverter.ConvertToGeneralResultTopLevelFaultTreeIllustrationPoint(hydraRingGeneralResult);

            // Assert
            WindDirection generalResultGoverningWindDirection =
                generalResult.GoverningWindDirection;

            AssertWindDirection(governingHydraRingWindDirection, generalResultGoverningWindDirection);

            TopLevelFaultTreeIllustrationPoint topLevelFaultTreeIllustrationPoint =
                generalResult.TopLevelIllustrationPoints.Single();

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

            IllustrationPointNode faultTreeIllustrationPoint =
                topLevelFaultTreeIllustrationPoint.FaultTreeNodeRoot;

            CollectionAssert.IsEmpty(faultTreeIllustrationPoint.Children);

            var faultTreeIllustrationPointData = (FaultTreeIllustrationPoint)faultTreeIllustrationPoint.Data;

            CollectionAssert.IsEmpty(faultTreeIllustrationPointData.Stochasts);
            Assert.AreEqual(hydraRingIllustrationPoint.Name, faultTreeIllustrationPointData.Name);
            Assert.AreEqual(hydraRingIllustrationPoint.Beta, faultTreeIllustrationPointData.Beta,
                            faultTreeIllustrationPointData.Beta.GetAccuracy());
            Assert.AreEqual(CombinationType.Or, faultTreeIllustrationPointData.CombinationType);
        }
コード例 #18
0
        public void Constructor_ValidArguments_ReturnExpectedValues()
        {
            // Setup
            var data = new TestIllustrationPoint();

            // Call
            var illustrationPointNode = new IllustrationPointNode(data);

            // Assert
            Assert.IsInstanceOf <ICloneable>(illustrationPointNode);
            Assert.AreSame(data, illustrationPointNode.Data);
            CollectionAssert.IsEmpty(illustrationPointNode.Children);
        }
コード例 #19
0
        public void Constructor_WindDirectionNameNull_ThrowsArgumentNullException()
        {
            // Setup
            var node = new IllustrationPointNode(new TestFaultTreeIllustrationPoint());

            // Call
            TestDelegate test = () => new IllustrationPointNodeContext(node, null, "");

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

            Assert.AreEqual("windDirectionName", exception.ParamName);
        }
コード例 #20
0
        /// <summary>
        /// Reads the <see cref="FaultTreeIllustrationPointEntity"/> and uses
        /// the information to construct a <see cref="IllustrationPointNode"/>.
        /// </summary>
        /// <param name="entity">The <see cref="FaultTreeIllustrationPointEntity"/>
        /// to create a <see cref="IllustrationPointNode"/> for.</param>
        /// <returns>A new <see cref="IllustrationPointNode"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="entity"/>
        /// is <c>null</c>.</exception>
        public static IllustrationPointNode Read(this FaultTreeIllustrationPointEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            var node = new IllustrationPointNode(GetFaultTreeIllustrationPoint(entity));

            node.SetChildren(GetChildren(entity).ToArray());

            return(node);
        }
コード例 #21
0
        public void SetChildren_ChildrenNull_ThrowsArgumentNullException()
        {
            // Setup
            var illustrationPointNode = new IllustrationPointNode(new TestIllustrationPoint());

            // Call
            TestDelegate call = () => illustrationPointNode.SetChildren(null);

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

            Assert.AreEqual("children", exception.ParamName);
        }
コード例 #22
0
        /// <summary>
        /// Reads the <see cref="TopLevelFaultTreeIllustrationPointEntity"/> and
        /// uses the information to construct a <see cref="TopLevelFaultTreeIllustrationPoint"/>.
        /// </summary>
        /// <param name="entity">The <see cref="TopLevelFaultTreeIllustrationPointEntity"/>
        /// to create a <see cref="TopLevelFaultTreeIllustrationPoint"/> for.</param>
        /// <returns>A new <see cref="TopLevelFaultTreeIllustrationPoint"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="entity"/>
        /// is <c>null</c>.</exception>
        public static TopLevelFaultTreeIllustrationPoint Read(this TopLevelFaultTreeIllustrationPointEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            WindDirection windDirection = GetWindDirection(entity);

            IllustrationPointNode node = entity.FaultTreeIllustrationPointEntity.Read();

            return(new TopLevelFaultTreeIllustrationPoint(windDirection, entity.ClosingSituation, node));
        }
コード例 #23
0
        public void Create_IllustrationPointNodeWithSubMechanismIllustrationPoint_ThrowsNotSupportedException()
        {
            // Setup
            var node = new IllustrationPointNode(new TestSubMechanismIllustrationPoint());

            // Call
            TestDelegate call = () => node.Create(0);

            // Assert
            string message = Assert.Throws <NotSupportedException>(call).Message;

            Assert.AreEqual($"Illustration point type '{typeof(TestSubMechanismIllustrationPoint)}' is not supported.", message);
        }
コード例 #24
0
        public void Constructor_ClosingSituationNull_ThrowsArgumentNullException()
        {
            // Setup
            var node = new IllustrationPointNode(new TestFaultTreeIllustrationPoint());

            // Call
            TestDelegate test = () => new IllustrationPointContext <IllustrationPointBase>(new TestFaultTreeIllustrationPoint(), node, "", null);

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

            Assert.AreEqual("closingSituation", exception.ParamName);
        }
コード例 #25
0
        /// <summary>
        /// Creates a new <see cref="GraphNode"/> based on the <paramref name="node"/> and registers
        /// the <paramref name="node"/> and <see cref="GraphNode"/> combination.
        /// </summary>
        /// <param name="node">The node to base the <see cref="GraphNode"/> on.</param>
        /// <returns>The newly created <see cref="GraphNode"/>.</returns>
        /// <exception cref="NotSupportedException">Thrown when <paramref name="node.Data"/> or any of its children
        /// is not of type <see cref="FaultTreeIllustrationPoint"/> or <see cref="SubMechanismIllustrationPoint"/>.</exception>
        private GraphNode RegisterNode(IllustrationPointNode node)
        {
            GraphNode[] childNodes = node.Children.Select(RegisterNode).ToArray();

            GraphNode graphNode = RiskeerGraphNodeFactory.CreateGraphNode(node.Data, childNodes);

            drawnNodes.Add(new DrawnIllustrationPointNode
            {
                IllustrationPointNode = node,
                GraphNode             = graphNode
            });

            return(graphNode);
        }
コード例 #26
0
        private static void AssertSubMechanismIllustrationPointNode(SubMechanismIllustrationPointEntity entity,
                                                                    IllustrationPointNode node)
        {
            var illustrationPoint = node.Data as SubMechanismIllustrationPoint;

            Assert.IsNotNull(illustrationPoint);
            Assert.AreEqual(entity.Name, illustrationPoint.Name);
            Assert.AreEqual(entity.Beta, illustrationPoint.Beta, illustrationPoint.Beta.GetAccuracy());
            AssertStochasts(entity.SubMechanismIllustrationPointStochastEntities.ToArray(), illustrationPoint.Stochasts.ToArray());

            CollectionAssert.IsEmpty(illustrationPoint.Stochasts);
            CollectionAssert.IsEmpty(illustrationPoint.IllustrationPointResults);
            CollectionAssert.IsEmpty(node.Children);
        }
コード例 #27
0
        private static void AssertFaultTreeIllustrationPointNode(FaultTreeIllustrationPointEntity entity,
                                                                 IllustrationPointNode node)
        {
            var illustrationPoint = node.Data as FaultTreeIllustrationPoint;

            Assert.IsNotNull(illustrationPoint);
            Assert.AreEqual(entity.Name, illustrationPoint.Name);
            Assert.AreEqual(entity.Beta, illustrationPoint.Beta, illustrationPoint.Beta.GetAccuracy());
            Assert.AreEqual((CombinationType)entity.CombinationType, illustrationPoint.CombinationType);
            AssertStochasts(entity.StochastEntities.ToArray(), illustrationPoint.Stochasts.ToArray());

            AssertIllustrationPointNodes(entity.FaultTreeIllustrationPointEntity1, node.Children);
            AssertIllustrationPointNodes(entity.SubMechanismIllustrationPointEntities, node.Children);
        }
        public void CreateInstance_ValidArguments_ReturnFaultTreeIllustrationPointBaseProperties()
        {
            // Setup
            var illustrationPoint     = new TestSubMechanismIllustrationPoint();
            var illustrationPointNode = new IllustrationPointNode(illustrationPoint);
            var context = new IllustrationPointContext <SubMechanismIllustrationPoint>(illustrationPoint, illustrationPointNode,
                                                                                       "Wind direction", "Closing situation");

            // Call
            IObjectProperties objectProperties = info.CreateInstance(context);

            // Assert
            Assert.IsInstanceOf <SubMechanismIllustrationPointProperties>(objectProperties);
            Assert.AreSame(illustrationPoint, objectProperties.Data);
        }
コード例 #29
0
        public void Constructor_WindDirectionNull_ThrowsArgumentNullException()
        {
            // Setup
            var faultTreeNode = new IllustrationPointNode(new TestIllustrationPoint());

            // Call
            TestDelegate call = () => new TopLevelFaultTreeIllustrationPoint(null,
                                                                             "closing situation",
                                                                             faultTreeNode);

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

            Assert.AreEqual("windDirection", exception.ParamName);
        }
コード例 #30
0
        public void SetChildren_ValidNrOfChildren_ReturnsExpectedProperties(int nrOfChildren)
        {
            // Setup
            var illustrationPointNode = new IllustrationPointNode(new TestIllustrationPoint());
            var childrenToBeAdded     = new IllustrationPointNode[nrOfChildren];

            // Call
            illustrationPointNode.SetChildren(childrenToBeAdded);

            // Assert
            IEnumerable <IllustrationPointNode> addedChildren = illustrationPointNode.Children;

            Assert.AreSame(childrenToBeAdded, addedChildren);
            Assert.AreEqual(nrOfChildren, addedChildren.Count());
        }