Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add difference to numeric assertion failure messages (#1859)
- Loading branch information
1 parent
e32b95f
commit 51b0232
Showing
33 changed files
with
1,584 additions
and
72 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,22 @@ | ||
using System.Diagnostics; | ||
|
||
namespace FluentAssertions.Numeric | ||
{ | ||
/// <summary> | ||
/// Contains a number of methods to assert that a <see cref="byte"/> is in the expected state. | ||
/// </summary> | ||
[DebuggerNonUserCode] | ||
internal class ByteAssertions : NumericAssertions<byte> | ||
{ | ||
internal ByteAssertions(byte value) | ||
: base(value) | ||
{ | ||
} | ||
|
||
private protected override byte? CalculateDifferenceForFailureMessage(byte expected) | ||
{ | ||
var difference = (byte?)(Subject - expected); | ||
return difference != 0 ? difference : null; | ||
} | ||
} | ||
} |
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,30 @@ | ||
using System; | ||
using System.Diagnostics; | ||
|
||
namespace FluentAssertions.Numeric | ||
{ | ||
/// <summary> | ||
/// Contains a number of methods to assert that a <see cref="decimal"/> is in the expected state. | ||
/// </summary> | ||
[DebuggerNonUserCode] | ||
internal class DecimalAssertions : NumericAssertions<decimal> | ||
{ | ||
internal DecimalAssertions(decimal value) | ||
: base(value) | ||
{ | ||
} | ||
|
||
private protected override decimal? CalculateDifferenceForFailureMessage(decimal expected) | ||
{ | ||
try | ||
{ | ||
var difference = checked(Subject - expected); | ||
return difference != 0 ? difference : null; | ||
} | ||
catch (OverflowException) | ||
{ | ||
return null; | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,12 +1,24 @@ | ||
namespace FluentAssertions.Numeric | ||
using System.Diagnostics; | ||
|
||
namespace FluentAssertions.Numeric | ||
{ | ||
/// <summary> | ||
/// Contains a number of methods to assert that a <see cref="double"/> is in the expected state. | ||
/// </summary> | ||
[DebuggerNonUserCode] | ||
internal class DoubleAssertions : NumericAssertions<double> | ||
{ | ||
public DoubleAssertions(double value) | ||
internal DoubleAssertions(double value) | ||
: base(value) | ||
{ | ||
} | ||
|
||
private protected override bool IsNaN(double value) => double.IsNaN(value); | ||
|
||
private protected override double? CalculateDifferenceForFailureMessage(double expected) | ||
{ | ||
var difference = Subject - expected; | ||
return difference != 0 ? difference : null; | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,27 @@ | ||
using System.Diagnostics; | ||
|
||
namespace FluentAssertions.Numeric | ||
{ | ||
/// <summary> | ||
/// Contains a number of methods to assert that a <see cref="short"/> is in the expected state. | ||
/// </summary> | ||
[DebuggerNonUserCode] | ||
internal class Int16Assertions : NumericAssertions<short> | ||
{ | ||
internal Int16Assertions(short value) | ||
: base(value) | ||
{ | ||
} | ||
|
||
private protected override short? CalculateDifferenceForFailureMessage(short expected) | ||
{ | ||
if (Subject < 10 && expected < 10) | ||
{ | ||
return null; | ||
} | ||
|
||
var difference = (short?)(Subject - expected); | ||
return difference != 0 ? difference : null; | ||
} | ||
} | ||
} |
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,35 @@ | ||
using System; | ||
using System.Diagnostics; | ||
|
||
namespace FluentAssertions.Numeric | ||
{ | ||
/// <summary> | ||
/// Contains a number of methods to assert that a <see cref="int"/> is in the expected state. | ||
/// </summary> | ||
[DebuggerNonUserCode] | ||
internal class Int32Assertions : NumericAssertions<int> | ||
{ | ||
internal Int32Assertions(int value) | ||
: base(value) | ||
{ | ||
} | ||
|
||
private protected override int? CalculateDifferenceForFailureMessage(int expected) | ||
{ | ||
if (Subject is > 0 and < 10 && expected is > 0 and < 10) | ||
{ | ||
return null; | ||
} | ||
|
||
try | ||
{ | ||
var difference = checked(Subject - expected); | ||
return difference != 0 ? difference : null; | ||
} | ||
catch (OverflowException) | ||
{ | ||
return null; | ||
} | ||
} | ||
} | ||
} |
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,35 @@ | ||
using System; | ||
using System.Diagnostics; | ||
|
||
namespace FluentAssertions.Numeric | ||
{ | ||
/// <summary> | ||
/// Contains a number of methods to assert that a <see cref="long"/> is in the expected state. | ||
/// </summary> | ||
[DebuggerNonUserCode] | ||
internal class Int64Assertions : NumericAssertions<long> | ||
{ | ||
internal Int64Assertions(long value) | ||
: base(value) | ||
{ | ||
} | ||
|
||
private protected override long? CalculateDifferenceForFailureMessage(long expected) | ||
{ | ||
if (Subject is > 0 and < 10 && expected is > 0 and < 10) | ||
{ | ||
return null; | ||
} | ||
|
||
try | ||
{ | ||
var difference = checked(Subject - expected); | ||
return difference != 0 ? difference : null; | ||
} | ||
catch (OverflowException) | ||
{ | ||
return null; | ||
} | ||
} | ||
} | ||
} |
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,22 @@ | ||
using System.Diagnostics; | ||
|
||
namespace FluentAssertions.Numeric | ||
{ | ||
/// <summary> | ||
/// Contains a number of methods to assert that a nullable <see cref="byte"/> is in the expected state. | ||
/// </summary> | ||
[DebuggerNonUserCode] | ||
internal class NullableByteAssertions : NullableNumericAssertions<byte> | ||
{ | ||
internal NullableByteAssertions(byte? value) | ||
: base(value) | ||
{ | ||
} | ||
|
||
private protected override byte? CalculateDifferenceForFailureMessage(byte expected) | ||
{ | ||
var difference = (byte?)(Subject - expected); | ||
return difference != 0 ? difference : null; | ||
} | ||
} | ||
} |
Oops, something went wrong.