Change curvature calculator
This commit is contained in:
@@ -0,0 +1,136 @@
|
||||
using NUnit.Framework;
|
||||
using Moq;
|
||||
using System.Collections.Generic;
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Models.Calculators;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperLogics.NdmCalculations.Analyses.ByForces.Logics;
|
||||
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
|
||||
using StructureHelperLogics.NdmCalculations.Primitives;
|
||||
using LoaderCalculator.Data.Ndms;
|
||||
using StructureHelperCommon.Models.Forces;
|
||||
|
||||
namespace StructureHelperTests.UnitTests.Calcuators
|
||||
{
|
||||
|
||||
|
||||
[TestFixture]
|
||||
public class CheckForceTupleInputDataLogicTests
|
||||
{
|
||||
private Mock<IForceTupleInputData> _mockInputData;
|
||||
private Mock<IShiftTraceLogger> _mockTraceLogger;
|
||||
private CheckForceTupleInputDataLogic _checkLogic;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_mockInputData = new Mock<IForceTupleInputData>();
|
||||
_mockTraceLogger = new Mock<IShiftTraceLogger>();
|
||||
|
||||
_checkLogic = new CheckForceTupleInputDataLogic(_mockInputData.Object, _mockTraceLogger.Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Check_InputDataIsNull_ThrowsStructureHelperException()
|
||||
{
|
||||
// Arrange
|
||||
_checkLogic = new CheckForceTupleInputDataLogic(null, _mockTraceLogger.Object);
|
||||
|
||||
// Act & Assert
|
||||
var ex = Assert.Throws<StructureHelperException>(() => _checkLogic.Check());
|
||||
Assert.That(ex.Message, Is.EqualTo(ErrorStrings.ParameterIsNull + ": Input data"));
|
||||
_mockTraceLogger.Verify(x => x.AddMessage(ErrorStrings.ParameterIsNull + ": Input data"), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Check_NdmCollectionIsNullOrEmpty_ReturnsFalseAndLogsError()
|
||||
{
|
||||
// Arrange
|
||||
_mockInputData.Setup(x => x.NdmCollection).Returns((IEnumerable<INdm>)null);
|
||||
|
||||
// Act
|
||||
var result = _checkLogic.Check();
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.False);
|
||||
//Assert.That(_checkLogic.CheckResult, Is.EqualTo("Ndm collection is null or empty"));
|
||||
_mockTraceLogger.Verify(x => x.AddMessage("\nNdm collection is null or empty"), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Check_TupleIsNull_ReturnsFalseAndLogsError()
|
||||
{
|
||||
// Arrange
|
||||
_mockInputData.Setup(x => x.NdmCollection).Returns(new List<INdm>());
|
||||
_mockInputData.Setup(x => x.ForceTuple).Returns((IForceTuple)null);
|
||||
|
||||
// Act
|
||||
var result = _checkLogic.Check();
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.False);
|
||||
//Assert.That(_checkLogic.CheckResult, Is.EqualTo("Force tuple is null"));
|
||||
_mockTraceLogger.Verify(x => x.AddMessage("\nForce tuple is null"), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Check_AccuracyIsNull_ReturnsFalseAndLogsError()
|
||||
{
|
||||
// Arrange
|
||||
_mockInputData.Setup(x => x.NdmCollection).Returns(new List<INdm>());
|
||||
_mockInputData.Setup(x => x.ForceTuple).Returns(new ForceTuple());
|
||||
_mockInputData.Setup(x => x.Accuracy).Returns((IAccuracy)null);
|
||||
|
||||
// Act
|
||||
var result = _checkLogic.Check();
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.False);
|
||||
//Assert.That(_checkLogic.CheckResult, Is.EqualTo("Accuracy requirements is not assigned"));
|
||||
_mockTraceLogger.Verify(x => x.AddMessage("\nAccuracy requirements is not assigned"), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Check_AccuracyValuesAreInvalid_ReturnsFalseAndLogsErrors()
|
||||
{
|
||||
// Arrange
|
||||
var mockAccuracy = new Mock<IAccuracy>();
|
||||
mockAccuracy.Setup(x => x.IterationAccuracy).Returns(0);
|
||||
mockAccuracy.Setup(x => x.MaxIterationCount).Returns(0);
|
||||
|
||||
_mockInputData.Setup(x => x.NdmCollection).Returns(new List<INdm>());
|
||||
_mockInputData.Setup(x => x.ForceTuple).Returns(new ForceTuple());
|
||||
_mockInputData.Setup(x => x.Accuracy).Returns(mockAccuracy.Object);
|
||||
|
||||
// Act
|
||||
var result = _checkLogic.Check();
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.False);
|
||||
//Assert.That(_checkLogic.CheckResult, Is.EqualTo("Value of accuracy 0 must be grater than zeroMax number of iteration 0 must be grater than zero"));
|
||||
_mockTraceLogger.Verify(x => x.AddMessage("\nValue of accuracy 0 must be grater than zero"), Times.Once);
|
||||
_mockTraceLogger.Verify(x => x.AddMessage("\nMax number of iteration 0 must be grater than zero"), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Check_AllConditionsMet_ReturnsTrue()
|
||||
{
|
||||
// Arrange
|
||||
var mockAccuracy = new Mock<IAccuracy>();
|
||||
mockAccuracy.Setup(x => x.IterationAccuracy).Returns(1);
|
||||
mockAccuracy.Setup(x => x.MaxIterationCount).Returns(10);
|
||||
|
||||
_mockInputData.Setup(x => x.NdmCollection).Returns(new List<INdm> { new Mock<INdm>().Object });
|
||||
_mockInputData.Setup(x => x.ForceTuple).Returns(new ForceTuple());
|
||||
_mockInputData.Setup(x => x.Accuracy).Returns(mockAccuracy.Object);
|
||||
|
||||
// Act
|
||||
var result = _checkLogic.Check();
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.True);
|
||||
Assert.That(_checkLogic.CheckResult, Is.EqualTo(string.Empty));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using NUnit.Framework;
|
||||
using StructureHelperCommon.Models.Calculators;
|
||||
|
||||
namespace StructureHelperTests.UnitTests.Calcuators
|
||||
{
|
||||
internal class FindParameterTest
|
||||
{
|
||||
[TestCase(0d, 1d, 0.5d, 0.5d)]
|
||||
[TestCase(0d, 10d, 5d, 5d)]
|
||||
public void Run_ShouldPass_Valid(double startValue, double endValue, double predicateValue, double expectedValue)
|
||||
{
|
||||
//Arrange
|
||||
var calculator = new FindParameterCalculator();
|
||||
calculator.InputData.StartValue = startValue;
|
||||
calculator.InputData.EndValue = endValue; ;
|
||||
calculator.InputData.Predicate = x => x > predicateValue;
|
||||
|
||||
//Act
|
||||
calculator.Run();
|
||||
var result = calculator.Result as FindParameterResult;
|
||||
//Assert
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.IsValid, Is.True);
|
||||
Assert.That(expectedValue, Is.EqualTo(predicateValue).Within(0.001d));
|
||||
}
|
||||
[TestCase(0d, 1d, 5d, 5d, false)]
|
||||
[TestCase(0d, 10d, 15d, 15d, false)]
|
||||
public void Run_ShouldPass_NotValid(double startValue, double endValue, double predicateValue, double expectedValue, bool isValid)
|
||||
{
|
||||
//Arrange
|
||||
var calculator = new FindParameterCalculator();
|
||||
calculator.InputData.StartValue = startValue;
|
||||
calculator.InputData.EndValue = endValue; ;
|
||||
calculator.InputData.Predicate = x => x > predicateValue;
|
||||
//Act
|
||||
calculator.Run();
|
||||
var result = calculator.Result as FindParameterResult;
|
||||
//Assert
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.IsValid == isValid, Is.True);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Models.Shapes;
|
||||
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
|
||||
|
||||
namespace StructureHelperTests.UnitTests.Calcuators
|
||||
{
|
||||
[TestFixture]
|
||||
public class LimitCurveCalculatorTest
|
||||
{
|
||||
[TestCase(10d, 20d)]
|
||||
public void Run_ShouldPass(double xmax, double ymax)
|
||||
{
|
||||
//Arrange
|
||||
var calculator = new LimitCurveCalculator(new StabLimitCurveLogic())
|
||||
{
|
||||
};
|
||||
calculator.PointCount = 12;
|
||||
calculator.SurroundData.XMax = xmax;
|
||||
calculator.SurroundData.XMin = -xmax;
|
||||
calculator.SurroundData.YMax = ymax;
|
||||
calculator.SurroundData.YMin = -ymax;
|
||||
//Act
|
||||
calculator.Run();
|
||||
var result = calculator.Result;
|
||||
//Assert
|
||||
Assert.That(result, Is.Not.Null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Models.Shapes;
|
||||
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
|
||||
using StructureHelperLogics.NdmCalculations.Analyses.ByForces.LimitCurve.Factories;
|
||||
|
||||
namespace StructureHelperTests.UnitTests.Calcuators
|
||||
{
|
||||
[TestFixture]
|
||||
public class LimitCurveLogicTests
|
||||
{
|
||||
[Test]
|
||||
public void GetPoints_ValidPoints_ReturnsTransformedPoints()
|
||||
{
|
||||
// Arrange
|
||||
var getPredicateLogic = new Mock<IGetPredicateLogic>();
|
||||
getPredicateLogic.Setup(p => p.GetPredicate()).Returns(point => point.X >= 0.5d);//
|
||||
|
||||
var limitCurveLogic = new LimitCurveLogic(getPredicateLogic.Object);
|
||||
|
||||
|
||||
var inputPoints = new List<IPoint2D>
|
||||
{
|
||||
new Point2D { X = 1, Y = 2 },
|
||||
new Point2D { X = 3, Y = 4 }
|
||||
// Add more points as needed
|
||||
};
|
||||
|
||||
// Act
|
||||
var result = limitCurveLogic.GetPoints(inputPoints);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.Count, Is.EqualTo(inputPoints.Count));
|
||||
for (int i = 0; i < inputPoints.Count; i++)
|
||||
{
|
||||
Assert.That(result[i].X, Is.EqualTo(0.5d).Within(0.01d));
|
||||
Assert.That(result[i].Y, Is.EqualTo(inputPoints[i].Y / inputPoints[i].X * 0.5d).Within(0.01d));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
using NUnit.Framework;
|
||||
using StructureHelperCommon.Models.Soils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperTests.UnitTests.Calcuators
|
||||
{
|
||||
[TestFixture]
|
||||
public class SoilAnchorCalculatorTest
|
||||
{
|
||||
[TestCase(6d, 0.483d, 7d, 0d, -2.188d, 25d, 30e3d, 2005767.1007324921d, 1671472.5839437435d)]
|
||||
[TestCase(6d, 0.483d, 7d, 0d, -2.188d, 30d, 0d, 1437198.1109237692d, 1197665.0924364743d)]
|
||||
public void Run_ShouldPass(double rootLength, double rootDiameter, double freeLength, double graundLevel, double headLevel, double fi, double c, double expectedCharBearingCapacity, double expectedDesignBearingCapacity)
|
||||
{
|
||||
//Arrange
|
||||
var anchor = new SoilAnchor()
|
||||
{
|
||||
RootLength = rootLength,
|
||||
RootDiameter = rootDiameter,
|
||||
FreeLength = freeLength,
|
||||
GroundLevel = graundLevel,
|
||||
HeadLevel = headLevel,
|
||||
};
|
||||
var soil = new AnchorSoilProperties()
|
||||
{
|
||||
FrictionAngle = fi,
|
||||
Coheasion = c
|
||||
};
|
||||
//Act
|
||||
var calculator = new AnchorCalculator(anchor, soil);
|
||||
calculator.Run();
|
||||
var result = calculator.Result as AnchorResult;
|
||||
//Assert
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.CharBearingCapacity, Is.EqualTo(expectedCharBearingCapacity).Within(expectedCharBearingCapacity * 1e-6d));
|
||||
Assert.That(result.DesignBearingCapacity, Is.EqualTo(expectedDesignBearingCapacity).Within(expectedDesignBearingCapacity * 1e-6d));
|
||||
}
|
||||
|
||||
[TestCase(6d, 0.2d, 7d, 0.145d, 0.28290937500000002d, 0.13633537500000006d)]
|
||||
[TestCase(6d, 0.483, 7d, 0.145d, 1.6716908400000001d, 1.5251168399999999d)]
|
||||
public void Run_ShouldPass_Volume(double rootLength, double rootDiameter, double freeLength, double boreHoleDiameter, double expectedVolume1, double expectedVolume2)
|
||||
{
|
||||
//Arrange
|
||||
var anchor = new SoilAnchor()
|
||||
{
|
||||
RootLength = rootLength,
|
||||
RootDiameter = rootDiameter,
|
||||
FreeLength = freeLength,
|
||||
BoreHoleDiameter = boreHoleDiameter,
|
||||
};
|
||||
var soil = new AnchorSoilProperties();
|
||||
//Act
|
||||
var calculator = new AnchorCalculator(anchor, soil);
|
||||
calculator.Run();
|
||||
var result = calculator.Result as AnchorResult;
|
||||
//Assert
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result.MortarVolumeFstStady, Is.EqualTo(expectedVolume1).Within(expectedVolume1 * 1e-6d));
|
||||
Assert.That(result.MortarVolumeSndStady, Is.EqualTo(expectedVolume2).Within(expectedVolume2 * 1e-6d));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user