public void CreateGraphNode_FaultTreeIllustrationPointNodeDataWithChildren_ReturnsExpectedGraphNodeContent(double probability, string expectedProbability) { // Setup var random = new Random(31); double beta = StatisticsConverter.ProbabilityToReliability(probability); var illustrationPoint = new FaultTreeIllustrationPoint( "Illustration Point", beta, Enumerable.Empty <Stochast>(), random.NextEnumValue <CombinationType>()); IEnumerable <GraphNode> childGraphNodes = new[] { CreateTestGraphNode() }; RoundedDouble roundedBeta = ((RoundedDouble)beta).ToPrecision(5); string expectedGraphNodeContent = $"<text><bold>{illustrationPoint.Name}</bold>{Environment.NewLine}" + $"{Environment.NewLine}" + $"Berekende kans = {expectedProbability}{Environment.NewLine}" + $"Betrouwbaarheidsindex = {roundedBeta}</text>"; // Call GraphNode graphNode = RiskeerGraphNodeFactory.CreateGraphNode(illustrationPoint, childGraphNodes); // Assert Assert.AreEqual(expectedGraphNodeContent, graphNode.Content); }
public void CreateGraphNode_FaultTreeIllustrationPointNodeDataWithoutChildren_ReturnsExpected() { // Setup var random = new Random(31); var illustrationPoint = new FaultTreeIllustrationPoint( "Illustration Point", random.NextRoundedDouble(), Enumerable.Empty <Stochast>(), random.NextEnumValue <CombinationType>()); // Call GraphNode graphNode = RiskeerGraphNodeFactory.CreateGraphNode(illustrationPoint, Enumerable.Empty <GraphNode>()); // Assert Assert.AreEqual(CreateExpectedGraphNodeContent(illustrationPoint.Name, illustrationPoint.Beta), graphNode.Content); Assert.IsTrue(graphNode.IsSelectable); var expectedStyle = new GraphNodeStyle(GraphNodeShape.Rectangle, Color.LightGray, Color.Black, 1); AssertEqualStyle(expectedStyle, graphNode.Style); Assert.AreEqual(1, graphNode.ChildNodes.Count()); GraphNode connectingNode = graphNode.ChildNodes.First(); AssertGraphConnectingNode(CreateExpectedGraphConnectingNodeContent(illustrationPoint.CombinationType), connectingNode); CollectionAssert.IsEmpty(connectingNode.ChildNodes); }
public void CreateGraphNode_IllustrationPointNull_ThrowsArgumentNullException() { // Call void Call() => RiskeerGraphNodeFactory.CreateGraphNode(null, Enumerable.Empty <GraphNode>()); // Assert var exception = Assert.Throws <ArgumentNullException>(Call); Assert.AreEqual("illustrationPoint", exception.ParamName); }
public void CreateGraphNode_WithFaultTreeIllustrationPointButChildrenNull_ThrowsArgumentNullException() { // Setup var illustrationPoint = new TestFaultTreeIllustrationPoint(); // Call void Call() => RiskeerGraphNodeFactory.CreateGraphNode(illustrationPoint, null); // Assert var exception = Assert.Throws <ArgumentNullException>(Call); Assert.AreEqual("childNodes", exception.ParamName); }
/// <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); }
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 CreateGraphNode_WithNotSupportedIllustrationPoint_ThrowsNotSupportedException() { // Setup var illustrationPoint = new TestIllustrationPoint(); // Call void Call() => RiskeerGraphNodeFactory.CreateGraphNode(illustrationPoint, new[] { CreateTestGraphNode() }); // Assert var exception = Assert.Throws <NotSupportedException>(Call); Assert.AreEqual($"IllustrationPointNode of type {illustrationPoint.GetType().Name} is not supported. " + $"Supported types: {nameof(FaultTreeIllustrationPoint)} and {nameof(SubMechanismIllustrationPoint)}", exception.Message); }
public void CreateGraphNode_WithSubMechanismIllustrationPointEmptyChildren_ReturnsGraphNodeWithExpectedStyling() { // Setup var illustrationPoint = new SubMechanismIllustrationPoint( "Illustration Point", new Random(31).NextRoundedDouble(), Enumerable.Empty <SubMechanismIllustrationPointStochast>(), Enumerable.Empty <IllustrationPointResult>()); // Call GraphNode graphNode = RiskeerGraphNodeFactory.CreateGraphNode(illustrationPoint, new[] { CreateTestGraphNode() }); // Assert Assert.AreEqual(CreateExpectedGraphNodeContent(illustrationPoint.Name, illustrationPoint.Beta), graphNode.Content); Assert.IsTrue(graphNode.IsSelectable); CollectionAssert.IsEmpty(graphNode.ChildNodes); var expectedStyle = new GraphNodeStyle(GraphNodeShape.Rectangle, Color.SkyBlue, Color.Black, 1); AssertEqualStyle(expectedStyle, graphNode.Style); }