Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
 private static void AssertFaultTreeIllustrationPointEntity(FaultTreeIllustrationPoint illustrationPoint,
                                                            FaultTreeIllustrationPointEntity illustrationPointEntity)
 {
     Assert.IsNotNull(illustrationPoint);
     Assert.AreEqual(illustrationPoint.Beta, illustrationPointEntity.Beta, illustrationPoint.Beta.GetAccuracy());
     Assert.AreEqual(Convert.ToByte(illustrationPoint.CombinationType), illustrationPointEntity.CombinationType);
     TestHelper.AssertAreEqualButNotSame(illustrationPoint.Name, illustrationPointEntity.Name);
     CollectionAssert.IsEmpty(illustrationPointEntity.StochastEntities);
 }
        /// <summary>
        /// Creates a new instance of <see cref="FaultTreeIllustrationPointProperties"/>.
        /// </summary>
        /// <param name="illustrationPoint">The fault tree illustration point to use for the properties.</param>
        /// <param name="childNodes">The child nodes that belongs to the <paramref name="illustrationPoint"/>.</param>
        /// <param name="windDirection">The wind direction of the illustration point.</param>
        /// <param name="closingSituation">The closing situation of the illustration point.</param>
        /// <exception cref="ArgumentNullException">Thrown when any input parameter is <c>null</c>.</exception>
        public FaultTreeIllustrationPointProperties(FaultTreeIllustrationPoint illustrationPoint, IEnumerable <IllustrationPointNode> childNodes,
                                                    string windDirection, string closingSituation)
            : base(illustrationPoint, windDirection, closingSituation)
        {
            if (childNodes == null)
            {
                throw new ArgumentNullException(nameof(childNodes));
            }

            faultTreeIllustrationPoint = illustrationPoint;
            this.childNodes            = childNodes;
        }
Exemplo n.º 9
0
        /// <summary>
        /// Creates a new instance of <see cref="GraphNode"/>, based on the properties of <paramref name="illustrationPoint"/>.
        /// </summary>
        /// <param name="illustrationPoint">The <see cref="FaultTreeIllustrationPoint"/> to base the
        /// <see cref="GraphNode"/> to create on.</param>
        /// <param name="childNodes">The child graph nodes of the <see cref="GraphNode"/> to create.</param>
        /// <returns>The created <see cref="GraphNode"/>.</returns>
        private static GraphNode CreateFaultTreeGraphNode(FaultTreeIllustrationPoint illustrationPoint,
                                                          IEnumerable <GraphNode> childNodes)
        {
            string childRelationTitle = illustrationPoint.CombinationType == CombinationType.And
                                            ? Resources.GraphNode_CombinationType_And
                                            : Resources.GraphNode_CombinationType_Or;
            GraphNode connectionGraphNode = CreateConnectingGraphNode(childRelationTitle, childNodes);

            return(CreateCompositeGraphNode(
                       illustrationPoint.Name,
                       CreateGraphNodeContent(illustrationPoint.Beta),
                       new[]
            {
                connectionGraphNode
            }));
        }
        private static FaultTreeIllustrationPointEntity CreateFaultTreeIllustrationPoint(
            FaultTreeIllustrationPoint illustrationPoint,
            int order)
        {
            var entity = new FaultTreeIllustrationPointEntity
            {
                Beta            = illustrationPoint.Beta,
                CombinationType = Convert.ToByte(illustrationPoint.CombinationType),
                Name            = illustrationPoint.Name.DeepClone(),
                Order           = order
            };

            AddEntitiesForStochasts(entity, illustrationPoint.Stochasts);

            return(entity);
        }
Exemplo n.º 11
0
        public void Constructor_ValidArguments_ReturnsExpectedValues(CombinationType combinationType)
        {
            // Setup
            const string name = "Fault tree illustration point name";

            var    random = new Random(21);
            double beta   = random.NextDouble();

            IEnumerable <Stochast> stochasts = Enumerable.Empty <Stochast>();

            // Call
            var illustrationPoint = new FaultTreeIllustrationPoint(name, beta, stochasts, combinationType);

            // Assert
            Assert.IsInstanceOf <IllustrationPointBase>(illustrationPoint);
            Assert.AreEqual(name, illustrationPoint.Name);
            Assert.AreSame(stochasts, illustrationPoint.Stochasts);
            Assert.AreEqual(beta, illustrationPoint.Beta, illustrationPoint.Beta.GetAccuracy());
            Assert.AreEqual(combinationType, illustrationPoint.CombinationType);
        }
        public void Constructor_WithValidParameter_ReturnsNewInstance()
        {
            // Setup
            var                    random          = new Random(123);
            const string           name            = "name";
            double                 beta            = random.NextDouble();
            var                    combinationType = random.NextEnumValue <CombinationType>();
            IEnumerable <Stochast> stochasts       = Enumerable.Empty <Stochast>();

            // Call
            var illustrationPoint = new FaultTreeIllustrationPoint(name, beta, stochasts, combinationType);

            // Assert
            Assert.IsInstanceOf <IIllustrationPoint>(illustrationPoint);
            Assert.AreEqual(name, illustrationPoint.Name);
            CollectionAssert.IsEmpty(illustrationPoint.Stochasts);
            Assert.AreEqual(beta, illustrationPoint.Beta);
            Assert.AreEqual(combinationType, illustrationPoint.CombinationType);
            Assert.AreSame(stochasts, illustrationPoint.Stochasts);
        }
