Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public static void DoubleWithDefaultTolerance(double first, double second, bool
[InlineData(1.1, 1.3, 0.5, true)]
[InlineData(100.55, 100.555, 0.00001, false)]
[InlineData(5.0, 14.999999, 10.0, true)]
[InlineData(5.0, 15.0, 10.0, false)]
[InlineData(5.0, 15.0, 10.0, true)]
[InlineData(4.9998, 15.0, 10.0, false)]
[InlineData(5.0, 15.0001, 10.0, false)]
public static void DoubleWithCustomTolerance(double first, double second, double tolerance, bool expected) =>
first.IsApproximately(second, tolerance).Should().Be(expected);
Expand All @@ -34,7 +35,8 @@ public static void FloatWithDefaultTolerance(float first, float second, bool exp
[InlineData(1.1f, 1.3f, 0.5f, true)]
[InlineData(100.55f, 100.555f, 0.00001f, false)]
[InlineData(5.0f, 14.999999f, 10.0f, true)]
[InlineData(5.0f, 15.0f, 10.0f, false)]
[InlineData(5.0f, 15.0f, 10.0f, true)]
[InlineData(4.99f, 15.0f, 10.0f, false)]
[InlineData(5.0f, 15.0001f, 10.0f, false)]
public static void FloatWithCustomTolerance(float first, float second, float tolerance, bool expected) =>
first.IsApproximately(second, tolerance).Should().Be(expected);
Expand All @@ -44,7 +46,8 @@ public static void FloatWithCustomTolerance(float first, float second, float tol
[InlineData(1.1, 1.3, 0.5, true)]
[InlineData(100.55, 100.555, 0.00001, false)]
[InlineData(5.0, 14.999999, 10.0, true)]
[InlineData(5.0, 15.0, 10.0, false)]
[InlineData(5.0, 15.0, 10.0, true)]
[InlineData(5.0, 15.000001, 10.0, false)]
[InlineData(5.0, 15.0001, 10.0, false)]
public static void GenericDoubleWithCustomTolerance(double first, double second, double tolerance, bool expected) =>
first.IsApproximately<double>(second, tolerance).Should().Be(expected);
Expand All @@ -53,14 +56,16 @@ public static void GenericDoubleWithCustomTolerance(double first, double second,
[InlineData(1.1f, 1.3f, 0.5f, true)]
[InlineData(100.55f, 100.555f, 0.00001f, false)]
[InlineData(5.0f, 14.999999f, 10.0f, true)]
[InlineData(5.0f, 15.0f, 10.0f, false)]
[InlineData(5.0f, 15.0f, 10.0f, true)]
[InlineData(5.0f, 15.01f, 10.0f, false)]
[InlineData(5.0f, 15.0001f, 10.0f, false)]
public static void GenericFloatWithCustomTolerance(float first, float second, float tolerance, bool expected) =>
first.IsApproximately<float>(second, tolerance).Should().Be(expected);

[Theory]
[InlineData(5, 10, 10, true)]
[InlineData(5, 15, 10, false)]
[InlineData(5, 15, 10, true)]
[InlineData(4, 15, 10, false)]
[InlineData(-5, 5, 12, true)]
[InlineData(-100, 100, 199, false)]
[InlineData(42, 42, 1, true)]
Expand All @@ -69,7 +74,8 @@ public static void GenericIntWithCustomTolerance(int first, int second, int tole

[Theory]
[InlineData(5L, 10L, 10L, true)]
[InlineData(5L, 15L, 10L, false)]
[InlineData(5L, 15L, 10L, true)]
[InlineData(5L, 16L, 10L, false)]
[InlineData(-5L, 5L, 12L, true)]
[InlineData(-100L, 100L, 199L, false)]
[InlineData(42L, 42L, 1L, true)]
Expand All @@ -91,7 +97,7 @@ bool expected
{ 1.1m, 1.3m, 0.5m, true },
{ 100.55m, 100.555m, 0.00001m, false },
{ 5.0m, 14.999999m, 10.0m, true },
{ 5.0m, 15.0m, 10.0m, false },
{ 5.0m, 15.0m, 9.99m, false },
};
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,59 @@ public static void FloatWithDefaultTolerance(float first, float second, bool exp
[InlineData(1.0f, 2.0f, 0.1f, false)]
public static void FloatWIthCustomTolerance(float first, float second, float tolerance, bool expected) =>
first.IsGreaterThanOrApproximately(second, tolerance).Should().Be(expected);
}

#if NET8_0
[Theory]
[InlineData(15.91, 15.9, 0.1, true)]
[InlineData(24.449, 24.45, 0.0001, false)]
[InlineData(-3.12, -3.2, 0.001, true)]
[InlineData(2.369, 2.37, 0.0005, false)]
[InlineData(15.0, 14.0, 0.1, true)] // Greater than case
[InlineData(14.95, 15.0, 0.1, true)] // Approximately equal case
public static void GenericDoubleWithCustomTolerance(double first, double second, double tolerance, bool expected) =>
first.IsGreaterThanOrApproximately<double>(second, tolerance).Should().Be(expected);

[Theory]
[InlineData(2.0f, 1.0f, 0.1f, true)]
[InlineData(1.0f, 1.0f, 0.1f, true)]
[InlineData(1.0f, 1.1f, 0.01f, false)]
[InlineData(1.0f, 2.0f, 0.1f, false)]
[InlineData(2.1f, 2.0f, 0.01f, true)] // Greater than case
public static void GenericFloatWithCustomTolerance(float first, float second, float tolerance, bool expected) =>
first.IsGreaterThanOrApproximately<float>(second, tolerance).Should().Be(expected);

[Theory]
[InlineData(10, 5, 1, true)] // Greater than case
[InlineData(5, 5, 1, true)] // Equal case
[InlineData(5, 6, 1, true)] // Approximately equal case
[InlineData(5, 7, 1, false)] // Not greater than or approximately equal case
public static void GenericIntWithCustomTolerance(int first, int second, int tolerance, bool expected) =>
first.IsGreaterThanOrApproximately(second, tolerance).Should().Be(expected);

[Theory]
[InlineData(10L, 5L, 1L, true)] // Greater than case
[InlineData(5L, 5L, 1L, true)] // Equal case
[InlineData(5L, 6L, 1L, true)] // Approximately equal case
[InlineData(5L, 7L, 1L, false)] // Not greater than or approximately equal case
public static void GenericLongWithCustomTolerance(long first, long second, long tolerance, bool expected) =>
first.IsGreaterThanOrApproximately(second, tolerance).Should().Be(expected);

[Theory]
[MemberData(nameof(DecimalTestData))]
public static void GenericDecimalWithCustomTolerance(
decimal first,
decimal second,
decimal tolerance,
bool expected
) =>
first.IsGreaterThanOrApproximately(second, tolerance).Should().Be(expected);

public static TheoryData<decimal, decimal, decimal, bool> DecimalTestData() => new ()
{
{ 1.3m, 1.1m, 0.1m, true }, // Greater than case
{ 1.1m, 1.1m, 0.1m, true }, // Equal case
{ 1.0m, 1.1m, 0.2m, true }, // Approximately equal case
{ 1.0m, 1.3m, 0.1m, false }, // Not greater than or approximately equal case
};
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,56 @@ public static void FloatWithDefaultTolerance(float first, float second, bool exp
[InlineData(0f, -1f, 0.9f, false)]
public static void FloatWithCustomTolerance(float first, float second, float tolerance, bool expected) =>
first.IsLessThanOrApproximately(second, tolerance).Should().Be(expected);

#if NET8_0
[Theory]
[InlineData(13.25, 13.5, 0.1, true)] // Less than case
[InlineData(13.5, 13.5, 0.1, true)] // Equal case
[InlineData(13.55, 13.5, 0.1, true)] // Approximately equal case
[InlineData(13.7, 13.5, 0.1, false)] // Not less than or approximately equal case
public static void GenericDoubleWithCustomTolerance(double first, double second, double tolerance, bool expected) =>
first.IsLessThanOrApproximately<double>(second, tolerance).Should().Be(expected);

[Theory]
[InlineData(13.25f, 13.5f, 0.1f, true)] // Less than case
[InlineData(13.5f, 13.5f, 0.1f, true)] // Equal case
[InlineData(13.55f, 13.5f, 0.1f, true)] // Approximately equal case
[InlineData(13.7f, 13.5f, 0.1f, false)] // Not less than or approximately equal case
public static void GenericFloatWithCustomTolerance(float first, float second, float tolerance, bool expected) =>
first.IsLessThanOrApproximately<float>(second, tolerance).Should().Be(expected);

[Theory]
[InlineData(5, 10, 1, true)] // Less than case
[InlineData(5, 5, 1, true)] // Equal case
[InlineData(6, 5, 1, true)] // Approximately equal case
[InlineData(7, 5, 1, false)] // Not less than or approximately equal case
public static void GenericIntWithCustomTolerance(int first, int second, int tolerance, bool expected) =>
first.IsLessThanOrApproximately(second, tolerance).Should().Be(expected);

[Theory]
[InlineData(5L, 10L, 1L, true)] // Less than case
[InlineData(5L, 5L, 1L, true)] // Equal case
[InlineData(6L, 5L, 1L, true)] // Approximately equal case
[InlineData(7L, 5L, 1L, false)] // Not less than or approximately equal case
public static void GenericLongWithCustomTolerance(long first, long second, long tolerance, bool expected) =>
first.IsLessThanOrApproximately(second, tolerance).Should().Be(expected);

[Theory]
[MemberData(nameof(DecimalTestData))]
public static void GenericDecimalWithCustomTolerance(
decimal first,
decimal second,
decimal tolerance,
bool expected
) =>
first.IsLessThanOrApproximately(second, tolerance).Should().Be(expected);

public static TheoryData<decimal, decimal, decimal, bool> DecimalTestData() => new ()
{
{ 1.0m, 1.2m, 0.1m, true }, // Less than case
{ 1.1m, 1.1m, 0.1m, true }, // Equal case
{ 1.2m, 1.1m, 0.1m, true }, // Approximately equal case
{ 1.3m, 1.1m, 0.1m, false }, // Not less than or approximately equal case
};
#endif
}
Loading