Change curvature calculator

This commit is contained in:
Evgeny Redikultsev
2025-11-29 21:43:00 +05:00
parent 5daa32a954
commit f381229a63
73 changed files with 1361 additions and 406 deletions

View File

@@ -0,0 +1,129 @@
using Moq;
using NUnit.Framework;
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Forces;
using StructureHelperLogics.NdmCalculations.Analyses.Curvatures;
using StructureHelperLogics.NdmCalculations.Primitives;
namespace StructureHelperTests.UnitTests.Curvatures
{
[TestFixture]
public class CurvatureCalculatorInputDataUpdateStrategyTests
{
private Mock<IUpdateStrategy<IDeflectionFactor>> _deflectionUpdateMock;
private CurvatureCalculatorInputDataUpdateStrategy _strategy;
private Mock<ICurvatureCalculatorInputData> _targetMock;
private Mock<ICurvatureCalculatorInputData> _sourceMock;
private List<INdmPrimitive> _targetPrimitives;
private List<INdmPrimitive> _sourcePrimitives;
private List<IForceAction> _targetForces;
private List<IForceAction> _sourceForces;
private Mock<IDeflectionFactor> _targetDeflectionFactorMock;
private Mock<IDeflectionFactor> _sourceDeflectionFactorMock;
[SetUp]
public void Setup()
{
_deflectionUpdateMock = new Mock<IUpdateStrategy<IDeflectionFactor>>();
_strategy = new CurvatureCalculatorInputDataUpdateStrategy(_deflectionUpdateMock.Object);
// Mock target and source ICurvatureCalculatorInputData
_targetMock = new Mock<ICurvatureCalculatorInputData>();
_sourceMock = new Mock<ICurvatureCalculatorInputData>();
_targetPrimitives = new List<INdmPrimitive> { new Mock<INdmPrimitive>().Object };
_sourcePrimitives = new List<INdmPrimitive> { new Mock<INdmPrimitive>().Object, new Mock<INdmPrimitive>().Object };
_targetForces = new List<IForceAction> { new Mock<IForceAction>().Object };
_sourceForces = new List<IForceAction> { new Mock<IForceAction>().Object, new Mock<IForceAction>().Object };
_targetDeflectionFactorMock = new Mock<IDeflectionFactor>();
_sourceDeflectionFactorMock = new Mock<IDeflectionFactor>();
_targetMock.SetupGet(x => x.Primitives).Returns(_targetPrimitives);
_targetMock.SetupGet(x => x.ForceActions).Returns(_targetForces);
_targetMock.SetupGet(x => x.DeflectionFactor).Returns(_targetDeflectionFactorMock.Object);
_sourceMock.SetupGet(x => x.Primitives).Returns(_sourcePrimitives);
_sourceMock.SetupGet(x => x.ForceActions).Returns(_sourceForces);
_sourceMock.SetupGet(x => x.DeflectionFactor).Returns(_sourceDeflectionFactorMock.Object);
}
// ---------------------------------------------------------
// TEST 1 — Basic update copies collections and calls DeflectionFactor update
// ---------------------------------------------------------
[Test]
public void Update_ShouldCopyCollections_AndCallDeflectionUpdate()
{
// Act
_strategy.Update(_targetMock.Object, _sourceMock.Object);
// Assert — target collections replaced by source
Assert.That(_targetPrimitives, Is.EqualTo(_sourcePrimitives));
Assert.That(_targetForces, Is.EqualTo(_sourceForces));
// DeflectionFactor update called
_deflectionUpdateMock.Verify(x =>
x.Update(_targetDeflectionFactorMock.Object, _sourceDeflectionFactorMock.Object), Times.Once);
}
// ---------------------------------------------------------
// TEST 2 — Should throw if target is null
// ---------------------------------------------------------
[Test]
public void Update_ShouldThrow_WhenTargetIsNull()
{
Assert.Throws<StructureHelperException>(() =>
_strategy.Update(null!, _sourceMock.Object));
}
// ---------------------------------------------------------
// TEST 3 — Should throw if source is null
// ---------------------------------------------------------
[Test]
public void Update_ShouldThrow_WhenSourceIsNull()
{
Assert.Throws<StructureHelperException>(() =>
_strategy.Update(_targetMock.Object, null!));
}
// ---------------------------------------------------------
// TEST 4 — Should not update if source and target are the same
// ---------------------------------------------------------
[Test]
public void Update_ShouldNotCallDeflectionUpdate_WhenSourceAndTargetSame()
{
_strategy.Update(_targetMock.Object, _targetMock.Object);
_deflectionUpdateMock.Verify(x =>
x.Update(It.IsAny<IDeflectionFactor>(), It.IsAny<IDeflectionFactor>()), Times.Never);
}
// ---------------------------------------------------------
// TEST 5 — Should skip children if UpdateChildren = false
// ---------------------------------------------------------
[Test]
public void Update_ShouldSkipChildren_WhenUpdateChildrenFalse()
{
_strategy.UpdateChildren = false;
_strategy.Update(_targetMock.Object, _sourceMock.Object);
_deflectionUpdateMock.Verify(x =>
x.Update(It.IsAny<IDeflectionFactor>(), It.IsAny<IDeflectionFactor>()), Times.Never);
// Collections unchanged
Assert.That(_targetPrimitives, Is.Not.EqualTo(_sourcePrimitives));
Assert.That(_targetForces, Is.Not.EqualTo(_sourceForces));
}
}
}

