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 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()); }
/// <summary> /// Creates a new instance of <see cref="WindDirection"/> based on the information of <paramref name="hydraRingWindDirection"/>. /// </summary> /// <param name="hydraRingWindDirection">The <see cref="HydraRingWindDirection"/> to base the /// <see cref="WindDirection"/> to create on.</param> /// <returns>The newly created <see cref="WindDirection"/>.</returns> /// <exception cref="ArgumentNullException">Thrown when <paramref name="hydraRingWindDirection"/> /// is <c>null</c>.</exception> public static WindDirection Convert(HydraRingWindDirection hydraRingWindDirection) { if (hydraRingWindDirection == null) { throw new ArgumentNullException(nameof(hydraRingWindDirection)); } return(new WindDirection(hydraRingWindDirection.Name, hydraRingWindDirection.Angle)); }
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_ValidArguments_ExpectedProperties() { // Setup var random = new Random(21); var hydraRingWindDirection = new HydraRingWindDirection("name", random.NextDouble()); // Call WindDirection windDirection = WindDirectionConverter.Convert(hydraRingWindDirection); // Assert Assert.AreEqual(hydraRingWindDirection.Angle, windDirection.Angle, windDirection.Angle.GetAccuracy()); Assert.AreEqual(hydraRingWindDirection.Name, windDirection.Name); }
public void Convert_SubMechanismIllustrationPointNull_ThrowsArgumentNullException() { // Setup HydraRingWindDirection hydraRingWindDirection = WindDirectionTestFactory.CreateWindDirection(); // Call void Call() => TopLevelSubMechanismIllustrationPointConverter.Convert(new HydraRingWindDirectionClosingSituation(hydraRingWindDirection, string.Empty), null); // Assert string paramName = Assert.Throws <ArgumentNullException>(Call).ParamName; Assert.AreEqual("hydraRingSubMechanismIllustrationPoint", 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); }
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 ConvertToGeneralResultTopLevelSubMechanismIllustrationPoint_HydraGeneralResultWithoutIllustrationPoints_ExpectedProperties() { // Setup var random = new Random(21); var hydraGoverningWindDirection = new HydraRingWindDirection("Name", random.NextDouble()); var hydraRingGeneralResult = new HydraRingGeneralResult( random.NextDouble(), hydraGoverningWindDirection, Enumerable.Empty <HydraRingStochast>(), new Dictionary < HydraRingWindDirectionClosingSituation, HydraRingIllustrationPointTreeNode>()); // Call GeneralResult <TopLevelSubMechanismIllustrationPoint> generalResult = GeneralResultConverter.ConvertToGeneralResultTopLevelSubMechanismIllustrationPoint(hydraRingGeneralResult); // Assert AssertWindDirection(hydraGoverningWindDirection, generalResult.GoverningWindDirection); CollectionAssert.IsEmpty(generalResult.TopLevelIllustrationPoints); CollectionAssert.IsEmpty(generalResult.Stochasts); }
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()); }
private static void AssertWindDirection(HydraRingWindDirection hydraRingWindDirection, WindDirection windDirection) { Assert.AreEqual(hydraRingWindDirection.Name, windDirection.Name); Assert.AreEqual(hydraRingWindDirection.Angle, windDirection.Angle, windDirection.Angle.GetAccuracy()); }