Beispiel #1
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);
        }
Beispiel #2
0
 private static void AssertStochast(StochastEntity stochastEntity,
                                    Stochast readStochast)
 {
     Assert.AreEqual(stochastEntity.Name, readStochast.Name);
     Assert.AreEqual(stochastEntity.Alpha, readStochast.Alpha, readStochast.Alpha.GetAccuracy());
     Assert.AreEqual(stochastEntity.Duration, readStochast.Duration, readStochast.Duration.GetAccuracy());
 }
Beispiel #3
0
        public void GetProperties_WithData_ReturnExpectedValues()
        {
            // Setup
            PartialProbabilisticFaultTreePipingOutput output = PipingTestDataGenerator.GetRandomPartialProbabilisticFaultTreePipingOutput();

            // Call
            var properties = new ProbabilisticFaultTreePipingOutputProperties(output);

            // Assert
            Assert.AreEqual(ProbabilityFormattingHelper.Format(StatisticsConverter.ReliabilityToProbability(output.Reliability)), properties.Probability);
            Assert.AreEqual(output.Reliability, properties.Reliability, properties.Reliability.GetAccuracy());

            GeneralResult <TopLevelFaultTreeIllustrationPoint> generalResult = output.GeneralResult;

            Assert.AreEqual(generalResult.GoverningWindDirection.Name, properties.WindDirection);

            int nrOfExpectedStochasts = generalResult.Stochasts.Count();

            Assert.AreEqual(nrOfExpectedStochasts, properties.AlphaValues.Length);
            Assert.AreEqual(nrOfExpectedStochasts, properties.Durations.Length);
            Stochast expectedStochast = generalResult.Stochasts.First();

            Assert.AreEqual(expectedStochast.Alpha, properties.AlphaValues[0].Alpha);
            Assert.AreEqual(expectedStochast.Duration, properties.Durations[0].Duration);

            int nrOfExpectedTopLevelIllustrationPoints = generalResult.TopLevelIllustrationPoints.Count();

            Assert.AreEqual(nrOfExpectedTopLevelIllustrationPoints, properties.IllustrationPoints.Length);

            CollectionAssert.AreEqual(generalResult.TopLevelIllustrationPoints, properties.IllustrationPoints.Select(i => i.Data));
        }
Beispiel #4
0
    void Start()
    {
        targetLevel = transform.position.y;

        random = new Stochast();

        initialize();
        generate();
    }
        private static void AssertStochastEntity(Stochast stochast,
                                                 StochastEntity stochastEntity,
                                                 int expectedOrder)
        {
            TestHelper.AssertAreEqualButNotSame(stochast.Name, stochastEntity.Name);
            Assert.AreEqual(stochast.Duration, stochastEntity.Duration, stochast.Duration.GetAccuracy());
            Assert.AreEqual(stochast.Alpha, stochastEntity.Alpha, stochast.Alpha.GetAccuracy());

            Assert.AreEqual(expectedOrder, stochastEntity.Order);
        }
