-
Notifications
You must be signed in to change notification settings - Fork 386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improving the ToUnit test coverage #1493
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These can of course be moved to the generated tests, but given that we're likely going to be removing this part of the interface, decided to just leave them here for now.. In my other project there are a few other tests here, testing for the |
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)); | ||
}); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could also skip the generation for this method for the single-unit quantities, but decided not to bother (tell me if you'd rather not have it at all).
Of course we could also put back the
[Skip]
, however I don't think that's very useful- I'm thinking of the[Skip]
as something that should be addressed, and I don't think that having a single unit is something that needs fixing (as long as it'sSI
😈 )There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't mind much either way