// Path: hamcrest/hamcrest-matchers/src/test/java/it/ozimov/cirneco/hamcrest/BaseMatcherTest.java
// @RunWith(MockitoJUnitRunner.class)
// public abstract class BaseMatcherTest {
// 
//     @Rule
//     public ExpectedException thrown = ExpectedException.none();
// 
//     public static <T> void assertMatches(final String message, final boolean matches) {
//         assertTrue(message, matches);
//     }
// 
//     public static <T> void assertMatches(final boolean matches) {
//         assertMatches("Expected to match, but mismatched", matches);
//     }
// 
//     public static <T> void assertDoesNotMatch(final String message, final boolean matches) {
//         assertFalse(message, matches);
//     }
// 
//     public static <T> void assertDoesNotMatch(final boolean matches) {
//         assertDoesNotMatch("Unexpected matching", matches);
//     }
// 
//     public static void assertIsDescribedTo(final String expectedDescription, final Matcher<?> matcher) {
// 
//         // Act
//         final String actualDescription = descriptionFromMatcher(matcher);
// 
//         // Assert
//         assertThat("Expected description does not match the one returned by the Matcher " + getSimpleName(matcher),
//                 expectedDescription, equalTo(actualDescription));
//     }
// 
//     public static <T> void assertHasMismatchDescription(final String expectedDescription,
//                                                         final Matcher<? super T> matcher, final T matcherArgument) {
// 
//         // Assert
//         assertThat(format("The given matcher has no mismatch with value \"%s\"", matcherArgument),
//                 matcher.matches(matcherArgument), is(false));
// 
//         // Act
//         final String actualMismatchDescription = mismatchDescriptionForMatcherFromArgument(matcher, matcherArgument);
// 
//         // Assert
//         assertThat("Expected mismatch description does not match the one returned by the Matcher "
//                 + getSimpleName(matcher), expectedDescription, equalTo(actualMismatchDescription));
//     }
// 
//     private static String descriptionFromMatcher(final Matcher<?> matcher) {
//         return new StringDescription().appendDescriptionOf(matcher).toString().trim();
//     }
// 
//     protected static <T> String mismatchDescriptionForMatcherFromArgument(final Matcher<? super T> matcher,
//                                                                           final T arg) {
//         final Description description = new StringDescription();
//         matcher.describeMismatch(arg, description);
// 
//         return description.toString().trim();
//     }
// 
//     private static String getSimpleName(final Matcher<?> matcher) {
//         return matcher.getClass().getSimpleName();
//     }
// 
// }


import it.ozimov.cirneco.hamcrest.BaseMatcherTest;
import org.hamcrest.Matcher;
import org.junit.Before;
import org.junit.Test;
package it.ozimov.cirneco.hamcrest.collect;


public class IsIterableWithDistinctElementsTest extends BaseIterableMatcherTest {
    /**
     * Any quadratic algorithm should take "forever" for this amount of elements.
     * e.g. 100000 elements takes 13 seconds to scan for duplicates naively (check frequencies of all items).
     *
     * @see #HUGE_ITERABLE_QUADRATIC_TIMEOUT
     */
    private static final int HUGE_ITERABLE = 100000;
    /** Leeway for {@link #HUGE_ITERABLE} handling. */
    private static final int HUGE_ITERABLE_QUADRATIC_TIMEOUT = 500;

    public Matcher<Iterable<?>> isIterableWithDistinctElementsMatcher;

    @Before
    public void setUp() {
        isIterableWithDistinctElementsMatcher = IsIterableWithDistinctElements.hasDistinctElements();
    }

    @Test
    public void testGivenIterableWithNoElementsWhenMatchesForDistinctMatcherIsCalledThenTrueIsReturned()
            throws Exception {

        // Arrange
        final Iterable<Integer> iterable = createIterableWithElements(/* none */);

        // Act
        final boolean matches = isIterableWithDistinctElementsMatcher.matches(iterable);

        // Assert
        BaseMatcherTest.assertMatches(matches);
    }

    @Test
    public void testGivenIterableWithOnlyDistinctElementsWhenMatchesForDistinctMatcherIsCalledThenTrueIsReturned()
            throws Exception {

        // Arrange
        final Iterable<Integer> iterable = createIterableWithElements(1, 2, 3);

        // Act
        final boolean matches = isIterableWithDistinctElementsMatcher.matches(iterable);

        // Assert
        BaseMatcherTest.assertMatches(matches);
    }

    @Test
    public void testGivenIterableWithSomeNonDistinctElementsWhenMatchesForDistinctMatcherIsCalledThenFalseIsReturned()
            throws Exception {

        // Arrange
        final Iterable<Integer> iterable = createIterableWithElements(1, 2, 3, 3);

        // Act
        final boolean matches = isIterableWithDistinctElementsMatcher.matches(iterable);

        // Assert
        BaseMatcherTest.assertDoesNotMatch(matches);
    }