Exemplo n.º 13
0
        public void Clone_Always_ReturnNewInstanceWithCopiedValues()
        {
            // Setup
            var random   = new Random(21);
            var original = new FaultTreeIllustrationPoint("Random name",
                                                          random.NextDouble(),
                                                          new[]
            {
                new Stochast("Random name 1",
                             random.NextDouble(),
                             random.NextDouble()),
                new Stochast("Random name 2",
                             random.NextDouble(),
                             random.NextDouble())
            },
                                                          random.NextEnumValue <CombinationType>());

            // Call
            object clone = original.Clone();

            // Assert
            CoreCloneAssert.AreObjectClones(original, clone, CommonCloneAssert.AreClones);
        }
Exemplo n.º 14
0
 /// <summary>
 /// Method that asserts whether <paramref name="original"/> and <paramref name="clone"/>
 /// are clones.
 /// </summary>
 /// <param name="original">The original object.</param>
 /// <param name="clone">The cloned object.</param>
 /// <exception cref="AssertionException">Thrown when <paramref name="original"/> and
 /// <paramref name="clone"/> are not clones.</exception>
 public static void AreClones(FaultTreeIllustrationPoint original, FaultTreeIllustrationPoint clone)
 {
     AreClones((IllustrationPointBase)original, clone);
     CoreCloneAssert.AreEnumerationClones(original.Stochasts, clone.Stochasts, AreClones);
     Assert.AreEqual(original.CombinationType, clone.CombinationType);
 }
        public void Parse_ValidStructuresStabilityData_SetsOutputAsExpected()
        {
            // Setup
            string path   = Path.Combine(testDirectory, "ValidStructuresStabilityOutputSection1");
            var    parser = new IllustrationPointsParser();

            // Call
            parser.Parse(path, 1);

            // Assert
            GeneralResult generalResult = parser.Output;

            Assert.NotNull(generalResult);
            Assert.NotNull(generalResult.GoverningWindDirection);
            Assert.AreEqual(30, generalResult.GoverningWindDirection.Angle);
            Assert.AreEqual(" 30", generalResult.GoverningWindDirection.Name);
            Assert.AreEqual(-3.74187, generalResult.Beta);
            Assert.AreEqual(44, generalResult.Stochasts.Count());

            Dictionary <WindDirectionClosingSituation, IllustrationPointTreeNode> illustrationPointNodes = generalResult.IllustrationPoints;

            Assert.AreEqual(12, illustrationPointNodes.Count);
            CollectionAssert.AllItemsAreInstancesOfType(illustrationPointNodes.Values.Select(ip => ip.Data), typeof(FaultTreeIllustrationPoint));

            ICollection <FaultTreeIllustrationPoint>    faultTrees    = new List <FaultTreeIllustrationPoint>();
            ICollection <SubMechanismIllustrationPoint> subMechanisms = new List <SubMechanismIllustrationPoint>();

            GetAllNodes(illustrationPointNodes.Values.First(), faultTrees, subMechanisms);

            Assert.AreEqual(11, faultTrees.Count);
            Assert.AreEqual(new[]
            {
                CombinationType.Or,
                CombinationType.Or,
                CombinationType.And,
                CombinationType.And,
                CombinationType.Or,
                CombinationType.And,
                CombinationType.And,
                CombinationType.And,
                CombinationType.Or,
                CombinationType.And,
                CombinationType.And
            }, faultTrees.Select(f => f.CombinationType));

            Assert.AreEqual(12, subMechanisms.Count);
            SubMechanismIllustrationPoint subMechanismIllustrationPoint = subMechanisms.First();

            Assert.AreEqual("Bezwijken kunstwerk als gevolg van erosie bodem", subMechanismIllustrationPoint.Name);
            Assert.AreEqual(-7.94268, subMechanismIllustrationPoint.Beta);
            Assert.AreEqual(new[]
            {
                Tuple.Create("Faalkans gegeven erosie bodem", -1.0, 4383.0, -7.94268)
            }, subMechanismIllustrationPoint.Stochasts.Select(s => Tuple.Create(s.Name, s.Alpha, s.Duration, s.Realization)));
            CollectionAssert.IsEmpty(subMechanismIllustrationPoint.Results);

            FaultTreeIllustrationPoint faultTreeIllustrationPoint = faultTrees.First();

            Assert.AreEqual("Bezwijken kunstwerk als gevolg van erosie bodem", subMechanismIllustrationPoint.Name);
            Assert.AreEqual(0.508398, faultTreeIllustrationPoint.Beta);
            Assert.AreEqual(CombinationType.Or, faultTreeIllustrationPoint.CombinationType);
            Assert.AreEqual(44, faultTreeIllustrationPoint.Stochasts.Count());
            Assert.AreEqual(new[]
            {
                Tuple.Create("Kerende hoogte", 0.0, 4383.0),
                Tuple.Create("Modelfactor voor onvolkomen stroming", 0.0, 4383.0),
                Tuple.Create("Drempelhoogte", 0.0, 4383.0),
                Tuple.Create("Afvoercoefficient", -3.91812E-07, 4383.0),
                Tuple.Create("Doorstroomoppervlak", 3.93695E-08, 4383.0),
                Tuple.Create("Lineaire belastingschematisering constructieve sterkte", 0.214064, 4383.0)
            }, faultTreeIllustrationPoint.Stochasts.Take(6).Select(s => Tuple.Create(s.Name, s.Alpha, s.Duration)));
        }
        public void Constructor_ExpectedValues()
        {
            // Setup
            var stochast          = new Stochast("Stochast A", 10.0, 2.5);
            var illustrationPoint = new FaultTreeIllustrationPoint("Fault tree Test",
                                                                   1.5,
                                                                   new[]
            {
                stochast
            },
                                                                   CombinationType.And);
            var illustrationPointNodeChild1 = new IllustrationPointNode(new FaultTreeIllustrationPoint("Fault tree child",
                                                                                                       3.5,
                                                                                                       new[]
            {
                stochast
            },
                                                                                                       CombinationType.Or));
            var illustrationPointNodeChild2 = new IllustrationPointNode(new FaultTreeIllustrationPoint("Fault tree child 2",
                                                                                                       3.5,
                                                                                                       new Stochast[0],
                                                                                                       CombinationType.Or));

            IllustrationPointNode[] illustrationPointNodeChildren =
            {
                illustrationPointNodeChild1,
                illustrationPointNodeChild2
            };

            // Call
            var properties = new FaultTreeIllustrationPointProperties(illustrationPoint, illustrationPointNodeChildren, "NNE", "closing situation");

            // Assert
            Assert.IsInstanceOf <IllustrationPointProperties>(properties);
            PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties);

            PropertyDescriptor alphasProperty = dynamicProperties[alphasPropertyIndex];

            Assert.NotNull(alphasProperty.Attributes[typeof(KeyValueElementAttribute)]);

            PropertyDescriptor durationsProperty = dynamicProperties[durationsPropertyIndex];

            Assert.NotNull(durationsProperty.Attributes[typeof(KeyValueElementAttribute)]);

            Assert.AreEqual("NNE", properties.WindDirection);
            Assert.AreEqual(illustrationPoint.Beta, properties.Reliability, properties.Reliability.GetAccuracy());
            Assert.AreEqual(5, properties.Reliability.NumberOfDecimalPlaces);
            Assert.AreEqual(StatisticsConverter.ReliabilityToProbability(illustrationPoint.Beta), properties.CalculatedProbability);
            Assert.AreEqual("closing situation", properties.ClosingSituation);

            TestHelper.AssertTypeConverter <FaultTreeIllustrationPointProperties, KeyValueExpandableArrayConverter>(
                nameof(FaultTreeIllustrationPointProperties.AlphaValues));
            CollectionAssert.IsNotEmpty(properties.AlphaValues);
            CollectionAssert.AreEqual(new[]
            {
                stochast
            }, properties.AlphaValues);

            TestHelper.AssertTypeConverter <FaultTreeIllustrationPointProperties, KeyValueExpandableArrayConverter>(
                nameof(FaultTreeIllustrationPointProperties.Durations));
            CollectionAssert.AreEqual(new[]
            {
                stochast
            }, properties.Durations);

            TestHelper.AssertTypeConverter <FaultTreeIllustrationPointProperties, ExpandableArrayConverter>(
                nameof(FaultTreeIllustrationPointProperties.IllustrationPoints));
            Assert.AreEqual(2, properties.IllustrationPoints.Length);
            Assert.AreSame(illustrationPointNodeChild1.Data, properties.IllustrationPoints.ElementAt(0).Data);
            Assert.AreSame(illustrationPointNodeChild2.Data, properties.IllustrationPoints.ElementAt(1).Data);
        }