-
-
Notifications
You must be signed in to change notification settings - Fork 540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Add collections methods BeProperSubsetOf / BeProperSupersetOf / BeSupersetOf #2432
base: develop
Are you sure you want to change the base?
Feature: Add collections methods BeProperSubsetOf / BeProperSupersetOf / BeSupersetOf #2432
Conversation
Qodana for .NET4 new problems were found
💡 Qodana analysis was run in the pull request mode: only the changed files were checked View the detailed Qodana reportTo be able to view the detailed Qodana report, you can either:
To get - name: 'Qodana Scan'
uses: JetBrains/qodana-action@v2023.2.8
with:
upload-result: true Contact Qodana teamContact us at qodana-support@jetbrains.com
|
5f23897
to
398bb8f
Compare
Pull Request Test Coverage Report for Build 9185874020Details
💛 - Coveralls |
These methods come from set theory, but work on var subject = new []{1, 1, 1, 2, 2, 3, 3};
subject.Should().BeProperSubsetOf(new []{1, 2, 3, 3, 3, 4}); Should we add test cases for it? |
@vbreuss done! thanks for the suggestion |
Src/FluentAssertions/Collections/GenericCollectionAssertions.cs
Outdated
Show resolved
Hide resolved
Src/FluentAssertions/Collections/GenericCollectionAssertions.cs
Outdated
Show resolved
Hide resolved
AssertBeSubsetOf(expectedProperSuperset, "proper subset", because, becauseArgs); | ||
|
||
ISet<T> expectedItems = expectedProperSuperset.ConvertOrCastToSet(); | ||
|
||
if (expectedItems.Intersect(Subject).Count() == expectedItems.Count) |
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.
Could this cause multiple enumeration of either Subject
or expectedProperSuperset
?
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.
hmm, maybe we should create an ISet
and an ICollection
for the Subject
and expected
values?
Tests/FluentAssertions.Specs/Collections/CollectionAssertionSpecs.BeProperSupersetOf.cs
Show resolved
Hide resolved
Src/FluentAssertions/Collections/GenericCollectionAssertions.cs
Outdated
Show resolved
Hide resolved
Src/FluentAssertions/Collections/GenericCollectionAssertions.cs
Outdated
Show resolved
Hide resolved
Src/FluentAssertions/Collections/GenericCollectionAssertions.cs
Outdated
Show resolved
Hide resolved
Tests/FluentAssertions.Specs/Collections/CollectionAssertionSpecs.BeProperSubsetOf.cs
Outdated
Show resolved
Hide resolved
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.
Not all previous comments have been addressed either.
Src/FluentAssertions/Collections/GenericCollectionAssertions.cs
Outdated
Show resolved
Hide resolved
Qodana for .NETIt seems all right 👌 No new problems were found according to the checks applied 💡 Qodana analysis was run in the pull request mode: only the changed files were checked Contact Qodana teamContact us at qodana-support@jetbrains.com
|
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.
Nice work
And there are some Qodana issues to address. |
d2ee717
to
817afca
Compare
@dennisdoomen done |
public void A_collection_with_all_items_of_a_superset_but_has_extra_items_is_not_a_proper_subset() | ||
{ | ||
// Arrange | ||
var subset = new[] { 1, 2, 3, 4 }; | ||
var superset = new[] { 4, 3, 2, 1 }; |
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.
I don't know that the "extra items" the method name mentions are?
} | ||
|
||
/// <summary> | ||
/// Asserts that the collection is a proper subset of the <paramref name="expectedProperSubset" />. |
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.
/// Asserts that the collection is a proper subset of the <paramref name="expectedProperSubset" />. | |
/// Asserts that the collection is a proper superset of the <paramref name="expectedProperSubset" />. |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
/// </content> | ||
public partial class CollectionAssertionSpecs | ||
{ | ||
public class BeSupersetOf |
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.
We're missing test on how BeSupersetOf
should behave when Subject
is either null
or empty.
[Fact] | ||
public void A_collection_is_not_a_superset_of_an_empty_collection() | ||
{ | ||
// Arrange | ||
var collection = new[] { 1, 2, 3 }; | ||
|
||
// Act | ||
Action act = () => collection.Should().BeSupersetOf(new int[0]); | ||
|
||
// Assert | ||
act.Should().Throw<ArgumentException>().WithMessage( | ||
"Cannot verify containment against an empty collection*"); | ||
} |
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.
I'm sorry, I didn't think about this case when I suggested forwarding BeProperSupersetOf
to Contain
.
The empty set is a valid set and { 1, 2, 3 }
is a super set of {}
.
I think all the set theoretic methods should handle empty sets.
resolves #2363
IMPORTANT
./build.sh --target spellcheck
or.\build.ps1 --target spellcheck
before pushing and check the good outcome