This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Add other compare extensions and tests. #21020
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,211 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using Xunit; | ||
using Xunit.Sdk; | ||
|
||
namespace Tests.System | ||
{ | ||
public class AssertExtensionTests | ||
{ | ||
private const string Null = "<null>"; | ||
|
||
[Theory, | ||
InlineData(0, 0, false), | ||
InlineData(1, 1, false), | ||
InlineData(0, 1, false), | ||
InlineData(0, -1, true), | ||
InlineData(-1, 0, false), | ||
InlineData(1, 0, true), | ||
InlineData(1, -1, true), | ||
InlineData(-1, 1, false) | ||
] | ||
public void GreaterThan_ValueType(int actual, int greaterThan, bool expected) | ||
{ | ||
try | ||
{ | ||
AssertExtensions.GreaterThan(actual, greaterThan); | ||
Assert.True(expected, $"{actual} > {greaterThan} should have failed the assertion."); | ||
} | ||
catch (XunitException) | ||
{ | ||
Assert.False(expected, $"{actual} > {greaterThan} should *not* have failed the assertion."); | ||
} | ||
} | ||
|
||
[Theory, | ||
// Null is always less than anything other than null | ||
InlineData("", null, true), | ||
InlineData(null, null, false), | ||
InlineData(null, "", false), | ||
InlineData("b", "b", false), | ||
InlineData("b", "c", false), | ||
InlineData("b", "a", true), | ||
InlineData("a", "b", false), | ||
InlineData("c", "b", true), | ||
InlineData("c", "a", true), | ||
InlineData("a", "c", false) | ||
] | ||
public void GreaterThan_ReferenceType(string actual, string greaterThan, bool expected) | ||
{ | ||
try | ||
{ | ||
AssertExtensions.GreaterThan(actual, greaterThan); | ||
Assert.True(expected, $"{actual ?? Null} > {greaterThan ?? Null} should have failed the assertion."); | ||
} | ||
catch (XunitException) | ||
{ | ||
Assert.False(expected, $"{actual ?? Null} > {greaterThan ?? Null} should *not* have failed the assertion."); | ||
} | ||
} | ||
|
||
[Theory, | ||
InlineData(0, 0, false), | ||
InlineData(1, 1, false), | ||
InlineData(0, 1, true), | ||
InlineData(0, -1, false), | ||
InlineData(-1, 0, true), | ||
InlineData(1, 0, false), | ||
InlineData(1, -1, false), | ||
InlineData(-1, 1, true) | ||
] | ||
public void LessThan_ValueType(int actual, int lessThan, bool expected) | ||
{ | ||
try | ||
{ | ||
AssertExtensions.LessThan(actual, lessThan); | ||
Assert.True(expected, $"{actual} < {lessThan} should have failed the assertion."); | ||
} | ||
catch (XunitException) | ||
{ | ||
Assert.False(expected, $"{actual} < {lessThan} should *not* have failed the assertion."); | ||
} | ||
} | ||
|
||
[Theory, | ||
// Null is always less than anything other than null | ||
InlineData("", null, false), | ||
InlineData(null, null, false), | ||
InlineData(null, "", true), | ||
InlineData("b", "b", false), | ||
InlineData("b", "c", true), | ||
InlineData("b", "a", false), | ||
InlineData("a", "b", true), | ||
InlineData("c", "b", false), | ||
InlineData("c", "a", false), | ||
InlineData("a", "c", true) | ||
] | ||
public void LessThan_ReferenceType(string actual, string lessThan, bool expected) | ||
{ | ||
try | ||
{ | ||
AssertExtensions.LessThan(actual, lessThan); | ||
Assert.True(expected, $"'{actual ?? Null}' < '{lessThan ?? Null}' should have failed the assertion."); | ||
} | ||
catch (XunitException) | ||
{ | ||
Assert.False(expected, $"'{actual ?? Null}' < '{lessThan ?? Null}' should *not* have failed the assertion."); | ||
} | ||
} | ||
|
||
[Theory, | ||
InlineData(0, 0, true), | ||
InlineData(1, 1, true), | ||
InlineData(0, 1, false), | ||
InlineData(0, -1, true), | ||
InlineData(-1, 0, false), | ||
InlineData(1, 0, true), | ||
InlineData(1, -1, true), | ||
InlineData(-1, 1, false) | ||
] | ||
public void GreaterThanOrEqualTo_ValueType(int actual, int greaterThanOrEqualTo, bool expected) | ||
{ | ||
try | ||
{ | ||
AssertExtensions.GreaterThanOrEqualTo(actual, greaterThanOrEqualTo); | ||
Assert.True(expected, $"{actual} >= {greaterThanOrEqualTo} should have failed the assertion."); | ||
} | ||
catch (XunitException) | ||
{ | ||
Assert.False(expected, $"{actual} >= {greaterThanOrEqualTo} should *not* have failed the assertion."); | ||
} | ||
} | ||
|
||
[Theory, | ||
// Null is always less than anything other than null | ||
InlineData("", null, true), | ||
InlineData(null, null, true), | ||
InlineData(null, "", false), | ||
InlineData("b", "b", true), | ||
InlineData("b", "c", false), | ||
InlineData("b", "a", true), | ||
InlineData("a", "b", false), | ||
InlineData("c", "b", true), | ||
InlineData("c", "a", true), | ||
InlineData("a", "c", false) | ||
] | ||
public void GreaterThanOrEqualTo_ReferenceType(string actual, string greaterThanOrEqualTo, bool expected) | ||
{ | ||
try | ||
{ | ||
AssertExtensions.GreaterThanOrEqualTo(actual, greaterThanOrEqualTo); | ||
Assert.True(expected, $"'{actual ?? Null}' >= '{greaterThanOrEqualTo ?? Null}' should have failed the assertion."); | ||
} | ||
catch (XunitException) | ||
{ | ||
Assert.False(expected, $"'{actual ?? Null}' >= '{greaterThanOrEqualTo ?? Null}' should *not* have failed the assertion."); | ||
} | ||
} | ||
|
||
[Theory, | ||
InlineData(0, 0, true), | ||
InlineData(1, 1, true), | ||
InlineData(0, 1, true), | ||
InlineData(0, -1, false), | ||
InlineData(-1, 0, true), | ||
InlineData(1, 0, false), | ||
InlineData(1, -1, false), | ||
InlineData(-1, 1, true) | ||
] | ||
public void LessThanOrEqualTo_ValueType(int actual, int lessThanOrEqualTo, bool expected) | ||
{ | ||
try | ||
{ | ||
AssertExtensions.LessThanOrEqualTo(actual, lessThanOrEqualTo); | ||
Assert.True(expected, $"{actual} <= {lessThanOrEqualTo} should have failed the assertion."); | ||
} | ||
catch (XunitException) | ||
{ | ||
Assert.False(expected, $"{actual} <= {lessThanOrEqualTo} should *not* have failed the assertion."); | ||
} | ||
} | ||
|
||
[Theory, | ||
// Null is always less than anything other than null | ||
InlineData("", null, false), | ||
InlineData(null, null, true), | ||
InlineData(null, "", true), | ||
InlineData("b", "b", true), | ||
InlineData("b", "c", true), | ||
InlineData("b", "a", false), | ||
InlineData("a", "b", true), | ||
InlineData("c", "b", false), | ||
InlineData("c", "a", false), | ||
InlineData("a", "c", true) | ||
] | ||
public void LessThanOrEqualTo_ReferenceType(string actual, string lessThanOrEqualTo, bool expected) | ||
{ | ||
try | ||
{ | ||
AssertExtensions.LessThanOrEqualTo(actual, lessThanOrEqualTo); | ||
Assert.True(expected, $"'{actual ?? Null}' >= '{lessThanOrEqualTo ?? Null}' should have failed the assertion."); | ||
} | ||
catch (XunitException) | ||
{ | ||
Assert.False(expected, $"'{actual ?? Null}' >= '{lessThanOrEqualTo ?? Null}' should *not* have failed the assertion."); | ||
} | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This could be written in just "one" line
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.
same for the other one
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.
It is a little bit more than that:
I opted for clearer and more verbose in these cases as this is a test assertion. I'm ok with merging the other one (
LessThanOrEqualTo
), but I'd rather keep the layout the same to make visually comparing the two methods easier.