-
Notifications
You must be signed in to change notification settings - Fork 165
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
(#1212) Fixed SetOf, which discarded all elements after duplicated occurrence #1215
Changes from 2 commits
b0c6c77
0d75b50
77b0162
7f5640a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,27 +23,93 @@ | |
*/ | ||
package org.cactoos.set; | ||
|
||
import org.hamcrest.MatcherAssert; | ||
import org.cactoos.iterable.IterableOf; | ||
import org.cactoos.iterable.Joined; | ||
import org.hamcrest.Matcher; | ||
import org.hamcrest.core.AllOf; | ||
import org.hamcrest.core.IsCollectionContaining; | ||
import org.hamcrest.core.IsEqual; | ||
import org.junit.Test; | ||
import org.llorllale.cactoos.matchers.Assertion; | ||
import org.llorllale.cactoos.matchers.HasSize; | ||
|
||
/** | ||
* Test case for {@link SetOf}. | ||
* | ||
* @since 0.49.2 | ||
* @checkstyle MagicNumber (500 line) | ||
* @checkstyle JavadocMethodCheck (500 lines) | ||
* @checkstyle ClassDataAbstractionCouplingCheck (500 lines) | ||
*/ | ||
@SuppressWarnings("PMD.AvoidDuplicateLiterals") | ||
public final class SetOfTest { | ||
|
||
/** | ||
* Ensures that SetOf behaves as set, which means no duplicates. | ||
*/ | ||
@Test | ||
public void behavesAsSet() { | ||
MatcherAssert.assertThat( | ||
"Can't behave as a set", | ||
public void behaveAsSetWithOriginalDuplicationsInTheTail() { | ||
new Assertion<>( | ||
"Must keep unique numbers", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fanifieiev please, change |
||
new SetOf<>(1, 2, 2), | ||
new BehavesAsSet<>(2) | ||
); | ||
new AllOf<>( | ||
new IterableOf<Matcher<? super SetOf<Integer>>>( | ||
new HasSize(2), | ||
new IsCollectionContaining<>(new IsEqual<>(1)), | ||
new IsCollectionContaining<>(new IsEqual<>(2)) | ||
) | ||
) | ||
).affirm(); | ||
} | ||
|
||
@Test | ||
public void behaveAsSetWithOriginalDuplicationsInTheHead() { | ||
new Assertion<>( | ||
"Must keep unique numbers", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fanifieiev please, change |
||
new SetOf<>(1, 1, 2, 3), | ||
new AllOf<>( | ||
new IterableOf<Matcher<? super SetOf<Integer>>>( | ||
new HasSize(3), | ||
new IsCollectionContaining<>(new IsEqual<>(1)), | ||
new IsCollectionContaining<>(new IsEqual<>(2)), | ||
new IsCollectionContaining<>(new IsEqual<>(3)) | ||
) | ||
) | ||
).affirm(); | ||
} | ||
|
||
@Test | ||
public void behaveAsSetWithOriginalDuplicationsInTheMiddle() { | ||
new Assertion<>( | ||
"Must keep unique numbers", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fanifieiev please, change |
||
new SetOf<>(1, 2, 2, 3), | ||
new AllOf<>( | ||
new IterableOf<Matcher<? super SetOf<Integer>>>( | ||
new HasSize(3), | ||
new IsCollectionContaining<>(new IsEqual<>(1)), | ||
new IsCollectionContaining<>(new IsEqual<>(2)), | ||
new IsCollectionContaining<>(new IsEqual<>(3)) | ||
) | ||
) | ||
).affirm(); | ||
} | ||
|
||
@Test | ||
public void behaveAsSetWithOriginalMergedCollectionsWithDuplicates() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fanifieiev please, add more tests for:
|
||
new Assertion<>( | ||
"Must keep unique string literals", | ||
new SetOf<String>( | ||
new Joined<String>( | ||
new IterableOf<>("cc", "ff"), | ||
new IterableOf<>("aa", "bb", "cc", "dd") | ||
) | ||
), | ||
new AllOf<>( | ||
new IterableOf<Matcher<? super SetOf<String>>>( | ||
new HasSize(5), | ||
new IsCollectionContaining<>(new IsEqual<>("aa")), | ||
new IsCollectionContaining<>(new IsEqual<>("bb")), | ||
new IsCollectionContaining<>(new IsEqual<>("cc")), | ||
new IsCollectionContaining<>(new IsEqual<>("dd")), | ||
new IsCollectionContaining<>(new IsEqual<>("ff")) | ||
) | ||
) | ||
).affirm(); | ||
} | ||
} |
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.
@fanifieiev I think it would be way better to use
src.forEach(tmp::add)
, that's whatIterable
is made for.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.
@victornoel Sure, that one looks better. But just wondering what was the
And(final Proc<X> proc, final Iterable<X> src)
created for ?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.
@fanifieiev I think it is here only for completeness.
And
is more about the logical assertion (which does not rely on side effect as theProc
version does).I created #1226 in reaction to this discussion :)