View File

@@ -0,0 +1,138 @@
using Moq;
using NUnit.Framework;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Forces;
using StructureHelperLogics.NdmCalculations.Analyses.Curvatures;
namespace StructureHelperTests.UnitTests.Curvatures
{
[TestFixture]
public class GetDeflectionByCurvatureLogicTests
{
private Mock<IShiftTraceLogger> _logger;
private GetDeflectionByCurvatureLogic _logic;
private Mock<IForceTuple> _curvature;
private Mock<IDeflectionFactor> _factor;
private Mock<IForceTuple> _k;
private Mock<IForceTuple> _max;
[SetUp]
public void Setup()
{
_logger = new Mock<IShiftTraceLogger>();
_logic = new GetDeflectionByCurvatureLogic(_logger.Object);
_curvature = new Mock<IForceTuple>();
_factor = new Mock<IDeflectionFactor>();
_k = new Mock<IForceTuple>();
_max = new Mock<IForceTuple>();
_factor.Setup(f => f.DeflectionFactors).Returns(_k.Object);
_factor.Setup(f => f.MaxDeflections).Returns(_max.Object);
}
[Test]
public void GetDeflection_ComputesDeflectionMxCorrectly()
{
_factor.Setup(f => f.SpanLength).Returns(5.0);
_k.Setup(f => f.Mx).Returns(2.0);
_curvature.Setup(c => c.Mx).Returns(3.0);
_max.Setup(m => m.Mx).Returns(10.0);
var result = _logic.GetDeflection(_curvature.Object, _factor.Object);
// Expected: k * curvature * L^2 = 2 * 3 * 25 = 150
Assert.That(result.DeflectionMx.Deflection, Is.EqualTo(150.0));
Assert.That(result.DeflectionMx.Curvature, Is.EqualTo(3.0));
Assert.That(result.DeflectionMx.UltimateDeflection, Is.EqualTo(10.0));
}
[Test]
public void GetDeflection_ComputesDeflectionMyCorrectly()
{
_factor.Setup(f => f.SpanLength).Returns(4.0);
_k.Setup(f => f.My).Returns(1.5);
_curvature.Setup(c => c.My).Returns(2.0);
_max.Setup(m => m.My).Returns(7.0);
var result = _logic.GetDeflection(_curvature.Object, _factor.Object);
// Expected: 1.5 * 2 * 16 = 48
Assert.That(result.DeflectionMy.Deflection, Is.EqualTo(48.0));
Assert.That(result.DeflectionMy.Curvature, Is.EqualTo(2.0));
Assert.That(result.DeflectionMy.UltimateDeflection, Is.EqualTo(7.0));
}
[Test]
public void GetDeflection_ComputesDeflectionNzCorrectly()
{
_factor.Setup(f => f.SpanLength).Returns(10.0);
_k.Setup(f => f.Nz).Returns(1.2);
_curvature.Setup(c => c.Nz).Returns(4.0);
_max.Setup(m => m.Nz).Returns(5.0);
var result = _logic.GetDeflection(_curvature.Object, _factor.Object);
// Expected: 1.2 * 4 * 10 = 48
Assert.That(result.DeflectionNz.Deflection, Is.EqualTo(48.0));
Assert.That(result.DeflectionNz.Curvature, Is.EqualTo(4.0));
Assert.That(result.DeflectionNz.UltimateDeflection, Is.EqualTo(5.0));
}
[Test]
public void GetDeflection_LogsSpanLength()
{
_factor.Setup(f => f.SpanLength).Returns(6.0);
_logic.GetDeflection(_curvature.Object, _factor.Object);
_logger.Verify(l => l.AddMessage("Span length L = 6(m)"), Times.Once);
}
[Test]
public void GetDeflection_LogsAllDeflectionsInCorrectFormat()
{
_factor.Setup(f => f.SpanLength).Returns(3.0);
_k.Setup(f => f.Mx).Returns(2);
_k.Setup(f => f.My).Returns(3);
_k.Setup(f => f.Nz).Returns(4);
_curvature.Setup(c => c.Mx).Returns(1.0);
_curvature.Setup(c => c.My).Returns(2.0);
_curvature.Setup(c => c.Nz).Returns(3.0);
_max.Setup(m => m.Mx).Returns(0);
_max.Setup(m => m.My).Returns(0);
_max.Setup(m => m.Nz).Returns(0);
_logic.GetDeflection(_curvature.Object, _factor.Object);
_logger.Verify(l =>
l.AddMessage("Deflection along X axis = 2 * 1 * (3)^2 = 18(m)"),
Times.Once);
_logger.Verify(l =>
l.AddMessage("Deflection along Y axis = 3 * 2 * (3)^2 = 54(m)"),
Times.Once);
_logger.Verify(l =>
l.AddMessage("Deflection along Z axis = 4 * 3 * 3 = 36(m)"),
Times.Once);
}
[Test]
public void GetDeflection_ZeroCurvature_ProducesZeroDeflection()
{
_factor.Setup(f => f.SpanLength).Returns(10);
_k.Setup(f => f.Mx).Returns(5);
_curvature.Setup(c => c.Mx).Returns(0);
var result = _logic.GetDeflection(_curvature.Object, _factor.Object);
Assert.That(result.DeflectionMx.Deflection, Is.EqualTo(0));
}
}
}

