public void GivenControl_WhenDataSetWithInvalidIllustrationPointChildType_ThenThrowsNotSupportedException() { // Given using (var control = new IllustrationPointsFaultTreeControl()) { var rootNode = new IllustrationPointNode(new TestFaultTreeIllustrationPoint()); rootNode.SetChildren(new[] { new IllustrationPointNode(new TestIllustrationPoint()), new IllustrationPointNode(new TestSubMechanismIllustrationPoint()) }); var topLevelFaultTreeIllustrationPoint = new TopLevelFaultTreeIllustrationPoint( WindDirectionTestFactory.CreateTestWindDirection(), "closing situation", rootNode); // When TestDelegate test = () => control.Data = topLevelFaultTreeIllustrationPoint; // Then var exception = Assert.Throws <NotSupportedException>(test); Assert.AreEqual($"IllustrationPointNode of type {nameof(TestIllustrationPoint)} is not supported. " + $"Supported types: {nameof(FaultTreeIllustrationPoint)} and {nameof(SubMechanismIllustrationPoint)}", exception.Message); } }
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); }
private static void AssertIllustrationPointSelection(TopLevelFaultTreeIllustrationPoint expectedSelection, IEnumerable <string> expectedClosingSituations, object selection) { var illustrationPointSelection = selection as SelectedTopLevelFaultTreeIllustrationPoint; Assert.IsNotNull(illustrationPointSelection); Assert.AreSame(expectedSelection, illustrationPointSelection.TopLevelFaultTreeIllustrationPoint); CollectionAssert.AreEqual(expectedClosingSituations, illustrationPointSelection.ClosingSituations); }
public void Constructor_FaultTreeIllustrationPoint_CorrectValues() { // Setup var random = new Random(31); var topLevel = new TopLevelFaultTreeIllustrationPoint( new WindDirection("N", 5.0), "closing situation", new IllustrationPointNode(new FaultTreeIllustrationPoint("Fault Tree A", 3.14, new[] { new Stochast("Stochast A", 2.5, 5.5) }, CombinationType.And))); topLevel.FaultTreeNodeRoot.SetChildren(new[] { new IllustrationPointNode(new TestFaultTreeIllustrationPoint("A")), new IllustrationPointNode(new TestSubMechanismIllustrationPoint("B")) }); // Call var properties = new TopLevelFaultTreeIllustrationPointProperties(topLevel, random.NextBoolean()); // Assert Assert.AreEqual(topLevel.WindDirection.Name, properties.WindDirection); TestHelper.AssertTypeConverter <TopLevelFaultTreeIllustrationPointProperties, NoValueRoundedDoubleConverter>( nameof(TopLevelFaultTreeIllustrationPointProperties.Reliability)); Assert.AreEqual(3.14, properties.Reliability.Value); Assert.AreEqual(5, properties.Reliability.NumberOfDecimalPlaces); TestHelper.AssertTypeConverter <TopLevelFaultTreeIllustrationPointProperties, NoProbabilityValueDoubleConverter>( nameof(TopLevelFaultTreeIllustrationPointProperties.CalculatedProbability)); Assert.AreEqual(StatisticsConverter.ReliabilityToProbability(3.14), properties.CalculatedProbability); Assert.AreEqual(topLevel.ClosingSituation, properties.ClosingSituation); TestHelper.AssertTypeConverter <TopLevelFaultTreeIllustrationPointProperties, KeyValueExpandableArrayConverter>( nameof(TopLevelFaultTreeIllustrationPointProperties.AlphaValues)); Assert.IsNotNull(properties.AlphaValues); Assert.AreEqual(1, properties.AlphaValues.Length); Assert.AreEqual(5.5, properties.AlphaValues[0].Alpha); TestHelper.AssertTypeConverter <TopLevelFaultTreeIllustrationPointProperties, KeyValueExpandableArrayConverter>( nameof(TopLevelFaultTreeIllustrationPointProperties.Durations)); Assert.IsNotNull(properties.Durations); Assert.AreEqual(1, properties.Durations.Length); Assert.AreEqual(2.5, properties.Durations[0].Duration); TestHelper.AssertTypeConverter <TopLevelFaultTreeIllustrationPointProperties, ExpandableArrayConverter>( nameof(TopLevelFaultTreeIllustrationPointProperties.IllustrationPoints)); Assert.IsNotNull(properties.IllustrationPoints); Assert.AreEqual(2, properties.IllustrationPoints.Length); }
private static void AssertTopLevelFaultTreeIllustrationPoint( TopLevelFaultTreeIllustrationPointEntity illustrationPointEntity, TopLevelFaultTreeIllustrationPoint illustrationPoint) { Assert.AreEqual(illustrationPointEntity.ClosingSituation, illustrationPoint.ClosingSituation); WindDirection actualWindDirection = illustrationPoint.WindDirection; Assert.AreEqual(illustrationPointEntity.WindDirectionName, actualWindDirection.Name); Assert.AreEqual(illustrationPointEntity.WindDirectionAngle, actualWindDirection.Angle, actualWindDirection.Angle); Assert.IsNotNull(illustrationPoint.FaultTreeNodeRoot); }
public void Constructor_ValidArguments_ReturnsExpectedValues() { // Setup TopLevelFaultTreeIllustrationPoint topLevelFaultTreeIllustrationPoint = CreateTopLevelFaultTreeIllustrationPoint(); IEnumerable <string> closingSituations = Enumerable.Empty <string>(); // Call var selectedTopLevelFaultTreeIllustrationPoint = new SelectedTopLevelFaultTreeIllustrationPoint(topLevelFaultTreeIllustrationPoint, closingSituations); // Assert Assert.AreSame(topLevelFaultTreeIllustrationPoint, selectedTopLevelFaultTreeIllustrationPoint.TopLevelFaultTreeIllustrationPoint); Assert.AreSame(closingSituations, selectedTopLevelFaultTreeIllustrationPoint.ClosingSituations); }
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="SelectedTopLevelFaultTreeIllustrationPoint"/>. /// </summary> /// <param name="topLevelFaultTreeIllustrationPoint">The top level fault tree illustration point.</param> /// <param name="closingSituations">The closing situations that are present.</param> /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception> public SelectedTopLevelFaultTreeIllustrationPoint(TopLevelFaultTreeIllustrationPoint topLevelFaultTreeIllustrationPoint, IEnumerable <string> closingSituations) { if (topLevelFaultTreeIllustrationPoint == null) { throw new ArgumentNullException(nameof(topLevelFaultTreeIllustrationPoint)); } if (closingSituations == null) { throw new ArgumentNullException(nameof(closingSituations)); } TopLevelFaultTreeIllustrationPoint = topLevelFaultTreeIllustrationPoint; ClosingSituations = closingSituations; }
public void ToString_CorrectValue_ReturnsCorrectString() { // Setup var random = new Random(31); var topLevelFaultTreeIllustrationPoint = new TopLevelFaultTreeIllustrationPoint( new WindDirection("N", 5.0), "closing situation", new IllustrationPointNode(new TestFaultTreeIllustrationPoint())); var topLevelFaultTreeProperties = new TopLevelFaultTreeIllustrationPointProperties(topLevelFaultTreeIllustrationPoint, random.NextBoolean()); // Call string toString = topLevelFaultTreeProperties.ToString(); // Assert Assert.AreEqual("N", toString); }
public void Constructor_ValidArguments_ReturnsExpectedProperties() { // Setup WindDirection windDirection = WindDirectionTestFactory.CreateTestWindDirection(); const string closingSituation = "closing situation"; var faultTreeNode = new IllustrationPointNode(new TestIllustrationPoint()); // Call var illustrationPoint = new TopLevelFaultTreeIllustrationPoint(windDirection, closingSituation, faultTreeNode); // Assert Assert.IsInstanceOf <TopLevelIllustrationPointBase>(illustrationPoint); Assert.AreSame(windDirection, illustrationPoint.WindDirection); Assert.AreEqual(closingSituation, illustrationPoint.ClosingSituation); Assert.AreSame(faultTreeNode, illustrationPoint.FaultTreeNodeRoot); }
public void Create_ValidTopLevelFaultTreeIllustrationPointWithChildren_ReturnsTopLevelFaultTreeIllustrationPointEntityWithChildren() { // Setup var random = new Random(21); var windDirection = new WindDirection("WindDirection Name", random.NextDouble()); var illustrationPointNode = new IllustrationPointNode(FaultTreeIllustrationPointTestFactory.CreateTestFaultTreeIllustrationPoint()); illustrationPointNode.SetChildren(new[] { new IllustrationPointNode(new TestSubMechanismIllustrationPoint("Point A")), new IllustrationPointNode(new TestSubMechanismIllustrationPoint("Point B")) }); var topLevelIllustrationPoint = new TopLevelFaultTreeIllustrationPoint( windDirection, "Just a situation", illustrationPointNode); int order = random.Next(); // Call TopLevelFaultTreeIllustrationPointEntity entity = topLevelIllustrationPoint.Create(order); // Assert TestHelper.AssertAreEqualButNotSame(topLevelIllustrationPoint.ClosingSituation, entity.ClosingSituation); TestHelper.AssertAreEqualButNotSame(windDirection.Name, entity.WindDirectionName); Assert.AreEqual(windDirection.Angle, entity.WindDirectionAngle, windDirection.Angle.GetAccuracy()); Assert.AreEqual(order, entity.Order); SubMechanismIllustrationPointEntity[] subMechanismIllustrationPointEntities = entity.FaultTreeIllustrationPointEntity.SubMechanismIllustrationPointEntities.ToArray(); Assert.AreEqual(2, subMechanismIllustrationPointEntities.Length); for (var i = 0; i < 2; i++) { var expectedIllustrationPoint = new TestSubMechanismIllustrationPoint(subMechanismIllustrationPointEntities[i].Name); SubMechanismIllustrationPointEntity illustrationPointEntity = subMechanismIllustrationPointEntities[i]; Assert.AreEqual(expectedIllustrationPoint.Name, illustrationPointEntity.Name); Assert.AreEqual(expectedIllustrationPoint.Beta, illustrationPointEntity.Beta, expectedIllustrationPoint.Beta.GetAccuracy()); Assert.AreEqual(expectedIllustrationPoint.IllustrationPointResults.Count(), illustrationPointEntity.IllustrationPointResultEntities.Count); Assert.AreEqual(expectedIllustrationPoint.Stochasts.Count(), illustrationPointEntity.IllustrationPointResultEntities.Count); Assert.AreEqual(i, illustrationPointEntity.Order); } }
public void CreateInstance_TopLevelFaultTreeIllustrationPoint_ReturnFaultTreeIllustrationPointBaseProperties() { // Setup var topLevelFaultTreeIllustrationPoint = new TopLevelFaultTreeIllustrationPoint( WindDirectionTestFactory.CreateTestWindDirection(), "Closing situation", new IllustrationPointNode(new TestIllustrationPoint())); var selectedTopLevelFaultTreeIllustrationPoint = new SelectedTopLevelFaultTreeIllustrationPoint(topLevelFaultTreeIllustrationPoint, Enumerable.Empty <string>()); // Call IObjectProperties objectProperties = info.CreateInstance(selectedTopLevelFaultTreeIllustrationPoint); // Assert Assert.IsInstanceOf <TopLevelFaultTreeIllustrationPointProperties>(objectProperties); Assert.AreSame(topLevelFaultTreeIllustrationPoint, objectProperties.Data); }
public void Read_ValidEntity_ReturnsTopLevelFaultTreeIllustrationPoint() { // Setup var random = new Random(21); var combinationType = random.NextEnumValue <CombinationType>(); var illustrationPointEntity = new FaultTreeIllustrationPointEntity { Name = "Illustration point name", Beta = random.NextDouble(), CombinationType = Convert.ToByte(combinationType) }; var entity = new TopLevelFaultTreeIllustrationPointEntity { ClosingSituation = "closingSituation", WindDirectionName = "WindDirectionName", WindDirectionAngle = random.NextDouble(), FaultTreeIllustrationPointEntity = illustrationPointEntity }; // Call TopLevelFaultTreeIllustrationPoint topLevelIllustrationPoint = entity.Read(); // Assert Assert.AreEqual(entity.ClosingSituation, topLevelIllustrationPoint.ClosingSituation); WindDirection actualWindDirection = topLevelIllustrationPoint.WindDirection; Assert.AreEqual(entity.WindDirectionName, actualWindDirection.Name); Assert.AreEqual(entity.WindDirectionAngle, actualWindDirection.Angle, actualWindDirection.Angle.GetAccuracy()); IllustrationPointNode rootNode = topLevelIllustrationPoint.FaultTreeNodeRoot; var illustrationPoint = rootNode.Data as FaultTreeIllustrationPoint; Assert.IsNotNull(illustrationPoint); Assert.AreEqual(illustrationPointEntity.Beta, illustrationPoint.Beta, illustrationPoint.Beta.GetAccuracy()); Assert.AreEqual(illustrationPointEntity.Name, illustrationPoint.Name); Assert.AreEqual(combinationType, illustrationPoint.CombinationType); CollectionAssert.IsEmpty(illustrationPoint.Stochasts); CollectionAssert.IsEmpty(rootNode.Children); }
public void GivenFullyConfiguredView_WhenSelectingFaultTreeIllustrationPointInTree_ThenSelectionChangedAndPropagatedAccordingly(bool sameClosingSituations) { // Given var mocks = new MockRepository(); var calculation = mocks.Stub <ICalculation>(); mocks.ReplayAll(); GeneralResult <TopLevelFaultTreeIllustrationPoint> generalResultFunc = GetGeneralResultWithThreeTopLevelIllustrationPointsWithChildren(sameClosingSituations); var view = new GeneralResultFaultTreeIllustrationPointView(calculation, () => generalResultFunc); ShowTestView(view); var selectionChangedCount = 0; view.SelectionChanged += (sender, args) => selectionChangedCount++; IllustrationPointsFaultTreeControl illustrationPointsFaultTreeControl = GetIllustrationPointsFaultTreeControl(view); PointedTreeGraph pointedTreeGraph = GetPointedTreeGraph(illustrationPointsFaultTreeControl); // When PointedTreeElementVertex selectedVertex = pointedTreeGraph.Vertices.ElementAt(0); selectedVertex.IsSelected = true; // Then Assert.AreEqual(1, selectionChangedCount); TopLevelFaultTreeIllustrationPoint topLevel = generalResultFunc.TopLevelIllustrationPoints.First(); IllustrationPointNode expectedSelectedNode = topLevel.FaultTreeNodeRoot; var selectedFaultTreeContext = view.Selection as IllustrationPointContext <FaultTreeIllustrationPoint>; Assert.IsNotNull(selectedFaultTreeContext); Assert.AreSame(expectedSelectedNode, selectedFaultTreeContext.IllustrationPointNode); Assert.AreEqual(sameClosingSituations ? string.Empty : topLevel.ClosingSituation, selectedFaultTreeContext.ClosingSituation); Assert.AreEqual(topLevel.WindDirection.Name, selectedFaultTreeContext.WindDirectionName); mocks.VerifyAll(); }
/// <summary> /// Creates a <see cref="TopLevelFaultTreeIllustrationPointEntity"/> /// based on the information of <paramref name="topLevelFaultTreeIllustrationPoint"/>. /// </summary> /// <param name="topLevelFaultTreeIllustrationPoint">The top level illustration point to /// create a database entity for.</param> /// <param name="order">The index at which <paramref name="topLevelFaultTreeIllustrationPoint"/> /// resides within its parent.</param> /// <returns>A <see cref="TopLevelFaultTreeIllustrationPointEntity"/>.</returns> /// <exception cref="ArgumentNullException">Thrown when /// <paramref name="topLevelFaultTreeIllustrationPoint"/> is <c>null</c>.</exception> public static TopLevelFaultTreeIllustrationPointEntity Create( this TopLevelFaultTreeIllustrationPoint topLevelFaultTreeIllustrationPoint, int order) { if (topLevelFaultTreeIllustrationPoint == null) { throw new ArgumentNullException(nameof(topLevelFaultTreeIllustrationPoint)); } WindDirection windDirection = topLevelFaultTreeIllustrationPoint.WindDirection; return(new TopLevelFaultTreeIllustrationPointEntity { ClosingSituation = topLevelFaultTreeIllustrationPoint.ClosingSituation.DeepClone(), WindDirectionName = windDirection.Name.DeepClone(), WindDirectionAngle = windDirection.Angle, FaultTreeIllustrationPointEntity = topLevelFaultTreeIllustrationPoint.FaultTreeNodeRoot.Create(0), Order = order }); }
public void Clone_Always_ReturnNewInstanceWithCopiedValues() { // Setup var faultTreeNodeRoot = new IllustrationPointNode(new TestIllustrationPoint()); faultTreeNodeRoot.SetChildren(new[] { new IllustrationPointNode(new TestIllustrationPoint()), new IllustrationPointNode(new TestIllustrationPoint()) }); var original = new TopLevelFaultTreeIllustrationPoint(WindDirectionTestFactory.CreateTestWindDirection(), "Random closing situation", faultTreeNodeRoot); // Call object clone = original.Clone(); // Assert CoreCloneAssert.AreObjectClones(original, clone, CommonCloneAssert.AreClones); }
private static GeneralResult <TopLevelFaultTreeIllustrationPoint> GetGeneralResultWithThreeTopLevelIllustrationPointsWithChildren(bool sameClosingSituations) { var faultTreeNodeRootWithChildren = new IllustrationPointNode(new TestFaultTreeIllustrationPoint()); faultTreeNodeRootWithChildren.SetChildren(new[] { new IllustrationPointNode(new TestSubMechanismIllustrationPoint("SubMechanismIllustrationPoint 1")), new IllustrationPointNode(new TestSubMechanismIllustrationPoint("SubMechanismIllustrationPoint 2")) }); var topLevelFaultTreeIllustrationPoint1 = new TopLevelFaultTreeIllustrationPoint( new WindDirection("Wind direction 1", 1.0), sameClosingSituations ? "same closing situation" : "first closing situation", faultTreeNodeRootWithChildren); var topLevelFaultTreeIllustrationPoint2 = new TopLevelFaultTreeIllustrationPoint( new WindDirection("Wind direction 2", 2.0), sameClosingSituations ? "same closing situation" : "second closing situation", new IllustrationPointNode(new TestSubMechanismIllustrationPoint())); var topLevelFaultTreeIllustrationPoint3 = new TopLevelFaultTreeIllustrationPoint( new WindDirection("Wind direction 3", 3.0), sameClosingSituations ? "same closing situation" : "second closing situation", new IllustrationPointNode(new TestSubMechanismIllustrationPoint())); var generalResultFunc = new GeneralResult <TopLevelFaultTreeIllustrationPoint>( WindDirectionTestFactory.CreateTestWindDirection(), Enumerable.Empty <Stochast>(), new[] { topLevelFaultTreeIllustrationPoint1, topLevelFaultTreeIllustrationPoint2, topLevelFaultTreeIllustrationPoint3 }); return(generalResultFunc); }
private static GeneralResult <TopLevelFaultTreeIllustrationPoint> GetGeneralResultWithTwoTopLevelIllustrationPoints() { var topLevelFaultTreeIllustrationPoint1 = new TopLevelFaultTreeIllustrationPoint( WindDirectionTestFactory.CreateTestWindDirection(), "Closing situation 1", new IllustrationPointNode(new TestFaultTreeIllustrationPoint())); var topLevelFaultTreeIllustrationPoint2 = new TopLevelFaultTreeIllustrationPoint( WindDirectionTestFactory.CreateTestWindDirection(), "Closing situation 2", new IllustrationPointNode(new TestSubMechanismIllustrationPoint())); return(new GeneralResult <TopLevelFaultTreeIllustrationPoint>(WindDirectionTestFactory.CreateTestWindDirection(), Enumerable.Empty <Stochast>(), new[] { topLevelFaultTreeIllustrationPoint1, topLevelFaultTreeIllustrationPoint2 })); }
private static void AssertIllustrationPointControlItems(GeneralResult <TopLevelFaultTreeIllustrationPoint> generalResult, IllustrationPointsControl illustrationPointsControl) { TopLevelFaultTreeIllustrationPoint topLevelFaultTreeIllustrationPoint1 = generalResult.TopLevelIllustrationPoints.ElementAt(0); TopLevelFaultTreeIllustrationPoint topLevelFaultTreeIllustrationPoint2 = generalResult.TopLevelIllustrationPoints.ElementAt(1); var faultTreeIllustrationPoint = (FaultTreeIllustrationPoint)topLevelFaultTreeIllustrationPoint1.FaultTreeNodeRoot.Data; var subMechanismIllustrationPoint = (SubMechanismIllustrationPoint)topLevelFaultTreeIllustrationPoint2.FaultTreeNodeRoot.Data; var expectedControlItems = new[] { new IllustrationPointControlItem(topLevelFaultTreeIllustrationPoint1, topLevelFaultTreeIllustrationPoint1.WindDirection.Name, topLevelFaultTreeIllustrationPoint1.ClosingSituation, faultTreeIllustrationPoint.Stochasts, faultTreeIllustrationPoint.Beta), new IllustrationPointControlItem(topLevelFaultTreeIllustrationPoint2, topLevelFaultTreeIllustrationPoint2.WindDirection.Name, topLevelFaultTreeIllustrationPoint2.ClosingSituation, subMechanismIllustrationPoint.Stochasts, subMechanismIllustrationPoint.Beta) }; CollectionAssert.AreEqual(expectedControlItems, illustrationPointsControl.Data, new IllustrationPointControlItemComparer()); }
public void GetStochastNamesRecursively_TopLevelFaultTreeIllustrationPointWithFaultTreeIllustrationPointAndChildrenContainingStochasts_ReturnStochastNames() { // Setup const string stochastNameA = "Stochast A"; const string stochastNameB = "Stochast B"; var illustrationPointNode = new IllustrationPointNode(new TestFaultTreeIllustrationPoint(new[] { new Stochast(stochastNameA, 2, 4), new Stochast(stochastNameB, 1, 5) })); var topLevelFaultTreeIllustrationPoint = new TopLevelFaultTreeIllustrationPoint(WindDirectionTestFactory.CreateTestWindDirection(), "closing situation", illustrationPointNode); illustrationPointNode.SetChildren(new[] { new IllustrationPointNode(new FaultTreeIllustrationPoint("Point A", 0.0, new[] { new Stochast(stochastNameA, 2, 3) }, CombinationType.And)), new IllustrationPointNode(new FaultTreeIllustrationPoint("Point B", 0.0, new[] { new Stochast(stochastNameB, 2, 3) }, CombinationType.And)) }); // Call IEnumerable <string> names = topLevelFaultTreeIllustrationPoint.GetStochastNamesRecursively(); // Assert CollectionAssert.AreEqual(new[] { stochastNameA, stochastNameB, stochastNameA, stochastNameB }, names); }
public void GivenFullyConfiguredView_WhenSelectingCellInRow_ThenSelectionChangedAndPropagatedAccordingly() { // Given var mocks = new MockRepository(); var calculation = mocks.Stub <ICalculation>(); mocks.ReplayAll(); GeneralResult <TopLevelFaultTreeIllustrationPoint> generalResult = GetGeneralResultWithTwoTopLevelIllustrationPoints(); var view = new GeneralResultFaultTreeIllustrationPointView(calculation, () => generalResult); ShowTestView(view); var selectionChangedCount = 0; view.SelectionChanged += (sender, args) => selectionChangedCount++; DataGridView dataGridView = ControlTestHelper.GetDataGridView(testForm, "DataGridView"); // When dataGridView.CurrentCell = dataGridView.Rows[1].Cells[0]; EventHelper.RaiseEvent(dataGridView, "CellClick", new DataGridViewCellEventArgs(0, 0)); // Then Assert.AreEqual(1, selectionChangedCount); IEnumerable <TopLevelFaultTreeIllustrationPoint> topLevelFaultTreeIllustrationPoints = generalResult.TopLevelIllustrationPoints.ToArray(); TopLevelFaultTreeIllustrationPoint topLevelFaultTreeIllustrationPoint = topLevelFaultTreeIllustrationPoints.ElementAt(1); AssertIllustrationPointSelection(topLevelFaultTreeIllustrationPoint, topLevelFaultTreeIllustrationPoints.Select(ip => ip.ClosingSituation), view.Selection); IllustrationPointsFaultTreeControl illustrationPointsFaultTreeControl = GetIllustrationPointsFaultTreeControl(view); Assert.AreSame(topLevelFaultTreeIllustrationPoint, illustrationPointsFaultTreeControl.Data); mocks.VerifyAll(); }
public void Create_ValidTopLevelFaultTreeIllustrationPoint_ReturnsTopLevelFaultTreeIllustrationPointEntity() { // Setup var random = new Random(21); var windDirection = new WindDirection("WindDirection Name", random.NextDouble()); var illustrationPoint = new TopLevelFaultTreeIllustrationPoint( windDirection, "Just a situation", new IllustrationPointNode(FaultTreeIllustrationPointTestFactory.CreateTestFaultTreeIllustrationPoint())); int order = random.Next(); // Call TopLevelFaultTreeIllustrationPointEntity entity = illustrationPoint.Create(order); // Assert TestHelper.AssertAreEqualButNotSame(illustrationPoint.ClosingSituation, entity.ClosingSituation); TestHelper.AssertAreEqualButNotSame(windDirection.Name, entity.WindDirectionName); Assert.AreEqual(windDirection.Angle, entity.WindDirectionAngle, windDirection.Angle.GetAccuracy()); CollectionAssert.IsEmpty(entity.FaultTreeIllustrationPointEntity.SubMechanismIllustrationPointEntities); CollectionAssert.IsEmpty(entity.FaultTreeIllustrationPointEntity.FaultTreeIllustrationPointEntity1); Assert.AreEqual(order, entity.Order); }
public void GetStochastNamesRecursively_TopLevelFaultTreeIllustrationPointWithFaultTreeIllustrationPointAndNoChildren_ReturnStochastNames() { // Setup const string stochastNameA = "Stochast A"; const string stochastNameB = "Stochast B"; var topLevelFaultTreeIllustrationPoint = new TopLevelFaultTreeIllustrationPoint(WindDirectionTestFactory.CreateTestWindDirection(), "closing situation", new IllustrationPointNode(new TestFaultTreeIllustrationPoint(new[] { new Stochast(stochastNameA, 4, 2), new Stochast(stochastNameB, 5, 4) }))); // Call IEnumerable <string> names = topLevelFaultTreeIllustrationPoint.GetStochastNamesRecursively(); // Assert CollectionAssert.AreEqual(new[] { stochastNameA, stochastNameB }, names); }
/// <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(TopLevelFaultTreeIllustrationPoint original, TopLevelFaultTreeIllustrationPoint clone) { AreClones((TopLevelIllustrationPointBase)original, clone); CoreCloneAssert.AreObjectClones(original.FaultTreeNodeRoot, clone.FaultTreeNodeRoot, AreClones); }
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 Constructor_NoUniqueClosingSituations_PropertiesHaveExpectedAttributesValues() { // Setup var topLevel = new TopLevelFaultTreeIllustrationPoint( new WindDirection("N", 5.0), "closing situation", new IllustrationPointNode(new TestFaultTreeIllustrationPoint())); // Call var properties = new TopLevelFaultTreeIllustrationPointProperties(topLevel, false); // Assert const string illustrationPointsCategoryName = "Illustratiepunten"; PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); Assert.AreEqual(7, dynamicProperties.Count); PropertyDescriptor probabilityProperty = dynamicProperties[probabilityPropertyIndex]; PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(probabilityProperty, illustrationPointsCategoryName, "Berekende kans [-]", "De berekende kans van voorkomen van het berekende resultaat.", true); PropertyDescriptor reliabilityProperty = dynamicProperties[reliabilityPropertyIndex]; PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(reliabilityProperty, illustrationPointsCategoryName, "Betrouwbaarheidsindex berekende kans [-]", "Betrouwbaarheidsindex van de berekende kans van voorkomen van het berekende resultaat.", true); PropertyDescriptor windDirectionProperty = dynamicProperties[windDirectionPropertyIndex]; PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(windDirectionProperty, illustrationPointsCategoryName, "Windrichting", "De windrichting waarvoor dit illlustratiepunt is berekend.", true); PropertyDescriptor closingSituationProperty = dynamicProperties[closingSituationPropertyIndex]; PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(closingSituationProperty, illustrationPointsCategoryName, "Keringsituatie", "De keringsituatie waarvoor dit illustratiepunt is berekend.", true); PropertyDescriptor alphasProperty = dynamicProperties[alphasPropertyIndex]; PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(alphasProperty, illustrationPointsCategoryName, "Invloedscoëfficiënten [-]", "Berekende invloedscoëfficiënten voor alle beschouwde stochasten.", true); PropertyDescriptor durationsProperty = dynamicProperties[durationsPropertyIndex]; PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(durationsProperty, illustrationPointsCategoryName, "Tijdsduren [uur]", "Tijdsduren waarop de stochasten betrekking hebben.", true); PropertyDescriptor illustrationPointProperty = dynamicProperties[illustrationPointPropertyIndex]; PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(illustrationPointProperty, illustrationPointsCategoryName, "Illustratiepunten", "De lijst van illustratiepunten voor de berekening.", true); }