    @Test(timeout = HUGE_ITERABLE_QUADRATIC_TIMEOUT)
    public void testGivenHugeIterableWithDistinctElementsWhenMatchesForDistinctMatcherIsCalledThenTrueIsReturnedInTime()
            throws Exception {

        // Arrange
        final Iterable<?> iterable = createIterableWithSize(HUGE_ITERABLE);

        // Act
        final boolean matches = isIterableWithDistinctElementsMatcher.matches(iterable);

        // Assert
// Path: hamcrest/hamcrest-matchers/src/test/java/it/ozimov/cirneco/hamcrest/BaseMatcherTest.java
// @RunWith(MockitoJUnitRunner.class)
// public abstract class BaseMatcherTest {
// 
//     @Rule
//     public ExpectedException thrown = ExpectedException.none();
// 
//     public static <T> void assertMatches(final String message, final boolean matches) {
//         assertTrue(message, matches);
//     }
// 
//     public static <T> void assertMatches(final boolean matches) {
//         assertMatches("Expected to match, but mismatched", matches);
//     }
// 
//     public static <T> void assertDoesNotMatch(final String message, final boolean matches) {
//         assertFalse(message, matches);
//     }
// 
//     public static <T> void assertDoesNotMatch(final boolean matches) {
//         assertDoesNotMatch("Unexpected matching", matches);
//     }
// 
//     public static void assertIsDescribedTo(final String expectedDescription, final Matcher<?> matcher) {
// 
//         // Act
//         final String actualDescription = descriptionFromMatcher(matcher);
// 
//         // Assert
//         assertThat("Expected description does not match the one returned by the Matcher " + getSimpleName(matcher),
//                 expectedDescription, equalTo(actualDescription));
//     }
// 
//     public static <T> void assertHasMismatchDescription(final String expectedDescription,
//                                                         final Matcher<? super T> matcher, final T matcherArgument) {
// 
//         // Assert
//         assertThat(format("The given matcher has no mismatch with value \"%s\"", matcherArgument),
//                 matcher.matches(matcherArgument), is(false));
// 
//         // Act
//         final String actualMismatchDescription = mismatchDescriptionForMatcherFromArgument(matcher, matcherArgument);
// 
//         // Assert
//         assertThat("Expected mismatch description does not match the one returned by the Matcher "
//                 + getSimpleName(matcher), expectedDescription, equalTo(actualMismatchDescription));
//     }
// 
//     private static String descriptionFromMatcher(final Matcher<?> matcher) {
//         return new StringDescription().appendDescriptionOf(matcher).toString().trim();
//     }
// 
//     protected static <T> String mismatchDescriptionForMatcherFromArgument(final Matcher<? super T> matcher,
//                                                                           final T arg) {
//         final Description description = new StringDescription();
//         matcher.describeMismatch(arg, description);
// 
//         return description.toString().trim();
//     }
// 
//     private static String getSimpleName(final Matcher<?> matcher) {
//         return matcher.getClass().getSimpleName();
//     }
// 
// }


// Path: hamcrest/hamcrest-matchers/src/test/java/it/ozimov/cirneco/hamcrest/collect/IsIterableWithDistinctElementsTest.java
import it.ozimov.cirneco.hamcrest.BaseMatcherTest;
import org.hamcrest.Matcher;
import org.junit.Before;
import org.junit.Test;

package it.ozimov.cirneco.hamcrest.collect;


public class IsIterableWithDistinctElementsTest extends BaseIterableMatcherTest {
    /**
     * Any quadratic algorithm should take "forever" for this amount of elements.
     * e.g. 100000 elements takes 13 seconds to scan for duplicates naively (check frequencies of all items).
     *
     * @see #HUGE_ITERABLE_QUADRATIC_TIMEOUT
     */
    private static final int HUGE_ITERABLE = 100000;
    /** Leeway for {@link #HUGE_ITERABLE} handling. */
    private static final int HUGE_ITERABLE_QUADRATIC_TIMEOUT = 500;

    public Matcher<Iterable<?>> isIterableWithDistinctElementsMatcher;

    @Before
    public void setUp() {
        isIterableWithDistinctElementsMatcher = IsIterableWithDistinctElements.hasDistinctElements();
    }

    @Test
    public void testGivenIterableWithNoElementsWhenMatchesForDistinctMatcherIsCalledThenTrueIsReturned()
            throws Exception {

        // Arrange
        final Iterable<Integer> iterable = createIterableWithElements(/* none */);

        // Act
        final boolean matches = isIterableWithDistinctElementsMatcher.matches(iterable);

        // Assert
        BaseMatcherTest.assertMatches(matches);
    }

    @Test
    public void testGivenIterableWithOnlyDistinctElementsWhenMatchesForDistinctMatcherIsCalledThenTrueIsReturned()
            throws Exception {

        // Arrange
        final Iterable<Integer> iterable = createIterableWithElements(1, 2, 3);

        // Act
        final boolean matches = isIterableWithDistinctElementsMatcher.matches(iterable);

        // Assert
        BaseMatcherTest.assertMatches(matches);
    }

    @Test
    public void testGivenIterableWithSomeNonDistinctElementsWhenMatchesForDistinctMatcherIsCalledThenFalseIsReturned()
            throws Exception {

        // Arrange
        final Iterable<Integer> iterable = createIterableWithElements(1, 2, 3, 3);

        // Act
        final boolean matches = isIterableWithDistinctElementsMatcher.matches(iterable);

        // Assert
        BaseMatcherTest.assertDoesNotMatch(matches);
    }

    @Test(timeout = HUGE_ITERABLE_QUADRATIC_TIMEOUT)
    public void testGivenHugeIterableWithDistinctElementsWhenMatchesForDistinctMatcherIsCalledThenTrueIsReturnedInTime()
            throws Exception {

        // Arrange
        final Iterable<?> iterable = createIterableWithSize(HUGE_ITERABLE);

        // Act
        final boolean matches = isIterableWithDistinctElementsMatcher.matches(iterable);

        // Assert
        BaseMatcherTest.assertMatches(matches);