Beispiel #6
0
        public void Clone_Always_ReturnNewInstanceWithCopiedValues()
        {
            // Setup
            var random   = new Random(21);
            var original = new Stochast("Random name", random.NextDouble(), random.NextDouble());

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

            // Assert
            CoreCloneAssert.AreObjectClones(original, clone, CommonCloneAssert.AreClones);
        }
        public void GetProperties_WithData_ReturnExpectedValues()
        {
            // Setup
            var    random                = new Random(39);
            double waveHeight            = random.NextDouble();
            bool   isOvertoppingDominant = random.NextBoolean();
            double reliability           = random.NextDouble();

            var generalResult = new TestGeneralResultFaultTreeIllustrationPoint();

            var overtoppingOutput = new OvertoppingOutput(waveHeight,
                                                          isOvertoppingDominant,
                                                          reliability,
                                                          generalResult);

            // Call
            var properties = new OvertoppingOutputProperties(overtoppingOutput);

            // Assert
            Assert.AreEqual(2, properties.WaveHeight.NumberOfDecimalPlaces);
            Assert.AreEqual(waveHeight, properties.WaveHeight, properties.WaveHeight.GetAccuracy());
            Assert.AreEqual(reliability, properties.Reliability, properties.Reliability.GetAccuracy());

            Assert.AreEqual(ProbabilityFormattingHelper.Format(0.5), properties.Probability);

            Assert.AreEqual(isOvertoppingDominant, properties.IsOvertoppingDominant);

            Assert.AreEqual(generalResult.GoverningWindDirection.Name, properties.WindDirection);

            TestHelper.AssertTypeConverter <StructuresOutputProperties, KeyValueExpandableArrayConverter>(
                nameof(StructuresOutputProperties.AlphaValues));
            TestHelper.AssertTypeConverter <StructuresOutputProperties, KeyValueExpandableArrayConverter>(
                nameof(StructuresOutputProperties.Durations));

            int nrOfExpectedStochasts = generalResult.Stochasts.Count();

            Assert.AreEqual(nrOfExpectedStochasts, properties.AlphaValues.Length);
            Assert.AreEqual(nrOfExpectedStochasts, properties.Durations.Length);
            Stochast expectedStochast = generalResult.Stochasts.First();

            Assert.AreEqual(expectedStochast.Alpha, properties.AlphaValues[0].Alpha);
            Assert.AreEqual(expectedStochast.Duration, properties.Durations[0].Duration);

            TestHelper.AssertTypeConverter <StructuresOutputProperties, ExpandableArrayConverter>(
                nameof(StructuresOutputProperties.IllustrationPoints));

            int nrOfExpectedTopLevelIllustrationPoints = generalResult.TopLevelIllustrationPoints.Count();

            Assert.AreEqual(nrOfExpectedTopLevelIllustrationPoints, properties.IllustrationPoints.Length);

            CollectionAssert.AreEqual(generalResult.TopLevelIllustrationPoints, properties.IllustrationPoints.Select(i => i.Data));
        }
        /// <summary>
        /// Creates a new instance of <see cref="GeneralResult"/> with duplicate stochasts.
        /// </summary>
        /// <returns>A <see cref="GeneralResult"/> with duplicate stochasts.</returns>
        public static GeneralResult CreateGeneralResultWithDuplicateStochasts()
        {
            var stochast = new Stochast("Stochast A", 0, 0);

            return(new GeneralResult(0.5,
                                     WindDirectionTestFactory.CreateWindDirection(),
                                     new[]
            {
                stochast,
                stochast
            },
                                     new Dictionary <WindDirectionClosingSituation, IllustrationPointTreeNode>()));
        }
Beispiel #9
0
        private static void AssertStochasts(StochastEntity[] stochastEntities, Stochast[] stochasts)
        {
            Assert.AreEqual(stochastEntities.Length, stochasts.Length);

            for (var i = 0; i < stochastEntities.Length; i++)
            {
                StochastEntity stochastEntity = stochastEntities[i];
                Stochast       stochast       = stochasts[i];

                Assert.AreEqual(stochastEntity.Name, stochast.Name);
                Assert.AreEqual(stochastEntity.Alpha, stochast.Alpha, stochast.Alpha.GetAccuracy());
                Assert.AreEqual(stochastEntity.Duration, stochast.Duration, stochast.Duration.GetAccuracy());
            }
        }
        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);
        }
Beispiel #11
0
        public void Constructor_WithParameters_ReturnsNewInstance()
        {
            // Setup
            const string name = "stochast name";

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

            // Call
            var stochast = new Stochast(name, duration, alpha);

            // Assert
            Assert.AreEqual(name, stochast.Name);
            Assert.AreEqual(duration, stochast.Duration);
            Assert.AreEqual(alpha, stochast.Alpha);
        }
