public void Clone_Always_ReturnNewInstanceWithCopiedValues() { // Setup var random = new Random(21); var slidingCurve = new MacroStabilityInwardsSlidingCurve(MacroStabilityInwardsSlidingCircleTestFactory.Create(), MacroStabilityInwardsSlidingCircleTestFactory.Create(), new[] { MacroStabilityInwardsSliceTestFactory.CreateSlice() }, random.NextDouble(), random.NextDouble()); var slipPlane = new MacroStabilityInwardsSlipPlaneUpliftVan(MacroStabilityInwardsGridTestFactory.Create(), MacroStabilityInwardsGridTestFactory.Create(), new[] { random.NextRoundedDouble() }); var properties = new MacroStabilityInwardsOutput.ConstructionProperties { FactorOfStability = random.NextDouble(), ForbiddenZonesXEntryMin = random.NextDouble(), ForbiddenZonesXEntryMax = random.NextDouble() }; var original = new MacroStabilityInwardsOutput(slidingCurve, slipPlane, properties); // Call object clone = original.Clone(); // Assert CoreCloneAssert.AreObjectClones(original, clone, MacroStabilityInwardsCloneAssert.AreClones); }
public void Constructor_ExpectedValues() { // Setup MacroStabilityInwardsGrid leftGrid = MacroStabilityInwardsGridTestFactory.Create(); MacroStabilityInwardsGrid rightGrid = MacroStabilityInwardsGridTestFactory.Create(); IEnumerable <RoundedDouble> tangentLines = new[] { (RoundedDouble)3.4567, (RoundedDouble)0.1294 }; // Call var result = new MacroStabilityInwardsSlipPlaneUpliftVan(leftGrid, rightGrid, tangentLines); // Assert Assert.IsInstanceOf <ICloneable>(result); Assert.AreSame(leftGrid, result.LeftGrid); Assert.AreSame(rightGrid, result.RightGrid); CollectionAssert.AreEqual(new[] { 2, 2 }, result.TangentLines.Select(tl => tl.NumberOfDecimalPlaces)); CollectionAssert.AreEqual(tangentLines.Select(tl => tl.Value), result.TangentLines.Select(tl => tl.Value), new DoubleWithToleranceComparer(1e-2)); }
private static void AssertSlipPlaneProperties(MacroStabilityInwardsSlipPlaneUpliftVan slipPlane, MacroStabilityInwardsCalculationOutputEntity entity) { string expectedTangentLinesXml = new TangentLineCollectionXmlSerializer().ToXml(slipPlane.TangentLines); Assert.AreEqual(expectedTangentLinesXml, entity.SlipPlaneTangentLinesXml); MacroStabilityInwardsGrid leftGrid = slipPlane.LeftGrid; AssertAreEqual(leftGrid.XLeft, entity.SlipPlaneLeftGridXLeft); AssertAreEqual(leftGrid.XRight, entity.SlipPlaneLeftGridXRight); Assert.AreEqual(leftGrid.NumberOfHorizontalPoints, entity.SlipPlaneLeftGridNrOfHorizontalPoints); AssertAreEqual(leftGrid.ZTop, entity.SlipPlaneLeftGridZTop); AssertAreEqual(leftGrid.ZBottom, entity.SlipPlaneLeftGridZBottom); Assert.AreEqual(leftGrid.NumberOfVerticalPoints, entity.SlipPlaneLeftGridNrOfVerticalPoints); MacroStabilityInwardsGrid rightGrid = slipPlane.RightGrid; AssertAreEqual(rightGrid.XLeft, entity.SlipPlaneRightGridXLeft); AssertAreEqual(rightGrid.XRight, entity.SlipPlaneRightGridXRight); Assert.AreEqual(rightGrid.NumberOfHorizontalPoints, entity.SlipPlaneRightGridNrOfHorizontalPoints); AssertAreEqual(rightGrid.ZTop, entity.SlipPlaneRightGridZTop); AssertAreEqual(rightGrid.ZBottom, entity.SlipPlaneRightGridZBottom); Assert.AreEqual(rightGrid.NumberOfVerticalPoints, entity.SlipPlaneRightGridNrOfVerticalPoints); }
/// <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(MacroStabilityInwardsSlipPlaneUpliftVan original, MacroStabilityInwardsSlipPlaneUpliftVan clone) { CoreCloneAssert.AreObjectClones(original.LeftGrid, clone.LeftGrid, AreClones); CoreCloneAssert.AreObjectClones(original.RightGrid, clone.RightGrid, AreClones); CoreCloneAssert.AreEnumerationClones(original.TangentLines, clone.TangentLines, (originalTangentLine, clonedTangentLine) => Assert.AreEqual(originalTangentLine, clonedTangentLine)); }
public void Create_WithNaNValues_ReturnsPropertyWithExpectedPropertiesSet() { // Setup MacroStabilityInwardsSlidingCircle leftCircle = CreateSlidingCircleWithNaNValues(); MacroStabilityInwardsSlidingCircle rightCircle = CreateSlidingCircleWithNaNValues(); var slidingCurve = new MacroStabilityInwardsSlidingCurve(leftCircle, rightCircle, new MacroStabilityInwardsSlice[0], double.NaN, double.NaN); var slipPlane = new MacroStabilityInwardsSlipPlaneUpliftVan(CreateGridWithNaNValues(), CreateGridWithNaNValues(), new RoundedDouble[0]); var output = new MacroStabilityInwardsOutput(slidingCurve, slipPlane, new MacroStabilityInwardsOutput.ConstructionProperties()); // Call MacroStabilityInwardsCalculationOutputEntity entity = output.Create(); // Assert Assert.IsNotNull(entity); Assert.IsNull(entity.FactorOfStability); Assert.IsNull(entity.ForbiddenZonesXEntryMin); Assert.IsNull(entity.ForbiddenZonesXEntryMax); Assert.IsNull(entity.SlipPlaneLeftGridXLeft); Assert.IsNull(entity.SlipPlaneLeftGridXRight); Assert.IsNull(entity.SlipPlaneLeftGridZTop); Assert.IsNull(entity.SlipPlaneLeftGridZBottom); Assert.IsNull(entity.SlipPlaneRightGridXLeft); Assert.IsNull(entity.SlipPlaneRightGridXRight); Assert.IsNull(entity.SlipPlaneRightGridZTop); Assert.IsNull(entity.SlipPlaneRightGridZBottom); Assert.IsNull(entity.SlidingCurveIteratedHorizontalForce); Assert.IsNull(entity.SlidingCurveNonIteratedHorizontalForce); Assert.IsNull(entity.SlidingCurveLeftSlidingCircleCenterX); Assert.IsNull(entity.SlidingCurveLeftSlidingCircleCenterY); Assert.IsNull(entity.SlidingCurveLeftSlidingCircleRadius); Assert.IsNull(entity.SlidingCurveLeftSlidingCircleIteratedForce); Assert.IsNull(entity.SlidingCurveLeftSlidingCircleNonIteratedForce); Assert.IsNull(entity.SlidingCurveLeftSlidingCircleDrivingMoment); Assert.IsNull(entity.SlidingCurveLeftSlidingCircleResistingMoment); Assert.IsNull(entity.SlidingCurveRightSlidingCircleCenterX); Assert.IsNull(entity.SlidingCurveRightSlidingCircleCenterY); Assert.IsNull(entity.SlidingCurveRightSlidingCircleRadius); Assert.IsNull(entity.SlidingCurveRightSlidingCircleIteratedForce); Assert.IsNull(entity.SlidingCurveRightSlidingCircleNonIteratedForce); Assert.IsNull(entity.SlidingCurveRightSlidingCircleDrivingMoment); Assert.IsNull(entity.SlidingCurveRightSlidingCircleResistingMoment); }
public void Constructor_SlidingCurveNull_ThrowsArgumentNullException() { // Setup var slipPlane = new MacroStabilityInwardsSlipPlaneUpliftVan(MacroStabilityInwardsGridTestFactory.Create(), MacroStabilityInwardsGridTestFactory.Create(), new RoundedDouble[0]); // Call TestDelegate call = () => new MacroStabilityInwardsOutput(null, slipPlane, new MacroStabilityInwardsOutput.ConstructionProperties()); // Assert var exception = Assert.Throws <ArgumentNullException>(call); Assert.AreEqual("slidingCurve", exception.ParamName); }
/// <summary> /// Read the <see cref="MacroStabilityInwardsCalculationOutputEntity"/> and use the information to /// construct a <see cref="MacroStabilityInwardsOutput"/>. /// </summary> /// <param name="entity">The <see cref="MacroStabilityInwardsCalculationOutputEntity"/> to create /// <see cref="MacroStabilityInwardsOutput"/> for.</param> /// <returns>A new <see cref="MacroStabilityInwardsOutput"/>.</returns> /// <exception cref="ArgumentNullException">Thrown when <paramref name="entity"/> is <c>null</c>.</exception> public static MacroStabilityInwardsOutput Read(this MacroStabilityInwardsCalculationOutputEntity entity) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } MacroStabilityInwardsSlipPlaneUpliftVan slipPlane = ReadSlipPlane(entity); MacroStabilityInwardsSlidingCurve slidingCurve = ReadSlidingCurve(entity); return(new MacroStabilityInwardsOutput(slidingCurve, slipPlane, new MacroStabilityInwardsOutput.ConstructionProperties { FactorOfStability = entity.FactorOfStability.ToNullAsNaN(), ForbiddenZonesXEntryMax = entity.ForbiddenZonesXEntryMax.ToNullAsNaN(), ForbiddenZonesXEntryMin = entity.ForbiddenZonesXEntryMin.ToNullAsNaN() })); }
public void Clone_Always_ReturnNewInstanceWithCopiedValues() { // Setup var random = new Random(21); var original = new MacroStabilityInwardsSlipPlaneUpliftVan(MacroStabilityInwardsGridTestFactory.Create(), MacroStabilityInwardsGridTestFactory.Create(), new[] { random.NextRoundedDouble() }); // Call object clone = original.Clone(); // Assert CoreCloneAssert.AreObjectClones(original, clone, MacroStabilityInwardsCloneAssert.AreClones); }
public void Constructor_ConstructionPropertiesWithoutValuesSet_PropertiesAreDefault() { // Setup var slidingCurve = new MacroStabilityInwardsSlidingCurve(MacroStabilityInwardsSlidingCircleTestFactory.Create(), MacroStabilityInwardsSlidingCircleTestFactory.Create(), new MacroStabilityInwardsSlice[0], 0, 0); var slipPlane = new MacroStabilityInwardsSlipPlaneUpliftVan(MacroStabilityInwardsGridTestFactory.Create(), MacroStabilityInwardsGridTestFactory.Create(), new RoundedDouble[0]); // Call var output = new MacroStabilityInwardsOutput(slidingCurve, slipPlane, new MacroStabilityInwardsOutput.ConstructionProperties()); // Assert Assert.IsNaN(output.FactorOfStability); Assert.IsNaN(output.ForbiddenZonesXEntryMin); Assert.IsNaN(output.ForbiddenZonesXEntryMax); }
public void Create_WithValidValues_ReturnsEntityWithExpectedPropertiesSet() { // Setup var random = new Random(21); MacroStabilityInwardsSlidingCircle leftCircle = CreateSlidingCircle(13); MacroStabilityInwardsSlidingCircle rightCircle = CreateSlidingCircle(34); IEnumerable<MacroStabilityInwardsSlice> slices = new[] { MacroStabilityInwardsSliceTestFactory.CreateSlice() }; var slidingCurve = new MacroStabilityInwardsSlidingCurve(leftCircle, rightCircle, slices, random.NextDouble(), random.NextDouble()); MacroStabilityInwardsGrid leftGrid = MacroStabilityInwardsGridTestFactory.Create(); MacroStabilityInwardsGrid rightGrid = MacroStabilityInwardsGridTestFactory.Create(); RoundedDouble[] tangentLines = { random.NextRoundedDouble() }; var slipPlane = new MacroStabilityInwardsSlipPlaneUpliftVan(leftGrid, rightGrid, tangentLines); var output = new MacroStabilityInwardsOutput(slidingCurve, slipPlane, new MacroStabilityInwardsOutput.ConstructionProperties { FactorOfStability = random.NextDouble(), ForbiddenZonesXEntryMax = random.NextDouble(), ForbiddenZonesXEntryMin = random.NextDouble() }); // Call MacroStabilityInwardsCalculationOutputEntity entity = output.Create(); // Assert Assert.IsNotNull(entity); MacroStabilityInwardsCalculationOutputEntityTestHelper.AssertOutputPropertyValues(output, entity); }
public void Constructor_ExpectedValues() { // Setup var slidingCurve = new MacroStabilityInwardsSlidingCurve(MacroStabilityInwardsSlidingCircleTestFactory.Create(), MacroStabilityInwardsSlidingCircleTestFactory.Create(), new MacroStabilityInwardsSlice[0], 0, 0); var slipPlane = new MacroStabilityInwardsSlipPlaneUpliftVan(MacroStabilityInwardsGridTestFactory.Create(), MacroStabilityInwardsGridTestFactory.Create(), new RoundedDouble[0]); var random = new Random(21); double factorOfStability = random.NextDouble(); double zValue = random.NextDouble(); double xEntryMin = random.NextDouble(); double xEntryMax = random.NextDouble(); var properties = new MacroStabilityInwardsOutput.ConstructionProperties { FactorOfStability = factorOfStability, ForbiddenZonesXEntryMin = xEntryMin, ForbiddenZonesXEntryMax = xEntryMax }; // Call var output = new MacroStabilityInwardsOutput(slidingCurve, slipPlane, properties); // Assert Assert.IsInstanceOf <CloneableObservable>(output); Assert.IsInstanceOf <ICalculationOutput>(output); Assert.AreSame(slidingCurve, output.SlidingCurve); Assert.AreSame(slipPlane, output.SlipPlane); Assert.AreEqual(factorOfStability, output.FactorOfStability); Assert.AreEqual(xEntryMin, output.ForbiddenZonesXEntryMin); Assert.AreEqual(xEntryMax, output.ForbiddenZonesXEntryMax); }
private static void SetSlipPlaneParametersToEntity(MacroStabilityInwardsCalculationOutputEntity entity, MacroStabilityInwardsSlipPlaneUpliftVan slipPlane) { entity.SlipPlaneTangentLinesXml = new TangentLineCollectionXmlSerializer().ToXml(slipPlane.TangentLines); MacroStabilityInwardsGrid leftGrid = slipPlane.LeftGrid; entity.SlipPlaneLeftGridXLeft = leftGrid.XLeft.ToNaNAsNull(); entity.SlipPlaneLeftGridXRight = leftGrid.XRight.ToNaNAsNull(); entity.SlipPlaneLeftGridNrOfHorizontalPoints = leftGrid.NumberOfHorizontalPoints; entity.SlipPlaneLeftGridZTop = leftGrid.ZTop.ToNaNAsNull(); entity.SlipPlaneLeftGridZBottom = leftGrid.ZBottom.ToNaNAsNull(); entity.SlipPlaneLeftGridNrOfVerticalPoints = leftGrid.NumberOfVerticalPoints; MacroStabilityInwardsGrid rightGrid = slipPlane.RightGrid; entity.SlipPlaneRightGridXLeft = rightGrid.XLeft.ToNaNAsNull(); entity.SlipPlaneRightGridXRight = rightGrid.XRight.ToNaNAsNull(); entity.SlipPlaneRightGridNrOfHorizontalPoints = rightGrid.NumberOfHorizontalPoints; entity.SlipPlaneRightGridZTop = rightGrid.ZTop.ToNaNAsNull(); entity.SlipPlaneRightGridZBottom = rightGrid.ZBottom.ToNaNAsNull(); entity.SlipPlaneRightGridNrOfVerticalPoints = rightGrid.NumberOfVerticalPoints; }
public void Convert_WithResult_ReturnConvertedSlipPlaneUpliftVan() { // Setup UpliftVanGrid leftGrid = UpliftVanGridTestFactory.Create(); UpliftVanGrid rightGrid = UpliftVanGridTestFactory.Create(); double[] tangentLines = { 3, 2, 1.5 }; var result = new UpliftVanCalculationGridResult(leftGrid, rightGrid, tangentLines); // Call MacroStabilityInwardsSlipPlaneUpliftVan output = MacroStabilityInwardsSlipPlaneUpliftVanConverter.Convert(result); // Assert CollectionAssert.AreEqual(tangentLines, output.TangentLines.Select(tl => tl.Value), new DoubleWithToleranceComparer(1e-2)); AssertGrid(leftGrid, output.LeftGrid); AssertGrid(rightGrid, output.RightGrid); }