import "copyrightAndOthers.stg"
import "primitiveLiteral.stg"

isTest() ::= "true"

targetPath() ::= "org/eclipse/collections/impl/set/mutable/primitive"

fileName(primitive) ::= "Abstract<primitive.name>SetTestCase"

class(primitive) ::= <<
<body(primitive.type, primitive.wrapperName, primitive.name)>
>>

body(type, wrapperName, name) ::= <<
<copyrightAndOthers()>

package org.eclipse.collections.impl.set.mutable.primitive;

<if(primitive.floatingPoint)>import java.util.HashSet;<endif>
import java.util.NoSuchElementException;
<if(primitive.floatingPoint)>import java.util.Set;<endif>

import org.eclipse.collections.api.Lazy<name>Iterable;
import org.eclipse.collections.api.iterator.<name>Iterator;
import org.eclipse.collections.api.set.MutableSet;
import org.eclipse.collections.api.set.primitive.Mutable<name>Set;
import org.eclipse.collections.impl.bag.mutable.primitive.<name>HashBag;
import org.eclipse.collections.impl.block.factory.primitive.<name>Predicates;
import org.eclipse.collections.impl.collection.mutable.primitive.AbstractMutable<name>CollectionTestCase;
import org.eclipse.collections.impl.factory.primitive.<name>Sets;
import org.eclipse.collections.impl.list.mutable.primitive.<name>ArrayList;
import org.eclipse.collections.impl.set.mutable.UnifiedSet;
import org.eclipse.collections.impl.test.Verify;
import org.eclipse.collections.impl.tuple.primitive.PrimitiveTuples;
import org.eclipse.collections.api.tuple.primitive.<name><name>Pair;
import org.eclipse.collections.impl.factory.Sets;
import org.junit.Assert;
import org.junit.Test;

/**
 * Abstract JUnit test for {@link Mutable<name>Set}.
 * This file was automatically generated from template file abstractPrimitiveSetTestCase.stg.
 */
public abstract class Abstract<name>SetTestCase extends AbstractMutable<name>CollectionTestCase
{
    protected static <name>ArrayList generateCollisions1()
    {
        <name>ArrayList collisions = new <name>ArrayList();
        <name>HashSet set = new <name>HashSet();
        for (<type> i = <(literal.(type))("32")>; collisions.size() \<= 10; i++)
        {
            if (set.spreadAndMask(i) == set.spreadAndMask(<(literal.(type))("32")>))
            {
                collisions.add(i);
            }
        }
        return collisions;
    }

    private static <name>ArrayList generateNonCollisions()
    {
        <name>ArrayList collisions = new <name>ArrayList();
        <name>HashSet set = new <name>HashSet();
        for (<type> i = <(literal.(type))("32")>; collisions.size() \<= 10; i++)
        {
            if (set.spreadAndMask(i) != set.spreadAndMask(<(literal.(type))("32")>))
            {
                collisions.add(i);
            }
        }
        return collisions;
    }

    @Override
    protected abstract Mutable<name>Set classUnderTest();

    @Override
    protected abstract Mutable<name>Set newWith(<type>... elements);

    @Override
    protected Mutable<name>Set newMutableCollectionWith(<type>... elements)
    {
        return <name>HashSet.newSetWith(elements);
    }

    @Override
    protected MutableSet\<<wrapperName>\> newObjectCollectionWith(<wrapperName>... elements)
    {
        return UnifiedSet.newSetWith(elements);
    }