Beispiel #12
0
        public void Create_ValidStochast_ReturnStochastEntity()
        {
            // Setup
            var random   = new Random(123);
            var stochast = new Stochast("Some description",
                                        random.NextDouble(),
                                        random.NextDouble());
            int order = random.Next();

            // Call
            StochastEntity entity = stochast.Create(order);

            // Assert
            TestHelper.AssertAreEqualButNotSame(stochast.Name, entity.Name);
            Assert.AreEqual(stochast.Alpha, entity.Alpha, stochast.Alpha.GetAccuracy());
            Assert.AreEqual(stochast.Duration, entity.Duration, stochast.Duration.GetAccuracy());
            Assert.AreEqual(order, entity.Order);
        }
Beispiel #13
0
        public void Convert_ValidHydraRingStochastArgument_ExpectedProperties()
        {
            // Setup
            const string name = "name";

            var    random            = new Random(21);
            double duration          = random.NextDouble();
            double alpha             = random.NextDouble();
            var    hydraRingStochast = new HydraRingStochast(name, duration, alpha);

            // Call
            Stochast stochast = StochastConverter.Convert(hydraRingStochast);

            // Assert
            Assert.AreEqual(hydraRingStochast.Alpha, stochast.Alpha, stochast.Alpha.GetAccuracy());
            Assert.AreEqual(duration, stochast.Duration, stochast.Duration.GetAccuracy());
            Assert.AreEqual(hydraRingStochast.Name, stochast.Name);
        }
        /// <summary>
        /// Creates a <see cref="StochastEntity"/> based on the information
        /// of the <paramref name="stochast"/>.
        /// </summary>
        /// <param name="stochast">The stochast to create a database entity for.</param>
        /// <param name="order">The index at which <paramref name="stochast"/> resides within its parent.</param>
        /// <returns>A new <see cref="StochastEntity"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="stochast"/>
        /// is <c>null</c>.</exception>
        internal static StochastEntity Create(
            this Stochast stochast, int order)
        {
            if (stochast == null)
            {
                throw new ArgumentNullException(nameof(stochast));
            }

            var entity = new StochastEntity
            {
                Name     = stochast.Name.DeepClone(),
                Alpha    = stochast.Alpha,
                Duration = stochast.Duration,
                Order    = order
            };

            return(entity);
        }
        public void Read_ValidEntity_ReturnStochast()
        {
            // Setup
            var random = new Random(123);
            var entity = new StochastEntity
            {
                Name     = "Description",
                Alpha    = random.NextDouble(),
                Duration = random.NextDouble()
            };

            // Call
            Stochast illustrationPointResult = entity.Read();

            // Assert
            Assert.AreEqual(entity.Name, illustrationPointResult.Name);
            Assert.AreEqual(entity.Alpha, illustrationPointResult.Alpha, illustrationPointResult.Alpha.GetAccuracy());
            Assert.AreEqual(entity.Duration, illustrationPointResult.Duration, illustrationPointResult.Duration.GetAccuracy());
        }
Beispiel #16
0
        public void Constructor_ValidArguments_ReturnExpectedValues()
        {
            // Setup
            const string name = "Stochast name";

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

            // Call
            var stochast = new Stochast(name, duration, alpha);

            // Assert
            Assert.IsInstanceOf <ICloneable>(stochast);
            Assert.AreEqual(name, stochast.Name);
            Assert.AreEqual(duration, stochast.Duration, stochast.Duration.GetAccuracy());
            Assert.AreEqual(1, stochast.Duration.NumberOfDecimalPlaces);
            Assert.AreEqual(alpha, stochast.Alpha, stochast.Alpha.GetAccuracy());
            Assert.AreEqual(5, stochast.Alpha.NumberOfDecimalPlaces);
        }
