-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Equals(T other, T maxError), obsolete Equals(T other) for Double …
…quantities Equality comparison is not safe with System.Double as internal representation. Decimal quantities (Power, Information) still allow equality. Add test on new Equals() method.
- Loading branch information
1 parent
e0eb3f0
commit 471d2fc
Showing
58 changed files
with
901 additions
and
9 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using Xunit; | ||
|
||
namespace UnitsNet.Tests | ||
{ | ||
/// <summary> | ||
/// Tests that cover generated code in quantity structs, such as <see cref="Length" /> and <see cref="Mass" />. | ||
/// The idea is to move tests that cover uniformly generated code here, because repeating the exact same test N times | ||
/// over don't make it safer. | ||
/// </summary> | ||
public class GeneratedQuantityCodeTests | ||
{ | ||
/// <summary> | ||
/// Types with <see cref="double" /> as internal representation. This is the majority of units, such as | ||
/// <see cref="Length" />. | ||
/// </summary> | ||
public class QuantitiesWithDouble | ||
{ | ||
[Fact] | ||
public void LengthEquals_GivenMaxError_ReturnsTrueIfWithinError() | ||
{ | ||
Length smallError = Length.FromMeters(1e-5); | ||
Assert.True(Length.FromMeters(1).Equals(Length.FromMeters(1), Length.Zero), "Integer values have zero difference."); | ||
Assert.True(Length.FromMeters(1).Equals(Length.FromMeters(1), smallError), "Using a max difference value should not change that fact."); | ||
|
||
Assert.False(Length.FromMeters(1 + 0.39).Equals(Length.FromMeters(1.39), Length.Zero), | ||
"Example of floating precision arithmetic that produces slightly different results."); | ||
Assert.True(Length.FromMeters(1 + 0.39).Equals(Length.FromMeters(1.39), smallError), "But the difference is very small"); | ||
} | ||
} | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.