    @Override
    @Test
    public void size()
    {
        super.size();
        Verify.assertSize(5, this.newWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().getFirst(), Abstract<name>SetTestCase.generateCollisions1().get(1)));
    }

    @Override
    @Test
    public void isEmpty()
    {
        super.isEmpty();
        Assert.assertFalse(this.newWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().getFirst(), Abstract<name>SetTestCase.generateCollisions1().get(1)).isEmpty());
    }

    @Override
    @Test
    public void notEmpty()
    {
        Assert.assertTrue(this.newWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().getFirst(), Abstract<name>SetTestCase.generateCollisions1().get(1)).notEmpty());
    }

    @Override
    @Test
    public void clear()
    {
        super.clear();
        Mutable<name>Set set = this.newWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().getFirst(), Abstract<name>SetTestCase.generateCollisions1().get(1));
        set.clear();
        Verify.assertSize(0, set);
        Assert.assertFalse(set.contains(<(literal.(type))("0")>));
        Assert.assertFalse(set.contains(<(literal.(type))("31")>));
        Assert.assertFalse(set.contains(<(literal.(type))("1")>));
        Assert.assertFalse(set.contains(Abstract<name>SetTestCase.generateCollisions1().getFirst()));
        Assert.assertFalse(set.contains(Abstract<name>SetTestCase.generateCollisions1().get(1)));
    }

    @Override
    @Test
    public void add()
    {
        super.add();
        Mutable<name>Set set = this.newWith();
        Assert.assertTrue(set.add(<(literal.(type))("14")>));
        Assert.assertFalse(set.add(<(literal.(type))("14")>));
        Assert.assertTrue(set.add(<(literal.(type))("2")>));
        Assert.assertFalse(set.add(<(literal.(type))("2")>));
        Assert.assertTrue(set.add(<(literal.(type))("35")>));
        Assert.assertFalse(set.add(<(literal.(type))("35")>));
        Assert.assertTrue(set.add(<(literal.(type))("31")>));
        Assert.assertFalse(set.add(<(literal.(type))("31")>));
        Assert.assertTrue(set.add(<(literal.(type))("32")>));
        Assert.assertFalse(set.add(<(literal.(type))("32")>));
        Assert.assertTrue(set.add(<(literal.(type))("0")>));
        Assert.assertFalse(set.add(<(literal.(type))("0")>));
        Assert.assertTrue(set.add(<(literal.(type))("1")>));
        Assert.assertFalse(set.add(<(literal.(type))("1")>));
    }

<if(primitive.floatingPoint)>
    <NaNTests("NaN")>
    <NaNTests("POSITIVE_INFINITY")>
    <NaNTests("NEGATIVE_INFINITY")>
