Add test of rebar by density and rebar by inclined rebar

This commit is contained in:
RedikultsevEvg
2025-08-10 18:24:46 +05:00
parent 3d8ac6f0c4
commit c61069a394
29 changed files with 364 additions and 134 deletions

View File

@@ -33,21 +33,107 @@ namespace StructureHelperTests.UnitTests.BeamShearTests
);
}
[Test]
public void GetShearStrength_CalculatesCorrectly()
[TestCase(0.2, 0.48)]
[TestCase(0.5, 1.2)]
[TestCase(1.1, 2.64)]
[TestCase(2.2, 2.64)]
public void GetShearStrength_CalculatesCorrectly_differentStirrupEnd(double stirrupEnd, double expectedStrength)
{
// Arrange
_mockInclinedSection.Setup(s => s.StartCoord).Returns(1.0);
_mockInclinedSection.Setup(s => s.EndCoord).Returns(3.0);
_mockInclinedSection.Setup(s => s.EffectiveDepth).Returns(2.0);
_mockInclinedSection.Setup(s => s.StartCoord).Returns(0);
_mockInclinedSection.Setup(s => s.EndCoord).Returns(100);
_mockInclinedSection.Setup(s => s.EffectiveDepth).Returns(0.55);
_mockStirrupEffectiveness.Setup(s => s.MaxCrackLengthRatio).Returns(0.5);
_mockStirrupEffectiveness.Setup(s => s.StirrupShapeFactor).Returns(1.2);
_mockStirrupEffectiveness.Setup(s => s.StirrupPlacementFactor).Returns(1.1);
_mockStirrupEffectiveness.Setup(s => s.MaxCrackLengthRatio).Returns(2.0);
_mockStirrupEffectiveness.Setup(s => s.StirrupShapeFactor).Returns(0.8);
_mockStirrupEffectiveness.Setup(s => s.StirrupPlacementFactor).Returns(0.75);
_mockStirrupEffectiveness.Setup(s => s.MinimumStirrupRatio).Returns(0.25);
_mockStirrupByDensity.Setup(s => s.StirrupDensity).Returns(4.0);
_mockStirrupByDensity.Setup(s => s.StartCoordinate).Returns(0);
_mockStirrupByDensity.Setup(s => s.EndCoordinate).Returns(stirrupEnd);
double expectedStrength = 1.2 * 1.1 * 1.0 * 4.0; // Min(2.0, 1.0) = 1.0
// Act
double result = _beamShearStrength.GetShearStrength();
// Assert
Assert.That(result, Is.EqualTo(expectedStrength).Within(1e-6));
_mockTraceLogger.Verify(t => t.AddMessage(It.IsAny<string>(), It.IsAny<TraceLogStatuses>()), Times.AtLeastOnce);
}
[TestCase(0.20, 0.48)]
[TestCase(0.55, 1.32)]
[TestCase(1.1, 2.64)]
[TestCase(2.2, 2.64)]
public void GetShearStrength_CalculatesCorrectly_differentInclinedSectionEnd(double inclinedSectionEnd, double expectedStrength)
{
// Arrange
_mockInclinedSection.Setup(s => s.StartCoord).Returns(0);
_mockInclinedSection.Setup(s => s.EndCoord).Returns(inclinedSectionEnd);
_mockInclinedSection.Setup(s => s.EffectiveDepth).Returns(0.55);
_mockStirrupEffectiveness.Setup(s => s.MaxCrackLengthRatio).Returns(2.0);
_mockStirrupEffectiveness.Setup(s => s.StirrupShapeFactor).Returns(0.8);
_mockStirrupEffectiveness.Setup(s => s.StirrupPlacementFactor).Returns(0.75);
_mockStirrupEffectiveness.Setup(s => s.MinimumStirrupRatio).Returns(0.25);
_mockStirrupByDensity.Setup(s => s.StirrupDensity).Returns(4.0);
_mockStirrupByDensity.Setup(s => s.StartCoordinate).Returns(0);
_mockStirrupByDensity.Setup(s => s.EndCoordinate).Returns(100);
// Act
double result = _beamShearStrength.GetShearStrength();
// Assert
Assert.That(result, Is.EqualTo(expectedStrength).Within(1e-6));
_mockTraceLogger.Verify(t => t.AddMessage(It.IsAny<string>(), It.IsAny<TraceLogStatuses>()), Times.AtLeastOnce);
}
[TestCase(0.2, 0.66)]
[TestCase(0.5, 1.65)]
[TestCase(0.8, 2.64)]
public void GetShearStrength_CalculatesCorrectly_differentShapeFactor(double shapeFactor, double expectedStrength)
{
// Arrange
_mockInclinedSection.Setup(s => s.StartCoord).Returns(0);
_mockInclinedSection.Setup(s => s.EndCoord).Returns(1.1);
_mockInclinedSection.Setup(s => s.EffectiveDepth).Returns(0.55);
_mockStirrupEffectiveness.Setup(s => s.MaxCrackLengthRatio).Returns(2.0);
_mockStirrupEffectiveness.Setup(s => s.StirrupShapeFactor).Returns(shapeFactor);
_mockStirrupEffectiveness.Setup(s => s.StirrupPlacementFactor).Returns(0.75);
_mockStirrupEffectiveness.Setup(s => s.MinimumStirrupRatio).Returns(0.25);
_mockStirrupByDensity.Setup(s => s.StirrupDensity).Returns(4.0);
_mockStirrupByDensity.Setup(s => s.StartCoordinate).Returns(0);
_mockStirrupByDensity.Setup(s => s.EndCoordinate).Returns(100);
// Act
double result = _beamShearStrength.GetShearStrength();
// Assert
Assert.That(result, Is.EqualTo(expectedStrength).Within(1e-6));
_mockTraceLogger.Verify(t => t.AddMessage(It.IsAny<string>(), It.IsAny<TraceLogStatuses>()), Times.AtLeastOnce);
}
[TestCase(0.2, 0.704)]
[TestCase(0.5, 1.76)]
[TestCase(0.8, 2.816)]
public void GetShearStrength_CalculatesCorrectly_differentPlacementFactor(double placementFactor, double expectedStrength)
{
// Arrange
_mockInclinedSection.Setup(s => s.StartCoord).Returns(0);
_mockInclinedSection.Setup(s => s.EndCoord).Returns(1.1);
_mockInclinedSection.Setup(s => s.EffectiveDepth).Returns(0.55);
_mockStirrupEffectiveness.Setup(s => s.MaxCrackLengthRatio).Returns(2.0);
_mockStirrupEffectiveness.Setup(s => s.StirrupShapeFactor).Returns(0.8);
_mockStirrupEffectiveness.Setup(s => s.StirrupPlacementFactor).Returns(placementFactor);
_mockStirrupEffectiveness.Setup(s => s.MinimumStirrupRatio).Returns(0.25);
_mockStirrupByDensity.Setup(s => s.StirrupDensity).Returns(4.0);
_mockStirrupByDensity.Setup(s => s.StartCoordinate).Returns(0);
_mockStirrupByDensity.Setup(s => s.EndCoordinate).Returns(100);
// Act
double result = _beamShearStrength.GetShearStrength();

View File

@@ -3,6 +3,7 @@ using Moq;
using NUnit.Framework;
using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Models.Materials;
using StructureHelperCommon.Models.Shapes;
using StructureHelperLogics.Models.BeamShears;
using StructureHelperLogics.Models.Materials;
using System;
@@ -36,6 +37,7 @@ namespace StructureHelperTests.UnitTests.BeamShearTests
mockSection.Setup(s => s.ConcreteMaterial).Returns(mockConcreteMaterial.Object);
mockSection.Setup(s => s.ReinforcementMaterial).Returns(mockReinforcementMaterial.Object);
mockSection.Setup(s => s.ReinforcementArea).Returns(reinforcementArea);
mockSection.Setup(s => s.Shape).Returns(new RectangleShape(){ Width = 1, Height =2 });
var mockInclSection = new Mock<IInclinedSection>();
mockInclSection.Setup(s => s.WebWidth).Returns(width);

View File

@@ -5,6 +5,7 @@ using StructureHelperCommon.Models;
using StructureHelperLogics.Models.Primitives;
using StructureHelperLogics.NdmCalculations.Primitives.Logics;
using StructureHelperLogics.NdmCalculations.Primitives;
using StructureHelperCommon.Infrastructures.Interfaces;
namespace StructureHelperTests.UnitTests.Ndms
@@ -13,7 +14,7 @@ namespace StructureHelperTests.UnitTests.Ndms
public class CheckPrimitiveCollectionLogicTests
{
private Mock<IShiftTraceLogger> _mockTraceLogger;
private Mock<ICheckRebarPrimitiveLogic> _mockCheckRebarPrimitiveLogic;
private Mock<ICheckEntityLogic<IRebarNdmPrimitive>> _mockCheckRebarPrimitiveLogic;
private Mock<IHasPrimitives> _mockHasPrimitives;
private Mock<CheckPrimitiveCollectionLogic> _mockCheckPrimitiveCollectionLogic;
@@ -21,7 +22,7 @@ namespace StructureHelperTests.UnitTests.Ndms
public void SetUp()
{
_mockTraceLogger = new Mock<IShiftTraceLogger>();
_mockCheckRebarPrimitiveLogic = new Mock<ICheckRebarPrimitiveLogic>();
_mockCheckRebarPrimitiveLogic = new Mock<ICheckEntityLogic<IRebarNdmPrimitive>>();
_mockHasPrimitives = new Mock<IHasPrimitives>();
_mockCheckPrimitiveCollectionLogic = new Mock<CheckPrimitiveCollectionLogic>(_mockTraceLogger.Object, _mockCheckRebarPrimitiveLogic.Object)

View File

@@ -0,0 +1,135 @@
using Moq;
using NUnit.Framework;
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Models;
using StructureHelperCommon.Services;
using StructureHelperLogics.Models.BeamShears;
using StructureHelperLogics.Models.Materials;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelperTests.UnitTests
{
[TestFixture]
public class StirrupByInclinedRebarStrengthLogicTests
{
private Mock<IInclinedSection> sectionMock;
private Mock<IStirrupByInclinedRebar> rebarMock;
private Mock<IRebarSectionStrengthLogic> rebarStrengthMock;
private Mock<IInterpolateValueLogic> interpolateMock;
private Mock<IShiftTraceLogger> loggerMock;
[SetUp]
public void SetUp()
{
sectionMock = new Mock<IInclinedSection>();
rebarMock = new Mock<IStirrupByInclinedRebar>();
rebarStrengthMock = new Mock<IRebarSectionStrengthLogic>();
interpolateMock = new Mock<IInterpolateValueLogic>();
loggerMock = new Mock<IShiftTraceLogger>();
// Default geometry
rebarMock.SetupGet(r => r.TransferLength).Returns(0.1);
rebarMock.SetupGet(r => r.StartCoordinate).Returns(0.0);
rebarMock.SetupGet(r => r.AngleOfInclination).Returns(45.0);
rebarMock.SetupGet(r => r.CompressedGap).Returns(0.0);
rebarMock.SetupGet(r => r.LegCount).Returns(2);
rebarMock.SetupGet(r => r.RebarSection).Returns(Mock.Of<IRebarSection>());
sectionMock.SetupGet(s => s.EffectiveDepth).Returns(1.0);
rebarStrengthMock.Setup(m => m.GetRebarMaxTensileForce()).Returns(1000.0);
interpolateMock.Setup(m => m.GetValueY()).Returns(123.0);
}
[Test]
public void GetShearStrength_RebarOutsideSectionStart_ReturnsZero()
{
sectionMock.SetupGet(s => s.StartCoord).Returns(10.0); // start is after rebar end
sectionMock.SetupGet(s => s.EndCoord).Returns(12.0);
var logic = CreateLogic();
var result = logic.GetShearStrength();
Assert.That(result, Is.EqualTo(0.0));
loggerMock.Verify(l => l.AddMessage(It.Is<string>(msg => msg.Contains("has been ignored"))));
}
[Test]
public void GetShearStrength_RebarOutsideSectionEnd_ReturnsZero()
{
sectionMock.SetupGet(s => s.StartCoord).Returns(-5.0);
sectionMock.SetupGet(s => s.EndCoord).Returns(-1.0);
var logic = CreateLogic();
var result = logic.GetShearStrength();
Assert.That(result, Is.EqualTo(0.0));
loggerMock.Verify(l => l.AddMessage(It.Is<string>(msg => msg.Contains("has been ignored"))));
}
[Test]
public void GetShearStrength_StartTransferZone_UsesInterpolation()
{
sectionMock.SetupGet(s => s.StartCoord).Returns(0.0);
sectionMock.SetupGet(s => s.EndCoord).Returns(0.05); // falls in start transfer zone
var logic = CreateLogic();
var result = logic.GetShearStrength();
Assert.That(result, Is.EqualTo(123.0)); // from interpolateMock
interpolateMock.Verify(m => m.GetValueY(), Times.Once);
}
[Test]
public void GetShearStrength_EndTransferZone_UsesInterpolation()
{
sectionMock.SetupGet(s => s.StartCoord).Returns(0.95); // falls in end transfer zone
sectionMock.SetupGet(s => s.EndCoord).Returns(2.0);
var logic = CreateLogic();
var result = logic.GetShearStrength();
Assert.That(result, Is.EqualTo(123.0));
interpolateMock.Verify(m => m.GetValueY(), Times.Once);
}
[Test]
public void GetShearStrength_MainZone_ComputesStrength()
{
sectionMock.SetupGet(s => s.StartCoord).Returns(0.2);
sectionMock.SetupGet(s => s.EndCoord).Returns(1.0);
var logic = CreateLogic();
var result = logic.GetShearStrength();
// Strength = 0.75 * 1000 * sin(45°) * 2
var expected = 0.75 * 1000.0 * Math.Sin(Math.PI / 4) * 2;
Assert.That(result, Is.EqualTo(expected).Within(1e-6));
}
[Test]
public void GetShearStrength_TransferZonesOverlap_ThrowsException()
{
rebarMock.SetupGet(r => r.TransferLength).Returns(5.0); // huge transfer length
var logic = CreateLogic();
Assert.Throws<StructureHelperException>(() => logic.GetShearStrength());
}
private StirrupByInclinedRebarStrengthLogic CreateLogic()
{
return new StirrupByInclinedRebarStrengthLogic(
sectionMock.Object,
rebarMock.Object,
rebarStrengthMock.Object,
interpolateMock.Object,
loggerMock.Object
);
}
}
}