/// <summary> /// Creates all the top level fault tree illustration points based on the /// combinations of <see cref="HydraRingWindDirectionClosingSituation"/> and /// <see cref="HydraRingFaultTreeIllustrationPoint"/>. /// </summary> /// <param name="hydraRingTopLevelIllustrationPoints">The collection of /// <see cref="HydraRingWindDirectionClosingSituation"/> and <see cref="HydraRingFaultTreeIllustrationPoint"/> /// combinations to base the <see cref="TopLevelFaultTreeIllustrationPoint"/> on.</param> /// <returns>An <see cref="IEnumerable{T}"/> of <see cref="TopLevelFaultTreeIllustrationPoint"/>.</returns> /// <exception cref="IllustrationPointConversionException">Thrown when the combination of /// <see cref="HydraRingWindDirectionClosingSituation"/> and <see cref="HydraRingFaultTreeIllustrationPoint"/> /// cannot be converted to <see cref="TopLevelSubMechanismIllustrationPoint"/>.</exception> private static IEnumerable <TopLevelSubMechanismIllustrationPoint> GetTopLevelSubMechanismIllustrationPoints( IDictionary <HydraRingWindDirectionClosingSituation, HydraRingIllustrationPointTreeNode> hydraRingTopLevelIllustrationPoints) { var topLevelIlustrationPoints = new List <TopLevelSubMechanismIllustrationPoint>(); foreach (KeyValuePair <HydraRingWindDirectionClosingSituation, HydraRingIllustrationPointTreeNode> topLevelIllustrationPointTreeNode in hydraRingTopLevelIllustrationPoints) { IHydraRingIllustrationPoint hydraIllustrationPointData = topLevelIllustrationPointTreeNode.Value.Data; HydraRingWindDirectionClosingSituation hydraWindDirectionClosingSituation = topLevelIllustrationPointTreeNode.Key; var subMechanismIllustrationPoint = hydraIllustrationPointData as HydraRingSubMechanismIllustrationPoint; if (subMechanismIllustrationPoint != null) { topLevelIlustrationPoints.Add(TopLevelSubMechanismIllustrationPointConverter.Convert( hydraWindDirectionClosingSituation, subMechanismIllustrationPoint)); } else { string exceptionMessage = $"Expected a fault tree node with data of type {typeof(HydraRingSubMechanismIllustrationPoint)} as root, " + $"but got {hydraIllustrationPointData.GetType()}"; throw new IllustrationPointConversionException(exceptionMessage); } } return(topLevelIlustrationPoints); }
public void Convert_ValidArguments_ExpectedProperties() { // Setup var random = new Random(21); var hydraRingWindDirection = new HydraRingWindDirection("Name", random.NextDouble()); var hydraRingWindDirectionClosingSituation = new HydraRingWindDirectionClosingSituation(hydraRingWindDirection, "closing scenario"); var hydraRingIllustrationPointResult = new HydraRingIllustrationPointResult("HydraIllustrationPointResult", "-", random.NextDouble()); var hydraRingSubMechanismIllustrationPointStochast = new HydraRingSubMechanismIllustrationPointStochast("HydraSubMechanismIllustrationPointStochast", "-", random.NextDouble(), random.NextDouble(), random.NextDouble()); var hydraRingSubMechanismIllustrationPoint = new HydraRingSubMechanismIllustrationPoint("name", new[] { hydraRingSubMechanismIllustrationPointStochast }, new[] { hydraRingIllustrationPointResult }, random.NextDouble()); // Call TopLevelSubMechanismIllustrationPoint combination = TopLevelSubMechanismIllustrationPointConverter.Convert( hydraRingWindDirectionClosingSituation, hydraRingSubMechanismIllustrationPoint); // Assert WindDirection windDirection = combination.WindDirection; Assert.AreEqual(hydraRingWindDirection.Angle, windDirection.Angle, windDirection.Angle.GetAccuracy()); Assert.AreEqual(hydraRingWindDirection.Name, windDirection.Name); Assert.AreEqual(hydraRingWindDirectionClosingSituation.ClosingSituation, combination.ClosingSituation); SubMechanismIllustrationPoint subMechanismIllustrationPoint = combination.SubMechanismIllustrationPoint; Assert.AreEqual(hydraRingSubMechanismIllustrationPoint.Beta, subMechanismIllustrationPoint.Beta, subMechanismIllustrationPoint.Beta.GetAccuracy()); Assert.AreEqual(hydraRingSubMechanismIllustrationPoint.Name, subMechanismIllustrationPoint.Name); IllustrationPointResult illustrationPointResult = subMechanismIllustrationPoint.IllustrationPointResults.Single(); Assert.AreEqual(hydraRingIllustrationPointResult.Description, illustrationPointResult.Description); Assert.AreEqual(hydraRingIllustrationPointResult.Value, illustrationPointResult.Value, illustrationPointResult.Value.GetAccuracy()); SubMechanismIllustrationPointStochast stochast = subMechanismIllustrationPoint.Stochasts.Single(); Assert.AreEqual(hydraRingSubMechanismIllustrationPointStochast.Alpha, stochast.Alpha, stochast.Alpha.GetAccuracy()); Assert.AreEqual(hydraRingSubMechanismIllustrationPointStochast.Duration, stochast.Duration, stochast.Duration.GetAccuracy()); Assert.AreEqual(hydraRingSubMechanismIllustrationPointStochast.Name, stochast.Name); Assert.AreEqual(hydraRingSubMechanismIllustrationPointStochast.Unit, stochast.Unit); Assert.AreEqual(hydraRingSubMechanismIllustrationPointStochast.Realization, stochast.Realization, stochast.Realization.GetAccuracy()); }
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); }
public void ConvertToGeneralResultTopLevelSubMechanismIllustrationPoint_HydraGeneralResultWithSubMechanismIllustrationPointsOnly_ExpectedProperties() { // Setup const string closingSituation = "Closing situation"; var random = new Random(21); var hydraRingWindDirection = new HydraRingWindDirection("SSE", random.NextDouble()); var hydraRingWindDirectionClosingSituation = new HydraRingWindDirectionClosingSituation( hydraRingWindDirection, closingSituation); var hydraRingIllustrationPoint = new HydraRingSubMechanismIllustrationPoint( "Illustration Point", Enumerable.Empty <HydraRingSubMechanismIllustrationPointStochast>(), Enumerable.Empty <HydraRingIllustrationPointResult>(), random.NextDouble()); var hydraRingIllustrationTreeNode = new HydraRingIllustrationPointTreeNode(hydraRingIllustrationPoint); var governingHydraWindDirection = new HydraRingWindDirection("Name", random.NextDouble()); var hydraGeneralResult = new HydraRingGeneralResult( random.NextDouble(), governingHydraWindDirection, Enumerable.Empty <HydraRingStochast>(), new Dictionary <HydraRingWindDirectionClosingSituation, HydraRingIllustrationPointTreeNode> { { hydraRingWindDirectionClosingSituation, hydraRingIllustrationTreeNode } }); // Call GeneralResult <TopLevelSubMechanismIllustrationPoint> generalResult = GeneralResultConverter.ConvertToGeneralResultTopLevelSubMechanismIllustrationPoint(hydraGeneralResult); // Assert WindDirection generalResultGoverningWindDirection = generalResult.GoverningWindDirection; AssertWindDirection(governingHydraWindDirection, generalResultGoverningWindDirection); CollectionAssert.IsEmpty(generalResult.Stochasts); TopLevelSubMechanismIllustrationPoint combination = generalResult.TopLevelIllustrationPoints.Single(); AssertWindDirection(hydraRingWindDirection, combination.WindDirection); Assert.AreEqual(closingSituation, combination.ClosingSituation); SubMechanismIllustrationPoint subMechanismIllustrationPoint = combination.SubMechanismIllustrationPoint; Assert.AreEqual(hydraRingIllustrationPoint.Name, subMechanismIllustrationPoint.Name); Assert.AreEqual(hydraRingIllustrationPoint.Beta, subMechanismIllustrationPoint.Beta, subMechanismIllustrationPoint.Beta.GetAccuracy()); CollectionAssert.IsEmpty(subMechanismIllustrationPoint.Stochasts); CollectionAssert.IsEmpty(subMechanismIllustrationPoint.IllustrationPointResults); }
public void Convert_HydraRingIllustrationPointTreeNodeNull_ThrowsArgumentNullException() { // Setup var hydraRingWindDirectionClosingSituation = new HydraRingWindDirectionClosingSituation(WindDirectionTestFactory.CreateWindDirection(), "random closing situation"); // Call TestDelegate call = () => TopLevelFaultTreeIllustrationPointConverter.Convert(hydraRingWindDirectionClosingSituation, null); // Assert var exception = Assert.Throws <ArgumentNullException>(call); Assert.AreEqual("hydraRingIllustrationPointTreeNode", exception.ParamName); }
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); }
/// <summary> /// Creates a new instance of <see cref="TopLevelFaultTreeIllustrationPoint"/> /// based on the information of <paramref name="hydraRingWindDirectionClosingSituation"/> /// and <paramref name="hydraRingIllustrationPointTreeNode"/>. /// </summary> /// <param name="hydraRingWindDirectionClosingSituation">The <see cref="HydraRingWindDirectionClosingSituation"/> /// to base the <see cref="TopLevelFaultTreeIllustrationPoint"/> on.</param> /// <param name="hydraRingIllustrationPointTreeNode">The <see cref="HydraRingIllustrationPointTreeNode"/> /// to base the <see cref="TopLevelFaultTreeIllustrationPoint"/> on.</param> /// <returns>A <see cref="TopLevelFaultTreeIllustrationPoint"/>.</returns> /// <exception cref="ArgumentNullException">Thrown when any input parameter /// is <c>null</c>.</exception> /// <exception cref="ArgumentException">Thrown when <paramref name="hydraRingIllustrationPointTreeNode"/> /// has tree node elements which do not contain exactly 0 or 2 children.</exception> public static TopLevelFaultTreeIllustrationPoint Convert(HydraRingWindDirectionClosingSituation hydraRingWindDirectionClosingSituation, HydraRingIllustrationPointTreeNode hydraRingIllustrationPointTreeNode) { if (hydraRingWindDirectionClosingSituation == null) { throw new ArgumentNullException(nameof(hydraRingWindDirectionClosingSituation)); } if (hydraRingIllustrationPointTreeNode == null) { throw new ArgumentNullException(nameof(hydraRingIllustrationPointTreeNode)); } WindDirection windDirection = WindDirectionConverter.Convert(hydraRingWindDirectionClosingSituation.WindDirection); return(new TopLevelFaultTreeIllustrationPoint(windDirection, hydraRingWindDirectionClosingSituation.ClosingSituation, IllustrationPointNodeConverter.Convert(hydraRingIllustrationPointTreeNode))); }
/// <summary> /// Creates a new instance of <see cref="TopLevelSubMechanismIllustrationPoint"/> /// based on the information of <paramref name="hydraRingWindDirectionClosingSituation"/> /// and <paramref name="hydraRingSubMechanismIllustrationPoint"/>. /// </summary> /// <param name="hydraRingWindDirectionClosingSituation">The <see cref="HydraRingWindDirectionClosingSituation"/> /// to base the <see cref="TopLevelSubMechanismIllustrationPoint"/> on.</param> /// <param name="hydraRingSubMechanismIllustrationPoint">The <see cref="HydraRingSubMechanismIllustrationPoint"/> /// to base the <see cref="TopLevelSubMechanismIllustrationPoint"/> on.</param> /// <returns>A <see cref="TopLevelSubMechanismIllustrationPoint"/>.</returns> /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception> public static TopLevelSubMechanismIllustrationPoint Convert(HydraRingWindDirectionClosingSituation hydraRingWindDirectionClosingSituation, HydraRingSubMechanismIllustrationPoint hydraRingSubMechanismIllustrationPoint) { if (hydraRingWindDirectionClosingSituation == null) { throw new ArgumentNullException(nameof(hydraRingWindDirectionClosingSituation)); } if (hydraRingSubMechanismIllustrationPoint == null) { throw new ArgumentNullException(nameof(hydraRingSubMechanismIllustrationPoint)); } WindDirection windDirection = WindDirectionConverter.Convert(hydraRingWindDirectionClosingSituation.WindDirection); SubMechanismIllustrationPoint subMechanismIllustrationPoint = SubMechanismIllustrationPointConverter.Convert(hydraRingSubMechanismIllustrationPoint); return(new TopLevelSubMechanismIllustrationPoint(windDirection, hydraRingWindDirectionClosingSituation.ClosingSituation, subMechanismIllustrationPoint)); }
public void ConvertToGeneralResultTopLevelSubMechanismIllustrationPoint_HydraRingGeneralResultWithFaultTreeIllustrationPointsOnly_ThrowsIllustrationPointConversionException() { // 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>(), random.NextEnumValue <HydraRingCombinationType>()); 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 TestDelegate call = () => GeneralResultConverter.ConvertToGeneralResultTopLevelSubMechanismIllustrationPoint(hydraRingGeneralResult); // Assert var exception = Assert.Throws <IllustrationPointConversionException>(call); string expectedMessage = $"Expected a fault tree node with data of type {typeof(HydraRingSubMechanismIllustrationPoint)} as root, " + $"but got {hydraRingIllustrationPoint.GetType()}"; Assert.AreEqual(expectedMessage, exception.Message); }
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()); }