Beispiel #17
0
        public void Create_IllustrationPointNodeWithFaultTreeIllustrationPointAndStochast_ReturnFaultTreeIllustrationPointEntity()
        {
            // Setup
            var random = new Random(21);

            var illustrationPoint = new FaultTreeIllustrationPoint(
                "Illustration point name",
                random.NextDouble(),
                new[]
            {
                new Stochast("Stochast",
                             random.NextDouble(),
                             random.NextDouble())
            },
                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.SubMechanismIllustrationPointEntities);
            CollectionAssert.IsEmpty(entity.TopLevelFaultTreeIllustrationPointEntities);
            Assert.AreEqual(order, entity.Order);

            StochastEntity entityStochastEntity = entity.StochastEntities.Single();
            Stochast       stochast             = illustrationPoint.Stochasts.First();

            Assert.AreEqual(stochast.Name, entityStochastEntity.Name);
            Assert.AreEqual(stochast.Alpha, entityStochastEntity.Alpha);
            Assert.AreEqual(stochast.Duration, entityStochastEntity.Duration);
        }
        public void GetProperties_WithData_ReturnExpectedValues()
        {
            // Setup
            var generalResult    = new TestGeneralResultFaultTreeIllustrationPoint();
            var structuresOutput = new TestStructuresOutput(generalResult);

            // Call
            var properties = new StructuresOutputProperties(structuresOutput);

            // Assert
            Assert.AreEqual(generalResult.GoverningWindDirection.Name, properties.WindDirection);

            Assert.AreEqual(ProbabilityFormattingHelper.Format(0.5), properties.Probability);
            Assert.AreEqual(0, properties.Reliability, properties.Reliability.GetAccuracy());

            TestHelper.AssertTypeConverter <StructuresOutputProperties, KeyValueExpandableArrayConverter>(
                nameof(StructuresOutputProperties.AlphaValues));
            TestHelper.AssertTypeConverter <StructuresOutputProperties, KeyValueExpandableArrayConverter>(
                nameof(StructuresOutputProperties.Durations));

            int nrOfExpectedStochasts = generalResult.Stochasts.Count();

            Assert.AreEqual(nrOfExpectedStochasts, properties.AlphaValues.Length);
            Assert.AreEqual(nrOfExpectedStochasts, properties.Durations.Length);
            Stochast expectedStochast = generalResult.Stochasts.First();

            Assert.AreEqual(expectedStochast.Alpha, properties.AlphaValues[0].Alpha);
            Assert.AreEqual(expectedStochast.Duration, properties.Durations[0].Duration);

            TestHelper.AssertTypeConverter <StructuresOutputProperties, ExpandableArrayConverter>(
                nameof(StructuresOutputProperties.IllustrationPoints));

            int nrOfExpectedTopLevelIllustrationPoints = generalResult.TopLevelIllustrationPoints.Count();

            Assert.AreEqual(nrOfExpectedTopLevelIllustrationPoints, properties.IllustrationPoints.Length);

            CollectionAssert.AreEqual(generalResult.TopLevelIllustrationPoints, properties.IllustrationPoints.Select(i => i.Data));
        }
        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());
        }
        public void GetProperties_WithData_ReturnExpectedValues()
        {
            // Setup
            var    random          = new Random();
            double overtoppingRate = random.NextDouble();
            double overtoppingRateTargetProbability     = random.NextDouble();
            double overtoppingRateTargetReliability     = random.NextDouble();
            double overtoppingRateCalculatedProbability = random.NextDouble();
            double overtoppingRateCalculatedReliability = random.NextDouble();
            var    overtoppingRateConvergence           = random.NextEnumValue <CalculationConvergence>();

            var generalResult = new TestGeneralResultFaultTreeIllustrationPoint();

            var overtoppingRateOutput = new OvertoppingRateOutput(overtoppingRate,
                                                                  overtoppingRateTargetProbability,
                                                                  overtoppingRateTargetReliability,
                                                                  overtoppingRateCalculatedProbability,
                                                                  overtoppingRateCalculatedReliability,
                                                                  overtoppingRateConvergence,
                                                                  generalResult);

            // Call
            var properties = new OvertoppingRateOutputProperties(overtoppingRateOutput);

            // Assert
            Assert.AreEqual(2, properties.OvertoppingRate.NumberOfDecimalPlaces);
            Assert.AreEqual(overtoppingRate * 1000, properties.OvertoppingRate, properties.OvertoppingRate.GetAccuracy());
            Assert.AreEqual(overtoppingRateTargetProbability, properties.OvertoppingRateTargetProbability);
            TestHelper.AssertTypeConverter <GrassCoverErosionInwardsOutputProperties, NoProbabilityValueDoubleConverter>(
                nameof(GrassCoverErosionInwardsOutputProperties.OvertoppingRateTargetProbability));
            Assert.AreEqual(overtoppingRateTargetReliability, properties.OvertoppingRateTargetReliability, properties.OvertoppingRateTargetReliability.GetAccuracy());
            TestHelper.AssertTypeConverter <GrassCoverErosionInwardsOutputProperties, NoValueRoundedDoubleConverter>(
                nameof(GrassCoverErosionInwardsOutputProperties.OvertoppingRateTargetReliability));
            Assert.AreEqual(overtoppingRateCalculatedProbability, properties.OvertoppingRateCalculatedProbability);
            TestHelper.AssertTypeConverter <GrassCoverErosionInwardsOutputProperties, NoProbabilityValueDoubleConverter>(
                nameof(GrassCoverErosionInwardsOutputProperties.OvertoppingRateCalculatedProbability));
            Assert.AreEqual(overtoppingRateCalculatedReliability, properties.OvertoppingRateCalculatedReliability, properties.OvertoppingRateCalculatedReliability.GetAccuracy());
            TestHelper.AssertTypeConverter <GrassCoverErosionInwardsOutputProperties, NoValueRoundedDoubleConverter>(
                nameof(GrassCoverErosionInwardsOutputProperties.OvertoppingRateCalculatedReliability));

            string overtoppingRateConvergenceValue = EnumDisplayNameHelper.GetDisplayName(overtoppingRateConvergence);

            Assert.AreEqual(overtoppingRateConvergenceValue, properties.OvertoppingRateConvergence);
            Assert.AreEqual(generalResult.GoverningWindDirection.Name, properties.WindDirection);

            TestHelper.AssertTypeConverter <StructuresOutputProperties, KeyValueExpandableArrayConverter>(
                nameof(StructuresOutputProperties.AlphaValues));
            TestHelper.AssertTypeConverter <StructuresOutputProperties, KeyValueExpandableArrayConverter>(
                nameof(StructuresOutputProperties.Durations));

            int nrOfExpectedStochasts = generalResult.Stochasts.Count();

            Assert.AreEqual(nrOfExpectedStochasts, properties.AlphaValues.Length);
            Assert.AreEqual(nrOfExpectedStochasts, properties.Durations.Length);
            Stochast expectedStochast = generalResult.Stochasts.First();

            Assert.AreEqual(expectedStochast.Alpha, properties.AlphaValues[0].Alpha);
            Assert.AreEqual(expectedStochast.Duration, properties.Durations[0].Duration);

            TestHelper.AssertTypeConverter <StructuresOutputProperties, ExpandableArrayConverter>(
                nameof(StructuresOutputProperties.IllustrationPoints));

            int nrOfExpectedTopLevelIllustrationPoints = generalResult.TopLevelIllustrationPoints.Count();

            Assert.AreEqual(nrOfExpectedTopLevelIllustrationPoints, properties.IllustrationPoints.Length);

            CollectionAssert.AreEqual(generalResult.TopLevelIllustrationPoints, properties.IllustrationPoints.Select(i => i.Data));
        }
        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);
        }
Beispiel #22
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(Stochast original, Stochast clone)
 {
     Assert.AreEqual(original.Name, clone.Name);
     Assert.AreEqual(original.Alpha, clone.Alpha);
     Assert.AreEqual(original.Duration, clone.Duration);
 }