-
Notifications
You must be signed in to change notification settings - Fork 385
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improving the ToUnit test coverage (#1493)
Improving the `ToUnit` test coverage: - `ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit` now also tests the non-base to non-base conversions - `ToUnit_FromNonBaseUnit_ReturnsQuantityWithGivenUnit` is no longer skipped for quantities with a single unit (the test is still generated) - added the `ToUnit_FromIQuantity_ReturnsTheExpectedIQuantity` test: covering the `IQuantity` interfaces - added the `Convert_GetTypeCode_Returns_Object` test (completing the `IConvertible` interface coverage) - `IQuantityTests`: removed the redundant `UnitSystem` tests and updated "wrong unit type" tests, using all quantities
- Loading branch information
Showing
128 changed files
with
4,087 additions
and
815 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,7 @@ | |
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet. | ||
|
||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
using UnitsNet.Units; | ||
using System.Linq; | ||
using Xunit; | ||
|
||
namespace UnitsNet.Tests | ||
|
@@ -14,48 +13,19 @@ public partial class IQuantityTests | |
[Fact] | ||
public void As_GivenWrongUnitType_ThrowsArgumentException() | ||
{ | ||
IQuantity length = Length.FromMeters(1.2345); | ||
Assert.Throws<ArgumentException>(() => length.As(MassUnit.Kilogram)); | ||
} | ||
|
||
[Fact] | ||
[SuppressMessage("ReSharper", "AssignNullToNotNullAttribute")] | ||
public void As_GivenNullUnitSystem_ThrowsArgumentNullException() | ||
{ | ||
IQuantity imperialLengthQuantity = new Length(2.0, LengthUnit.Inch); | ||
Assert.Throws<ArgumentNullException>(() => imperialLengthQuantity.As((UnitSystem)null!)); | ||
} | ||
|
||
[Fact] | ||
public void As_GivenSIUnitSystem_ReturnsSIValue() | ||
{ | ||
IQuantity inches = new Length(2.0, LengthUnit.Inch); | ||
Assert.Equal(0.0508, inches.As(UnitSystem.SI)); | ||
Assert.All(Quantity.Infos.Select(x => x.Zero), quantity => | ||
{ | ||
Assert.Throws<ArgumentException>(() => quantity.As(ComparisonType.Absolute)); | ||
}); | ||
} | ||
|
||
[Fact] | ||
public void ToUnit_GivenWrongUnitType_ThrowsArgumentException() | ||
{ | ||
IQuantity length = Length.FromMeters(1.2345); | ||
Assert.Throws<ArgumentException>(() => length.ToUnit(MassUnit.Kilogram)); | ||
} | ||
|
||
[Fact] | ||
public void ToUnit_GivenNullUnitSystem_ThrowsArgumentNullException() | ||
{ | ||
IQuantity imperialLengthQuantity = new Length(2.0, LengthUnit.Inch); | ||
Assert.Throws<ArgumentNullException>(() => imperialLengthQuantity.ToUnit((UnitSystem)null!)); | ||
} | ||
|
||
[Fact] | ||
public void ToUnit_GivenSIUnitSystem_ReturnsSIQuantity() | ||
{ | ||
IQuantity inches = new Length(2.0, LengthUnit.Inch); | ||
|
||
IQuantity inSI = inches.ToUnit(UnitSystem.SI); | ||
|
||
Assert.Equal(0.0508, inSI.Value); | ||
Assert.Equal(LengthUnit.Meter, inSI.Unit); | ||
Assert.All(Quantity.Infos.Select(x => x.Zero), quantity => | ||
{ | ||
Assert.Throws<ArgumentException>(() => quantity.ToUnit(ComparisonType.Absolute)); | ||
}); | ||
} | ||
} | ||
} |
38 changes: 32 additions & 6 deletions
38
UnitsNet.Tests/GeneratedCode/TestsBase/AbsorbedDoseOfIonizingRadiationTestsBase.g.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
38 changes: 32 additions & 6 deletions
38
UnitsNet.Tests/GeneratedCode/TestsBase/AccelerationTestsBase.g.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
38 changes: 32 additions & 6 deletions
38
UnitsNet.Tests/GeneratedCode/TestsBase/AmountOfSubstanceTestsBase.g.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
38 changes: 32 additions & 6 deletions
38
UnitsNet.Tests/GeneratedCode/TestsBase/AmplitudeRatioTestsBase.g.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.