Skip to content
This repository has been archived by the owner on Jul 5, 2023. It is now read-only.

Commit

Permalink
added unit tests for measurement related enum comparisson;
Browse files Browse the repository at this point in the history
  • Loading branch information
Dejan Bratic committed Jun 29, 2023
1 parent 7bdcafe commit 30fd4f5
Showing 1 changed file with 48 additions and 12 deletions.
60 changes: 48 additions & 12 deletions tests/Nox.Types.Tests/Common/MeasurementConversionFactorTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Nox.Common;
using FluentAssertions;
using Nox.Common;

namespace Nox.Types.Tests.Common;

Expand All @@ -9,64 +10,99 @@ public void MeasurementUnitConverter_GetConversionFactor_FromFootToMeter_Returns
{
var factor = new MeasurementConversionFactor(MeasurementTypeUnit.Foot, MeasurementTypeUnit.Meter);

Assert.Equal(0.30480000033, factor.Value);
factor.Value.Should().Be(0.30480000033);
}

[Fact]
public void MeasurementUnitConverter_GetConversionFactor_FromMeterToFoot_ReturnsValue()
{
var factor = new MeasurementConversionFactor(MeasurementTypeUnit.Meter, MeasurementTypeUnit.Foot);

Assert.Equal(3.28083989142, factor.Value);
factor.Value.Should().Be(3.28083989142);
}

[Fact]
public void MeasurementUnitConverter_GetConversionFactor_FromKilometerToMile_ReturnsValue()
{
var factor = new MeasurementConversionFactor(MeasurementTypeUnit.Kilometer, MeasurementTypeUnit.Mile);

Assert.Equal(0.62137119102, factor.Value);
factor.Value.Should().Be(0.62137119102);
}

[Fact]
public void MeasurementUnitConverter_GetConversionFactor_FromMileToKilometer_ReturnsValue()
{
var factor = new MeasurementConversionFactor(MeasurementTypeUnit.Mile, MeasurementTypeUnit.Kilometer);

Assert.Equal(1.60934400315, factor.Value);
factor.Value.Should().Be(1.60934400315);
}

[Fact]
public void MeasurementUnitConverter_GetConversionFactor_FromSquareFootToSquareMeter_ReturnsValue()
{
var factor = new MeasurementConversionFactor(MeasurementTypeUnit.SquareFoot, MeasurementTypeUnit.SquareMeter);

Assert.Equal(0.09290304, factor.Value);
factor.Value.Should().Be(0.09290304);
}

[Fact]
public void MeasurementUnitConverter_GetConversionFactor_FromSquareMeterToSquareFoot_ReturnsValue()
{
var factor = new MeasurementConversionFactor(MeasurementTypeUnit.SquareMeter, MeasurementTypeUnit.SquareFoot);

Assert.Equal(10.76391042, factor.Value);
factor.Value.Should().Be(10.76391042);
}

[Fact]
public void MeasurementUnitConverter_GetConversionFactor_WithSameSourceAndTargetUnit_ReturnsValue()
{
var factor = new MeasurementConversionFactor(MeasurementTypeUnit.Foot, MeasurementTypeUnit.Foot);

Assert.Equal(1, factor.Value);
factor.Value.Should().Be(1);
}

[Fact]
public void MeasurementUnitConverter_GetConversionFactor_WithUnsupportedConversion_ThrowsException()
{
var exception = Assert.Throws<NotImplementedException>(() => _ =
new MeasurementConversionFactor(MeasurementTypeUnit.SquareMeter, MeasurementTypeUnit.Meter)
);
var action = () => new MeasurementConversionFactor(MeasurementTypeUnit.SquareMeter, MeasurementTypeUnit.Meter);

Assert.Equal("No conversion defined from SquareMeter to Meter.", exception.Message);
action.Should().Throw<NotImplementedException>()
.WithMessage("No conversion defined from SquareMeter to Meter.");
}

[Fact]
public void MeasurementUnitType_Foot_ReturnsSameValueAsLengthTypeUnit()
{
((int)MeasurementTypeUnit.Foot).Should().Be((int)LengthTypeUnit.Foot);
}

[Fact]
public void MeasurementUnitType_Meter_ReturnsSameValueAsLengthTypeUnit()
{
((int)MeasurementTypeUnit.Meter).Should().Be((int)LengthTypeUnit.Meter);
}

[Fact]
public void MeasurementUnitType_Kilometer_ReturnsSameValueAsDistanceTypeUnit()
{
((int)MeasurementTypeUnit.Kilometer).Should().Be((int)DistanceTypeUnit.Kilometer);
}

[Fact]
public void MeasurementUnitType_Mile_ReturnsSameValueAsDistanceTypeUnit()
{
((int)MeasurementTypeUnit.Mile).Should().Be((int)DistanceTypeUnit.Mile);
}

[Fact]
public void MeasurementUnitType_SquareFoot_ReturnsSameValueAsLengthTypeUnit()
{
((int)MeasurementTypeUnit.SquareFoot).Should().Be((int)AreaTypeUnit.SquareFoot);
}

[Fact]
public void MeasurementUnitType_SquareMeter_ReturnsSameValueAsLengthTypeUnit()
{
((int)MeasurementTypeUnit.SquareMeter).Should().Be((int)AreaTypeUnit.SquareMeter);
}
}

0 comments on commit 30fd4f5

Please sign in to comment.