Skip to content

Commit a412d31

Browse files
committed
Improved IsCloseTo unit tests
1 parent 0258fec commit a412d31

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

UnitTests/UnitTests.Shared/Diagnostics/Test_Guard.Comparable.Numeric.cs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,35 @@ public partial class Test_Guard
2525
[DataRow(-500, -530, 50u, true)]
2626
[DataRow(1000, 800, 200u, true)]
2727
[DataRow(int.MaxValue, int.MaxValue - 10, 10u, true)]
28-
public void Test_Guard_IsCloseToInt(int value, int target, uint delta, bool isClose)
28+
public void Test_Guard_IsCloseOrNotToInt(int value, int target, uint delta, bool isClose)
2929
{
3030
void Test(int value, int target)
3131
{
3232
bool isFailed = false;
3333

3434
try
3535
{
36-
Guard.IsCloseTo(value, target, delta, nameof(Test_Guard_IsCloseToInt));
36+
Guard.IsCloseTo(value, target, delta, nameof(Test_Guard_IsCloseOrNotToInt));
3737
}
3838
catch (ArgumentException)
3939
{
4040
isFailed = true;
4141
}
4242

4343
Assert.AreEqual(isClose, !isFailed);
44+
45+
isFailed = false;
46+
47+
try
48+
{
49+
Guard.IsNotCloseTo(value, target, delta, nameof(Test_Guard_IsCloseOrNotToInt));
50+
}
51+
catch (ArgumentException)
52+
{
53+
isFailed = true;
54+
}
55+
56+
Assert.AreEqual(isClose, isFailed);
4457
}
4558

4659
Test(value, target);
@@ -70,14 +83,27 @@ void Test(float value, float target)
7083

7184
try
7285
{
73-
Guard.IsCloseTo(value, target, delta, nameof(Test_Guard_IsCloseToInt));
86+
Guard.IsCloseTo(value, target, delta, nameof(Test_Guard_IsCloseToFloat));
7487
}
7588
catch (ArgumentException)
7689
{
7790
isFailed = true;
7891
}
7992

8093
Assert.AreEqual(isClose, !isFailed);
94+
95+
isFailed = false;
96+
97+
try
98+
{
99+
Guard.IsNotCloseTo(value, target, delta, nameof(Test_Guard_IsCloseToFloat));
100+
}
101+
catch (ArgumentException)
102+
{
103+
isFailed = true;
104+
}
105+
106+
Assert.AreEqual(isClose, isFailed);
81107
}
82108

83109
Test(value, target);

0 commit comments

Comments
 (0)