Add beam section logic
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperLogics.Models.BeamShears;
|
||||
|
||||
namespace StructureHelperTests.UnitTests.BeamShearTests
|
||||
{
|
||||
|
||||
|
||||
[TestFixture]
|
||||
public class BeamShearStrengthByStirrupDensityTests
|
||||
{
|
||||
private Mock<IStirrupEffectiveness> _mockStirrupEffectiveness;
|
||||
private Mock<IStirrupByDensity> _mockStirrupByDensity;
|
||||
private Mock<IInclinedSection> _mockInclinedSection;
|
||||
private Mock<IShiftTraceLogger> _mockTraceLogger;
|
||||
private BeamShearStrengthByStirrupDensityLogic _beamShearStrength;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockStirrupEffectiveness = new Mock<IStirrupEffectiveness>();
|
||||
_mockStirrupByDensity = new Mock<IStirrupByDensity>();
|
||||
_mockInclinedSection = new Mock<IInclinedSection>();
|
||||
_mockTraceLogger = new Mock<IShiftTraceLogger>();
|
||||
|
||||
_beamShearStrength = new BeamShearStrengthByStirrupDensityLogic(
|
||||
_mockStirrupEffectiveness.Object,
|
||||
_mockStirrupByDensity.Object,
|
||||
_mockInclinedSection.Object,
|
||||
_mockTraceLogger.Object
|
||||
);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetShearStrength_CalculatesCorrectly()
|
||||
{
|
||||
// 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);
|
||||
|
||||
_mockStirrupEffectiveness.Setup(s => s.MaxCrackLengthRatio).Returns(0.5);
|
||||
_mockStirrupEffectiveness.Setup(s => s.StirrupShapeFactor).Returns(1.2);
|
||||
_mockStirrupEffectiveness.Setup(s => s.StirrupPlacementFactor).Returns(1.1);
|
||||
|
||||
_mockStirrupByDensity.Setup(s => s.StirrupDensity).Returns(4.0);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetShearStrength_ThrowsException_WhenDependenciesAreNull()
|
||||
{
|
||||
// Arrange
|
||||
var invalidInstance = new BeamShearStrengthByStirrupDensityLogic(
|
||||
_mockStirrupEffectiveness.Object,
|
||||
null, // Invalid
|
||||
_mockInclinedSection.Object,
|
||||
_mockTraceLogger.Object
|
||||
);
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<StructureHelperException>(() => invalidInstance.GetShearStrength());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using StructureHelperCommon.Infrastructures.Enums;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperLogics.Models.BeamShears;
|
||||
using StructureHelperLogics.Models.Materials;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace StructureHelperTests.UnitTests.BeamShearTests
|
||||
{
|
||||
|
||||
|
||||
[TestFixture]
|
||||
public class StirrupByUniformRebarToDensityConvertStrategyTests
|
||||
{
|
||||
private Mock<IUpdateStrategy<IStirrup>> _mockUpdateStrategy;
|
||||
private Mock<IShiftTraceLogger> _mockTraceLogger;
|
||||
private StirrupByUniformRebarToDensityConvertStrategy _convertStrategy;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockUpdateStrategy = new Mock<IUpdateStrategy<IStirrup>>();
|
||||
_mockTraceLogger = new Mock<IShiftTraceLogger>();
|
||||
|
||||
_convertStrategy = new StirrupByUniformRebarToDensityConvertStrategy(
|
||||
_mockUpdateStrategy.Object,
|
||||
_mockTraceLogger.Object
|
||||
);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Convert_UpdatesAndCalculatesDensityCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
var mockMaterial = new Mock<IReinforcementLibMaterial>();
|
||||
mockMaterial.Setup(m => m.GetStrength(LimitStates.ULS, CalcTerms.ShortTerm)).Returns((2e8, 2e8));
|
||||
|
||||
var stirrupRebar = new Mock<IStirrupByUniformRebar>();
|
||||
stirrupRebar.Setup(s => s.Diameter).Returns(0.02);
|
||||
stirrupRebar.Setup(s => s.Material).Returns(mockMaterial.Object);
|
||||
stirrupRebar.Setup(s => s.LegCount).Returns(2);
|
||||
stirrupRebar.Setup(s => s.Step).Returns(0.15);
|
||||
|
||||
// Act
|
||||
var result = _convertStrategy.Convert(stirrupRebar.Object);
|
||||
|
||||
// Assert
|
||||
_mockUpdateStrategy.Verify(u => u.Update(It.IsAny<IStirrupByDensity>(), stirrupRebar.Object), Times.Once);
|
||||
Assert.That(result.StirrupDensity, Is.EqualTo(837758.04095727834d).Within(0.00001));
|
||||
//_mockTraceLogger.Verify(t => t.AddMessage(It.IsAny<string>(), It.IsAny<TraceLogStatuses>()), Times.AtLeastOnce);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user