<endif>
    @Override
    @Test
    public void addAllIterable()
    {
        super.addAllIterable();
        Mutable<name>Set set = this.newWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().getFirst(), Abstract<name>SetTestCase.generateCollisions1().get(1));
        Assert.assertFalse(set.addAll(new <name>ArrayList()));
        Assert.assertFalse(set.addAll(<name>ArrayList.newListWith(<(literal.(type))("31")>, Abstract<name>SetTestCase.generateCollisions1().get(0), Abstract<name>SetTestCase.generateCollisions1().get(1))));
        Assert.assertEquals(<name>HashSet.newSetWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().getFirst(), Abstract<name>SetTestCase.generateCollisions1().get(1)), set);

        Assert.assertTrue(set.addAll(<name>HashSet.newSetWith(<["0", "1", "2", "30"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().getFirst(), Abstract<name>SetTestCase.generateCollisions1().get(4))));
        Assert.assertEquals(<name>HashSet.newSetWith(<["0", "1", "2", "30", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().getFirst(), Abstract<name>SetTestCase.generateCollisions1().get(1), Abstract<name>SetTestCase.generateCollisions1().get(4)), set);

        Assert.assertTrue(set.addAll(<name>HashSet.newSetWith(<(literal.(type))("5")>)));
        Assert.assertEquals(<name>HashSet.newSetWith(<["0", "1", "2", "5", "30", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().getFirst(), Abstract<name>SetTestCase.generateCollisions1().get(1), Abstract<name>SetTestCase.generateCollisions1().get(4)), set);

        Assert.assertTrue(set.addAll(<name>HashSet.newSetWith(Abstract<name>SetTestCase.generateCollisions1().get(5))));
        Assert.assertEquals(<name>HashSet.newSetWith(<["0", "1", "2", "5", "30", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().getFirst(), Abstract<name>SetTestCase.generateCollisions1().get(1), Abstract<name>SetTestCase.generateCollisions1().get(4), Abstract<name>SetTestCase.generateCollisions1().get(5)), set);

        <name>HashSet set1 = new <name>HashSet();
        Assert.assertTrue(set1.addAll(<["2", "35"]:(literal.(type))(); separator=", ">));
        Assert.assertEquals(<name>HashSet.newSetWith(<["2", "35"]:(literal.(type))(); separator=", ">), set1);
    }

    @Test
    public void testOfAllFactory()
    {
        Assert.assertEquals(
                <name>HashSet.newSetWith(<["0", "1", "2", "5", "30", "31"]:(literal.(type))(); separator=", ">),
                <name>Sets.mutable.ofAll(<name>HashBag.newBagWith(<["0", "1", "2", "5", "30", "31", "0", "1", "2", "5", "30", "31"]:(literal.(type))(); separator=", ">)));
    }

    @Override
    @Test
    public void remove()
    {
        super.remove();
        Mutable<name>Set set = this.newWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().getFirst(), Abstract<name>SetTestCase.generateCollisions1().get(1));
        Assert.assertFalse(this.newWith().remove(<(literal.(type))("15")>));
        Assert.assertFalse(set.remove(<(literal.(type))("15")>));
        Assert.assertTrue(set.remove(<(literal.(type))("0")>));
        Assert.assertEquals(<name>HashSet.newSetWith(<["1", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().getFirst(), Abstract<name>SetTestCase.generateCollisions1().get(1)), set);
        Assert.assertFalse(set.remove(Abstract<name>SetTestCase.generateNonCollisions().getFirst()));
        Assert.assertFalse(set.remove(Abstract<name>SetTestCase.generateCollisions1().get(3)));
        Assert.assertTrue(set.remove(Abstract<name>SetTestCase.generateCollisions1().get(1)));
        Assert.assertEquals(<name>HashSet.newSetWith(<["1", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().getFirst()), set);
        Assert.assertTrue(set.remove(Abstract<name>SetTestCase.generateCollisions1().getFirst()));
        Assert.assertEquals(<name>HashSet.newSetWith(<["1", "31"]:(literal.(type))(); separator=", ">), set);
        Assert.assertTrue(set.remove(<(literal.(type))("31")>));
        Assert.assertEquals(<name>HashSet.newSetWith(<(literal.(type))("1")>), set);
        Assert.assertTrue(set.remove(<(literal.(type))("1")>));
        Assert.assertEquals(<name>HashSet.newSetWith(), set);
    }

    @Override
    @Test
    public void removeAll()
    {
        super.removeAll();
        Mutable<name>Set set = this.newWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().getFirst(), Abstract<name>SetTestCase.generateCollisions1().get(1));
        Assert.assertFalse(set.removeAll());
        Assert.assertFalse(set.removeAll(<(literal.(type))("15")>, Abstract<name>SetTestCase.generateCollisions1().get(2), Abstract<name>SetTestCase.generateCollisions1().get(3)));
        Assert.assertEquals(<name>HashSet.newSetWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().getFirst(), Abstract<name>SetTestCase.generateCollisions1().get(1)), set);
        Assert.assertTrue(set.removeAll(<["0", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().get(3)));
        Assert.assertEquals(<name>HashSet.newSetWith(<(literal.(type))("1")>, Abstract<name>SetTestCase.generateCollisions1().getFirst(), Abstract<name>SetTestCase.generateCollisions1().get(1)), set);
        Assert.assertTrue(set.removeAll(<(literal.(type))("1")>, Abstract<name>SetTestCase.generateCollisions1().getFirst(), Abstract<name>SetTestCase.generateCollisions1().get(1)));
        Assert.assertEquals(new <name>HashSet(), set);
        Assert.assertFalse(set.removeAll(<(literal.(type))("1")>));
        Assert.assertEquals(new <name>HashSet(), set);
    }

    @Override
    @Test
    public void removeAll_iterable()
    {
        super.removeAll_iterable();
        Mutable<name>Set set = this.newWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().getFirst(), Abstract<name>SetTestCase.generateCollisions1().get(1));
        Assert.assertFalse(set.removeAll(new <name>ArrayList()));
        Assert.assertFalse(set.removeAll(<name>ArrayList.newListWith(<(literal.(type))("15")>, Abstract<name>SetTestCase.generateCollisions1().get(2), Abstract<name>SetTestCase.generateCollisions1().get(3))));
        Assert.assertEquals(<name>HashSet.newSetWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().getFirst(), Abstract<name>SetTestCase.generateCollisions1().get(1)), set);
        Assert.assertTrue(set.removeAll(<name>HashSet.newSetWith(<["0", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().get(4))));
        Assert.assertEquals(<name>HashSet.newSetWith(<(literal.(type))("1")>, Abstract<name>SetTestCase.generateCollisions1().getFirst(), Abstract<name>SetTestCase.generateCollisions1().get(1)), set);
        Assert.assertTrue(set.removeAll(<name>HashSet.newSetWith(<(literal.(type))("1")>, Abstract<name>SetTestCase.generateCollisions1().getFirst(), Abstract<name>SetTestCase.generateCollisions1().get(1))));
        Assert.assertEquals(new <name>HashSet(), set);
        Assert.assertFalse(set.removeAll(<name>HashSet.newSetWith(<(literal.(type))("1")>)));
        Assert.assertEquals(new <name>HashSet(), set);
    }

    @Override
    @Test
    public void retainAll()
    {
        super.retainAll();
        Mutable<name>Set set = this.newWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().getFirst(), Abstract<name>SetTestCase.generateCollisions1().get(1));
        Assert.assertFalse(set.retainAll(<["0", "1", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().getFirst(), Abstract<name>SetTestCase.generateCollisions1().get(1)));
        Assert.assertEquals(<name>HashSet.newSetWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().getFirst(), Abstract<name>SetTestCase.generateCollisions1().get(1)), set);
        Assert.assertTrue(set.retainAll(<["0", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().get(4), Abstract<name>SetTestCase.generateCollisions1().get(1)));
        Assert.assertEquals(<name>HashSet.newSetWith(<["0", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().get(1)), set);
        Assert.assertTrue(set.retainAll(<(literal.(type))("1")>, Abstract<name>SetTestCase.generateCollisions1().getFirst()));
        Assert.assertEquals(new <name>HashSet(), set);
        Assert.assertFalse(set.retainAll(<(literal.(type))("1")>));
        Assert.assertEquals(new <name>HashSet(), set);
    }

    @Override
    @Test
    public void retainAll_iterable()
    {
        super.retainAll_iterable();
        Mutable<name>Set set = this.newWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().getFirst(), Abstract<name>SetTestCase.generateCollisions1().get(1));
        Assert.assertFalse(set.retainAll(<name>HashSet.newSetWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().getFirst(), Abstract<name>SetTestCase.generateCollisions1().get(1))));
        Assert.assertEquals(<name>HashSet.newSetWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().getFirst(), Abstract<name>SetTestCase.generateCollisions1().get(1)), set);
        Assert.assertTrue(set.retainAll(<name>HashSet.newSetWith(<["0", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().get(4), Abstract<name>SetTestCase.generateCollisions1().get(1))));
        Assert.assertEquals(<name>HashSet.newSetWith(<["0", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().get(1)), set);
        Assert.assertTrue(set.retainAll(<name>HashSet.newSetWith(<(literal.(type))("1")>, Abstract<name>SetTestCase.generateCollisions1().getFirst())));
        Assert.assertEquals(new <name>HashSet(), set);
        Assert.assertFalse(set.retainAll(<name>HashSet.newSetWith(<(literal.(type))("1")>)));
        Assert.assertEquals(new <name>HashSet(), set);
    }

    @Override
    @Test
    public void <type>Iterator()
    {
        MutableSet\<<wrapperName>\> expected = UnifiedSet.newSetWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().getFirst(), Abstract<name>SetTestCase.generateCollisions1().get(1));
        MutableSet\<<wrapperName>\> actual = UnifiedSet.newSet();
        Mutable<name>Set set = this.newWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().getFirst(), Abstract<name>SetTestCase.generateCollisions1().get(1));
        <name>Iterator iterator = set.<type>Iterator();
        Assert.assertTrue(iterator.hasNext());
        actual.add(iterator.next());
        Assert.assertTrue(iterator.hasNext());
        actual.add(iterator.next());
        Assert.assertTrue(iterator.hasNext());
        actual.add(iterator.next());
        Assert.assertTrue(iterator.hasNext());
        actual.add(iterator.next());
        Assert.assertTrue(iterator.hasNext());
        actual.add(iterator.next());
        Assert.assertFalse(iterator.hasNext());
        Assert.assertEquals(expected, actual);
        Assert.assertThrows(NoSuchElementException.class, iterator::next);
    }

    @Override
    @Test(expected = NoSuchElementException.class)
    public void <type>Iterator_throws()
    {
        Mutable<name>Set set = this.newWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().getFirst(), Abstract<name>SetTestCase.generateCollisions1().get(1));
        <name>Iterator iterator = set.<type>Iterator();
        while (iterator.hasNext())
        {
            iterator.next();
        }

        iterator.next();
    }

    @Override
    @Test
    public void injectInto()
    {
        super.injectInto();

        Mutable<name>Set set = this.newWith(<["0", "2", "31"]:(literal.(type))(); separator=", ">);
        <wrapperName> sum = set.injectInto(<wrapperName>.valueOf(<(literal.(type))("0")>), (<wrapperName> result, <type> value) -> <wrapperName>.valueOf((<type>) (result + value)));
        Assert.assertEquals(<wrapperName>.valueOf(<(literal.(type))("33")>), sum);
    }

    @Override
    @Test
    public void forEach()
    {
        super.forEach();
        <wideType.(type)>[] sum = new <wideType.(type)>[1];
        Mutable<name>Set set = this.newWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().getFirst(), Abstract<name>SetTestCase.generateCollisions1().get(1));
        set.forEach((<type> each) -> sum[0] += each);

        Assert.assertEquals(32L + Abstract<name>SetTestCase.generateCollisions1().getFirst() + Abstract<name>SetTestCase.generateCollisions1().get(1), sum[0]<(delta.(type))>);
    }

    @Override
    @Test
    public void count()
    {
        super.count();
        Mutable<name>Set set = this.newWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().getFirst(), Abstract<name>SetTestCase.generateCollisions1().get(1));
        Assert.assertEquals(4L, set.count(<name>Predicates.greaterThan(<(literal.(type))("0")>)));
        Assert.assertEquals(3L, set.count(<name>Predicates.lessThan(<(literal.(type))("32")>)));
        Assert.assertEquals(1L, set.count(<name>Predicates.greaterThan(<(literal.(type))("32")>)));
    }

    @Override
    @Test
    public void select()
    {
        super.select();
        Mutable<name>Set set = this.newWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().getFirst(), Abstract<name>SetTestCase.generateCollisions1().get(1));
        Verify.assertSize(3, set.select(<name>Predicates.lessThan(<(literal.(type))("32")>)));
        Verify.assertSize(4, set.select(<name>Predicates.greaterThan(<(literal.(type))("0")>)));
    }

    @Override
    @Test
    public void reject()
    {
        super.reject();
        Mutable<name>Set set = this.newWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().getFirst(), Abstract<name>SetTestCase.generateCollisions1().get(1));
        Verify.assertSize(1, set.reject(<name>Predicates.greaterThan(<(literal.(type))("0")>)));
        Verify.assertSize(2, set.reject(<name>Predicates.lessThan(<(literal.(type))("32")>)));
    }

    @Override
    @Test
    public void detectIfNone()
    {
        super.detectIfNone();
        Mutable<name>Set set = this.newWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().getFirst(), Abstract<name>SetTestCase.generateCollisions1().get(1));
        Assert.assertEquals(<(literal.(type))("0")>, set.detectIfNone(<name>Predicates.lessThan(<(literal.(type))("1")>), <(literal.(type))("9")>)<(delta.(type))>);
        Assert.assertEquals(Abstract<name>SetTestCase.generateCollisions1().get(1), set.detectIfNone(<name>Predicates.greaterThan(Abstract<name>SetTestCase.generateCollisions1().getFirst()), <(literal.(type))("9")>)<(delta.(type))>);
        Assert.assertEquals(<(literal.(type))("9")>, set.detectIfNone(<name>Predicates.greaterThan(Abstract<name>SetTestCase.generateCollisions1().get(1)), <(literal.(type))("9")>)<(delta.(type))>);
    }

    @Override
    @Test
    public void collect()
    {
        super.collect();
        Mutable<name>Set set = this.newWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().getFirst(), Abstract<name>SetTestCase.generateCollisions1().get(1));
        Assert.assertEquals(
                UnifiedSet.newSetWith(<["-1", "0", "30"]:(literal.(type))(); separator=", ">, <(castIntToNarrowTypeWithParens.(type))({Abstract<name>SetTestCase.generateCollisions1().getFirst() - 1})>, <(castIntToNarrowTypeWithParens.(type))({Abstract<name>SetTestCase.generateCollisions1().get(1) - 1})>),
                set.collect((<type> byteParameter) -> <(castIntToNarrowTypeWithParens.(type))("byteParameter - 1")>));
    }

    @Override
    @Test
    public void toSortedArray()
    {
        super.toSortedArray();
        Mutable<name>Set set = this.newWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().getFirst(), Abstract<name>SetTestCase.generateCollisions1().get(1));
        Assert.assertArrayEquals(new <type>[]{<["0", "1", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().getFirst(), Abstract<name>SetTestCase.generateCollisions1().get(1)}, set.toSortedArray()<(delta.(type))>);
    }

    @Override
    @Test
    public void testEquals()
    {
        super.testEquals();
        Mutable<name>Set set1 = this.newWith(<["1", "31", "32"]:(literal.(type))(); separator=", ">);
        Mutable<name>Set set2 = this.newWith(<["32", "31", "1"]:(literal.(type))(); separator=", ">);
        Mutable<name>Set set3 = this.newWith(<["32", "32", "31", "1"]:(literal.(type))(); separator=", ">);
        Mutable<name>Set set4 = this.newWith(<["32", "32", "31", "1", "1"]:(literal.(type))(); separator=", ">);
        Verify.assertEqualsAndHashCode(set1, set2);
        Verify.assertEqualsAndHashCode(set1, set3);
        Verify.assertEqualsAndHashCode(set1, set4);
        Verify.assertEqualsAndHashCode(set2, set3);
        Verify.assertEqualsAndHashCode(set2, set4);
    }

    @Override
    @Test
    public void testHashCode()
    {
        super.testEquals();
        Mutable<name>Set set1 = this.newWith(<["1", "31", "32"]:(literal.(type))(); separator=", ">);
        Mutable<name>Set set2 = this.newWith(<["32", "31", "1"]:(literal.(type))(); separator=", ">);
        Assert.assertEquals(set1.hashCode(), set2.hashCode());
    }

    @Override
    @Test
    public void toBag()
    {
        Assert.assertEquals(<name>HashBag.newBagWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">), this.classUnderTest().toBag());
        Assert.assertEquals(<name>HashBag.newBagWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">), this.newWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">).toBag());
        Assert.assertEquals(<name>HashBag.newBagWith(<["0", "1", "31", "32"]:(literal.(type))(); separator=", ">), this.newWith(<["0", "1", "31", "32"]:(literal.(type))(); separator=", ">).toBag());
    }

    @Override
    @Test
    public void asLazy()
    {
        super.asLazy();
        Mutable<name>Set set = this.newWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().getFirst(), Abstract<name>SetTestCase.generateCollisions1().get(1));
        Assert.assertEquals(set.toSet(), set.asLazy().toSet());
        Verify.assertInstanceOf(Lazy<name>Iterable.class, set.asLazy());
    }

    @Override
    @Test
    public void asSynchronized()
    {
        super.asSynchronized();
        Mutable<name>Set set = this.newWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().getFirst(), Abstract<name>SetTestCase.generateCollisions1().get(1));
        Verify.assertInstanceOf(Synchronized<name>Set.class, set.asSynchronized());
        Assert.assertEquals(new Synchronized<name>Set(set), set.asSynchronized());
    }

    @Override
    @Test
    public void asUnmodifiable()
    {
        super.asUnmodifiable();
        Mutable<name>Set set = this.newWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">, Abstract<name>SetTestCase.generateCollisions1().getFirst(), Abstract<name>SetTestCase.generateCollisions1().get(1));
        Verify.assertInstanceOf(Unmodifiable<name>Set.class, set.asUnmodifiable());
        Assert.assertEquals(new Unmodifiable<name>Set(set), set.asUnmodifiable());
    }

    @Test
    public void union()
    {
        this.assertUnion(
                this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">),
                this.newWith(<["3", "4", "5"]:(literal.(type))(); separator=", ">),
                this.newWith(<["1", "2", "3", "4", "5"]:(literal.(type))(); separator=", ">));

        this.assertUnion(
                this.newWith(<["1", "2", "3", "6"]:(literal.(type))(); separator=", ">),
                this.newWith(<["3", "4", "5"]:(literal.(type))(); separator=", ">),
                this.newWith(<["1", "2", "3", "4", "5", "6"]:(literal.(type))(); separator=", ">));

        this.assertUnion(
                this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">),
                this.newWith(<["3", "4", "5" , "6"]:(literal.(type))(); separator=", ">),
                this.newWith(<["1", "2", "3", "4", "5", "6"]:(literal.(type))(); separator=", ">));

        this.assertUnion(
                this.newWith(),
                this.newWith(),
                this.newWith());

        this.assertUnion(
                this.newWith(),
                this.newWith(<["3", "4", "5"]:(literal.(type))(); separator=", ">),
                this.newWith(<["3", "4", "5"]:(literal.(type))(); separator=", ">));

        this.assertUnion(
                this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">),
                this.newWith(),
                this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">));
    }

    private void assertUnion(Mutable<name>Set set1, Mutable<name>Set set2, Mutable<name>Set expected)
    {
        Mutable<name>Set actual = set1.union(set2);
        Assert.assertEquals(expected, actual);
    }

    @Test
    public void intersect()
    {
        this.assertIntersect(
                this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">),
                this.newWith(<["3", "4", "5"]:(literal.(type))(); separator=", ">),
                this.newWith(<["3"]:(literal.(type))(); separator=", ">));

        this.assertIntersect(
                this.newWith(<["1", "2", "3", "6"]:(literal.(type))(); separator=", ">),
                this.newWith(<["3", "4", "5"]:(literal.(type))(); separator=", ">),
                this.newWith(<["3"]:(literal.(type))(); separator=", ">));

        this.assertIntersect(
                this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">),
                this.newWith(<["3", "4", "5" , "6"]:(literal.(type))(); separator=", ">),
                this.newWith(<["3"]:(literal.(type))(); separator=", ">));

        this.assertIntersect(
                this.newWith(),
                this.newWith(),
                this.newWith());

        this.assertIntersect(
                this.newWith(),
                this.newWith(<["3", "4", "5"]:(literal.(type))(); separator=", ">),
                this.newWith());

        this.assertIntersect(
                this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">),
                this.newWith(),
                this.newWith());
    }

    private void assertIntersect(Mutable<name>Set set1, Mutable<name>Set set2, Mutable<name>Set expected)
    {
        Mutable<name>Set actual = set1.intersect(set2);
        Assert.assertEquals(expected, actual);
    }

    @Test
    public void difference()
    {
        this.assertDifference(
                this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">),
                this.newWith(<["3", "4", "5"]:(literal.(type))(); separator=", ">),
                this.newWith(<["1", "2"]:(literal.(type))(); separator=", ">));

        this.assertDifference(
                this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">),
                this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">),
                this.newWith());

        this.assertDifference(
                this.newWith(),
                this.newWith(),
                this.newWith());

        this.assertDifference(
                this.newWith(),
                this.newWith(<["3", "4", "5"]:(literal.(type))(); separator=", ">),
                this.newWith());

        this.assertDifference(
                this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">),
                this.newWith(),
                this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">));
    }

    private void assertDifference(Mutable<name>Set set1, Mutable<name>Set set2, Mutable<name>Set expected)
    {
        Mutable<name>Set actual = set1.difference(set2);
        Assert.assertEquals(expected, actual);
    }

    @Test
    public void symmetricDifference()
    {
        this.assertSymmetricDifference(
                this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">),
                this.newWith(<["2", "3", "4"]:(literal.(type))(); separator=", ">),
                this.newWith(<["1", "4"]:(literal.(type))(); separator=", ">));

        this.assertSymmetricDifference(
                this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">),
                this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">),
                this.newWith());

        this.assertSymmetricDifference(
                this.newWith(),
                this.newWith(),
                this.newWith());

        this.assertSymmetricDifference(
                this.newWith(),
                this.newWith(<["3", "4", "5"]:(literal.(type))(); separator=", ">),
                this.newWith(<["3", "4", "5"]:(literal.(type))(); separator=", ">));

        this.assertSymmetricDifference(
                this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">),
                this.newWith(),
                this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">));
    }

    private void assertSymmetricDifference(Mutable<name>Set set1, Mutable<name>Set set2, Mutable<name>Set expected)
    {
        Mutable<name>Set actual = set1.symmetricDifference(set2);
        Assert.assertEquals(expected, actual);
    }

    @Test
    public void isSubsetOf()
    {
        this.assertIsSubsetOf(
                this.newWith(<["1", "2"]:(literal.(type))(); separator=", ">),
                this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">),
                true);

        this.assertIsSubsetOf(
                this.newWith(<["1", "4"]:(literal.(type))(); separator=", ">),
                this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">),
                false);

        this.assertIsSubsetOf(
                this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">),
                this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">),
                true);

        this.assertIsSubsetOf(
                this.newWith(),
                this.newWith(),
                true);

        this.assertIsSubsetOf(
                this.newWith(),
                this.newWith(<["3", "4", "5"]:(literal.(type))(); separator=", ">),
                true);

        this.assertIsSubsetOf(
                this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">),
                this.newWith(),
                false);
    }

    private void assertIsSubsetOf(Mutable<name>Set set1, Mutable<name>Set set2, boolean expected)
    {
        boolean actual = set1.isSubsetOf(set2);
        Assert.assertEquals(expected, actual);
    }

    @Test
    public void isProperSubsetOf()
    {
        this.assertIsProperSubsetOf(
                this.newWith(<["1", "2"]:(literal.(type))(); separator=", ">),
                this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">),
                true);

        this.assertIsProperSubsetOf(
                this.newWith(<["1", "4"]:(literal.(type))(); separator=", ">),
                this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">),
                false);

        this.assertIsProperSubsetOf(
                this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">),
                this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">),
                false);

        this.assertIsProperSubsetOf(
                this.newWith(),
                this.newWith(),
                false);

        this.assertIsProperSubsetOf(
                this.newWith(),
                this.newWith(<["3", "4", "5"]:(literal.(type))(); separator=", ">),
                true);

        this.assertIsProperSubsetOf(
                this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">),
                this.newWith(),
                false);
    }

    private void assertIsProperSubsetOf(Mutable<name>Set set1, Mutable<name>Set set2, boolean expected)
    {
        boolean actual = set1.isProperSubsetOf(set2);
        Assert.assertEquals(expected, actual);
    }

    @Test
    public void cartesianProduct()
    {
        this.assertCartesianProduct(
                this.newWith(<["1", "2"]:(literal.(type))(); separator=", ">),
                this.newWith(<["3", "4"]:(literal.(type))(); separator=", ">),
                Sets.mutable.with(
                        PrimitiveTuples.pair(<(literal.(type))("1")>, <(literal.(type))("3")>),
                        PrimitiveTuples.pair(<(literal.(type))("1")>, <(literal.(type))("4")>),
                        PrimitiveTuples.pair(<(literal.(type))("2")>, <(literal.(type))("3")>),
                        PrimitiveTuples.pair(<(literal.(type))("2")>, <(literal.(type))("4")>)));

        this.assertCartesianProduct(
                this.newWith(<["1", "2"]:(literal.(type))(); separator=", ">),
                this.newWith(<["1", "2"]:(literal.(type))(); separator=", ">),
                Sets.mutable.with(
                        PrimitiveTuples.pair(<(literal.(type))("1")>, <(literal.(type))("1")>),
                        PrimitiveTuples.pair(<(literal.(type))("1")>, <(literal.(type))("2")>),
                        PrimitiveTuples.pair(<(literal.(type))("2")>, <(literal.(type))("1")>),
                        PrimitiveTuples.pair(<(literal.(type))("2")>, <(literal.(type))("2")>)));

        this.assertCartesianProduct(
                this.newWith(<["1", "2"]:(literal.(type))(); separator=", ">),
                this.newWith(),
                Sets.mutable.empty());

        this.assertCartesianProduct(
                this.newWith(),
                this.newWith(<["1", "2"]:(literal.(type))(); separator=", ">),
                Sets.mutable.empty());
    }

    private void assertCartesianProduct(Mutable<name>Set set1, Mutable<name>Set set2, MutableSet\<<name><name>Pair> expected)
    {
        MutableSet\<<name><name>Pair> actual = set1.cartesianProduct(set2).toSet();
        Assert.assertEquals(expected, actual);
    }
}

>>

NaNTests(key) ::= <<
@Test
public void add_<key>()
{
    Mutable<name>Set set = this.newWith(<wrapperName>.<key>);
    Set\<<wrapperName>\> hashSet = new HashSet\<>();
    Assert.assertTrue(hashSet.add(<wrapperName>.<key>));

    Assert.assertFalse(hashSet.add(<wrapperName>.<key>));
    Assert.assertFalse(set.add(<wrapperName>.<key>));
    Verify.assertSize(hashSet.size(), set);
}

>>