View File

@@ -0,0 +1,123 @@
using Moq;
using NUnit.Framework;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Forces;
using StructureHelperCommon.Services.Forces;
using StructureHelperLogics.NdmCalculations.Analyses.Curvatures;
namespace StructureHelperTests.UnitTests.Curvatures
{
[TestFixture]
public class GetTermDeflectionLogicTests
{
private Mock<IGetDeflectionByCurvatureLogic> _deflectionLogicMock;
private Mock<IForceTupleServiceLogic> _forceTupleServiceMock;
private Mock<IShiftTraceLogger> _loggerMock;
private Mock<IDeflectionFactor> _deflectionFactorMock;
private Mock<IForceTuple> _longCurvatureMock;
private Mock<IForceTuple> _shortLongCurvatureMock;
private Mock<IForceTuple> _shortFullCurvatureMock;
private Mock<ICurvatureTermResult> _expectedResultMock;
[SetUp]
public void Setup()
{
_deflectionLogicMock = new Mock<IGetDeflectionByCurvatureLogic>();
_forceTupleServiceMock = new Mock<IForceTupleServiceLogic>();
_loggerMock = new Mock<IShiftTraceLogger>();
_deflectionFactorMock = new Mock<IDeflectionFactor>();
_longCurvatureMock = new Mock<IForceTuple>();
_shortLongCurvatureMock = new Mock<IForceTuple>();
_shortFullCurvatureMock = new Mock<IForceTuple>();
_expectedResultMock = new Mock<ICurvatureTermResult>();
}
// ---------------------------------------------------------
// TEST 1 — GetLongResult should call deflection logic
// ---------------------------------------------------------
[Test]
public void GetLongResult_ShouldCallDeflectionLogic_AndReturnResult()
{
// Arrange
var logic = new GetTermDeflectionLogic(
_deflectionLogicMock.Object,
_forceTupleServiceMock.Object,
_loggerMock.Object)
{
LongCurvature = _longCurvatureMock.Object,
DeflectionFactor = _deflectionFactorMock.Object
};
_deflectionLogicMock
.Setup(x => x.GetDeflection(_longCurvatureMock.Object, _deflectionFactorMock.Object))
.Returns(_expectedResultMock.Object);
// Act
var result = logic.GetLongResult();
// Assert
Assert.That(result, Is.EqualTo(_expectedResultMock.Object));
_deflectionLogicMock.Verify(x => x.GetDeflection(_longCurvatureMock.Object, _deflectionFactorMock.Object),
Times.Once);
_loggerMock.Verify(x => x.AddMessage(It.IsAny<string>()), Times.Once);
}
// ---------------------------------------------------------
// TEST 2 — GetShortResult should compute curvature and call deflection logic
// ---------------------------------------------------------
[Test]
public void GetShortResult_ShouldComputeShortCurvature_AndReturnDeflection()
{
// Arrange
var deltaCurvatureMock = new Mock<IForceTuple>().Object;
var shortCurvatureMock = new Mock<IForceTuple>().Object;
var logic = new GetTermDeflectionLogic(
_deflectionLogicMock.Object,
_forceTupleServiceMock.Object,
_loggerMock.Object)
{
LongCurvature = _longCurvatureMock.Object,
ShortFullCurvature = _shortFullCurvatureMock.Object,
ShortLongCurvature = _shortLongCurvatureMock.Object,
DeflectionFactor = _deflectionFactorMock.Object
};
_forceTupleServiceMock
.Setup(x => x.SumTuples(_shortFullCurvatureMock.Object, _shortLongCurvatureMock.Object, -1))
.Returns(deltaCurvatureMock);
_forceTupleServiceMock
.Setup(x => x.SumTuples(_longCurvatureMock.Object, deltaCurvatureMock))
.Returns(shortCurvatureMock);
_deflectionLogicMock
.Setup(x => x.GetDeflection(shortCurvatureMock, _deflectionFactorMock.Object))
.Returns(_expectedResultMock.Object);
// Act
var result = logic.GetShortResult();
// Assert
Assert.That(result, Is.EqualTo(_expectedResultMock.Object));
_forceTupleServiceMock.Verify(x =>
x.SumTuples(_shortFullCurvatureMock.Object, _shortLongCurvatureMock.Object, -1), Times.Once);
_forceTupleServiceMock.Verify(x =>
x.SumTuples(_longCurvatureMock.Object, deltaCurvatureMock), Times.Once);
_deflectionLogicMock.Verify(x =>
x.GetDeflection(shortCurvatureMock, _deflectionFactorMock.Object), Times.Once);
// Trace should run once for the final curvature
_loggerMock.Verify(x => x.AddMessage(It.IsAny<string>()), Times.Once);
}
}
}