private Dictionary <WindDirectionClosingSituation, IllustrationPointTreeNode> ParseFaultTree(HydraRingDatabaseReader reader) { IEnumerable <Tuple <int, WindDirection, int, string> > windDirectionClosingSituations = GetAllWindDirectionClosingSituationCombinations(); Dictionary <string, object>[] readFaultTrees = GetIterator(reader).ToArray(); if (readFaultTrees.Length > 0) { IEnumerable <Tuple <int?, int, Type, CombinationType> > results = CreateResultTuples(readFaultTrees); var rootIllustrationPoints = new Dictionary <WindDirectionClosingSituation, IllustrationPointTreeNode>(); foreach (Tuple <int, WindDirection, int, string> windDirectionClosingSituation in windDirectionClosingSituations) { Tuple <int?, int, Type, CombinationType> root = results.Single(r => !r.Item1.HasValue); IllustrationPointTreeNode illustrationPointTreeNode = BuildFaultTree(windDirectionClosingSituation, root.Item2, root.Item4, results); if (illustrationPointTreeNode != null) { rootIllustrationPoints[CreateFaultTreeKey(windDirectionClosingSituation)] = illustrationPointTreeNode; } } return(rootIllustrationPoints); } return(null); }
private IllustrationPointTreeNode BuildFaultTree( Tuple <int, WindDirection, int, string> windDirectionClosingSituation, int faultTreeId, CombinationType combinationType, IEnumerable <Tuple <int?, int, Type, CombinationType> > results) { var dataKey = new ThreeKeyIndex(windDirectionClosingSituation.Item1, windDirectionClosingSituation.Item3, faultTreeId); var faultTreeIllustrationPointStochasts = new List <Stochast>(); if (!faultTreeBetaValues.ContainsKey(dataKey)) { return(null); } if (faultTreeStochasts.ContainsKey(dataKey)) { AddRange(faultTreeIllustrationPointStochasts, faultTreeStochasts[dataKey]); } var illustrationPoint = new FaultTreeIllustrationPoint(faultTrees[faultTreeId], faultTreeBetaValues[dataKey], faultTreeIllustrationPointStochasts, combinationType); var node = new IllustrationPointTreeNode(illustrationPoint); node.SetChildren(results.Where(r => r.Item1 == faultTreeId) .Select(child => child.Item3 == typeof(FaultTreeIllustrationPoint) ? BuildFaultTree(windDirectionClosingSituation, child.Item2, child.Item4, results) : BuildSubMechanism(windDirectionClosingSituation, child.Item2)).ToArray()); return(node); }
public void Constructor_WithData_DataIsAssigned() { // Setup var mocks = new MockRepository(); var data = mocks.Stub <IIllustrationPoint>(); mocks.ReplayAll(); // Call var node = new IllustrationPointTreeNode(data); // Assert Assert.AreSame(data, node.Data); CollectionAssert.IsEmpty(node.Children); mocks.VerifyAll(); }
private static void GetAllNodes(IllustrationPointTreeNode tree, ICollection <FaultTreeIllustrationPoint> faultTrees, ICollection <SubMechanismIllustrationPoint> subMechanisms) { var subMechanism = tree.Data as SubMechanismIllustrationPoint; var faultTree = tree.Data as FaultTreeIllustrationPoint; if (subMechanism != null) { subMechanisms.Add(subMechanism); } else if (faultTree != null) { faultTrees.Add(faultTree); } foreach (IllustrationPointTreeNode child in tree.Children) { GetAllNodes(child, faultTrees, subMechanisms); } }
private Dictionary <WindDirectionClosingSituation, IllustrationPointTreeNode> GetSubMechanismAsRootIllustrationPoint() { var rootIllustrationPoints = new Dictionary <WindDirectionClosingSituation, IllustrationPointTreeNode>(); int subMechanismId = subMechanisms.First().Key; foreach (Tuple <int, WindDirection, int, string> windDirectionClosingSituation in GetAllWindDirectionClosingSituationCombinations()) { IllustrationPointTreeNode illustrationPointTreeNode = BuildSubMechanism( windDirectionClosingSituation, subMechanismId); if (illustrationPointTreeNode != null) { rootIllustrationPoints[CreateFaultTreeKey(windDirectionClosingSituation)] = illustrationPointTreeNode; } } return(rootIllustrationPoints); }
public void SetChildren_ChildrenNull_ThrowsArgumentNullException() { // Setup var mocks = new MockRepository(); var data = mocks.Stub <IIllustrationPoint>(); mocks.ReplayAll(); var treeNode = new IllustrationPointTreeNode(data); // Call TestDelegate call = () => treeNode.SetChildren(null); // Assert var exception = Assert.Throws <ArgumentNullException>(call); Assert.AreEqual("children", exception.ParamName); mocks.VerifyAll(); }
public void SetChildren_ValidNrOfChildren_ReturnsExpectedProperties(int nrOfChildren) { // Setup var mocks = new MockRepository(); var data = mocks.Stub <IIllustrationPoint>(); mocks.ReplayAll(); var treeNode = new IllustrationPointTreeNode(data); var childrenToBeAttached = new IllustrationPointTreeNode[nrOfChildren]; // Call treeNode.SetChildren(childrenToBeAttached); // Assert IEnumerable <IllustrationPointTreeNode> addedChildren = treeNode.Children; Assert.AreSame(childrenToBeAttached, addedChildren); Assert.AreEqual(nrOfChildren, addedChildren.Count()); mocks.VerifyAll(); }
public void SetChildren_InvalidNrOfChildren_ThrowsInvalidArgumentException(int nrOfChildren) { // Setup var mocks = new MockRepository(); var data = mocks.Stub <IIllustrationPoint>(); mocks.ReplayAll(); var treeNode = new IllustrationPointTreeNode(data); var childrenToBeAttached = new IllustrationPointTreeNode[nrOfChildren]; // Call TestDelegate call = () => treeNode.SetChildren(childrenToBeAttached); // Assert const string expectedMessage = "Een illustratiepunt node in de foutenboom moet 0 of 2 onderliggende nodes hebben."; var exception = TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentException>(call, expectedMessage); Assert.AreEqual("children", exception.ParamName); CollectionAssert.IsEmpty(treeNode.Children); mocks.VerifyAll(); }