import "copyright.stg" import "primitiveEquals.stg" import "primitiveHashCode.stg" import "primitiveLiteral.stg" isTest() ::= "true" targetPath() ::= "org/eclipse/collections/impl/collection/immutable/primitive" fileName(primitive) ::= "AbstractImmutableCollectionTestCase" class(primitive) ::= << >> body(type, wrapperName, name) ::= << package org.eclipse.collections.impl.collection.immutable.primitive; import org.eclipse.collections.api.collection.primitive.ImmutableCollection; import org.eclipse.collections.api.collection.primitive.MutableCollection; import org.eclipse.collections.impl.collection.mutable.primitive.AbstractIterableTestCase; import org.junit.Assert; import org.junit.Test; /** * Abstract JUnit test for {@link ImmutableCollection}s. * This file was automatically generated from template file abstractImmutablePrimitiveCollectionTestCase.stg. */ public abstract class AbstractImmutableCollectionTestCase extends AbstractIterableTestCase { @Override protected abstract ImmutableCollection classUnderTest(); @Override protected abstract ImmutableCollection newWith(... elements); @Override protected abstract MutableCollection newMutableCollectionWith(... elements); protected void assertSizeAndContains(ImmutableCollection collection, ... elements) { Assert.assertEquals(elements.length, collection.size()); for ( i: elements) { Assert.assertTrue(collection.contains(i)); } } @Test public void testNewWith() { ImmutableCollection immutableCollection = this.newWith(); ImmutableCollection collection = immutableCollection.newWith(<(literal.(type))("1")>); ImmutableCollection collection0 = immutableCollection.newWith(<(literal.(type))("1")>).newWith(<(literal.(type))("2")>); ImmutableCollection collection1 = immutableCollection.newWith(<(literal.(type))("1")>).newWith(<(literal.(type))("2")>).newWith(<(literal.(type))("3")>); ImmutableCollection collection2 = immutableCollection.newWith(<(literal.(type))("1")>).newWith(<(literal.(type))("2")>).newWith(<(literal.(type))("3")>).newWith(<(literal.(type))("4")>); ImmutableCollection collection3 = immutableCollection.newWith(<(literal.(type))("1")>).newWith(<(literal.(type))("2")>).newWith(<(literal.(type))("3")>).newWith(<(literal.(type))("4")>).newWith(<(literal.(type))("5")>); this.assertSizeAndContains(immutableCollection); this.assertSizeAndContains(collection, <(literal.(type))("1")>); this.assertSizeAndContains(collection0, <(literal.(type))("1")>, <(literal.(type))("2")>); this.assertSizeAndContains(collection1, <(literal.(type))("1")>, <(literal.(type))("2")>, <(literal.(type))("3")>); this.assertSizeAndContains(collection2, <(literal.(type))("1")>, <(literal.(type))("2")>, <(literal.(type))("3")>, <(literal.(type))("4")>); this.assertSizeAndContains(collection3, <(literal.(type))("1")>, <(literal.(type))("2")>, <(literal.(type))("3")>, <(literal.(type))("4")>, <(literal.(type))("5")>); } @Test public void newWithAll() { ImmutableCollection immutableCollection = this.newWith(); ImmutableCollection collection = immutableCollection.newWithAll(this.newMutableCollectionWith(<(literal.(type))("1")>)); ImmutableCollection collection0 = collection.newWithAll(this.newMutableCollectionWith(<(literal.(type))("2")>)); ImmutableCollection collection1 = collection0.newWithAll(this.newMutableCollectionWith(<(literal.(type))("3")>)); ImmutableCollection collection2 = immutableCollection.newWithAll(this.newMutableCollectionWith(<["1", "2", "3", "4"]:(literal.(type))(); separator=", ">)); ImmutableCollection collection3 = immutableCollection.newWithAll(this.newMutableCollectionWith(<["1", "2", "3", "4", "5"]:(literal.(type))(); separator=", ">)); this.assertSizeAndContains(immutableCollection); this.assertSizeAndContains(collection, <(literal.(type))("1")>); this.assertSizeAndContains(collection0, <(literal.(type))("1")>, <(literal.(type))("2")>); this.assertSizeAndContains(collection1, <(literal.(type))("1")>, <(literal.(type))("2")>, <(literal.(type))("3")>); this.assertSizeAndContains(collection2, <(literal.(type))("1")>, <(literal.(type))("2")>, <(literal.(type))("3")>, <(literal.(type))("4")>); this.assertSizeAndContains(collection3, <(literal.(type))("1")>, <(literal.(type))("2")>, <(literal.(type))("3")>, <(literal.(type))("4")>, <(literal.(type))("5")>); } @Test public void newWithout() { ImmutableCollection collection3 = this.newWith(<(literal.(type))("1")>, <(literal.(type))("2")>, <(literal.(type))("3")>, <(literal.(type))("4")>, <(literal.(type))("5")>); ImmutableCollection collection2 = collection3.newWithout(<(literal.(type))("5")>); ImmutableCollection collection1 = collection2.newWithout(<(literal.(type))("4")>); ImmutableCollection collection0 = collection1.newWithout(<(literal.(type))("3")>); ImmutableCollection collection4 = collection0.newWithout(<(literal.(type))("2")>); ImmutableCollection collection5 = collection4.newWithout(<(literal.(type))("1")>); ImmutableCollection collection6 = collection5.newWithout(<(literal.(type))("0")>); this.assertSizeAndContains(collection6); this.assertSizeAndContains(collection5); this.assertSizeAndContains(collection4, <(literal.(type))("1")>); this.assertSizeAndContains(collection0, <(literal.(type))("1")>, <(literal.(type))("2")>); this.assertSizeAndContains(collection1, <(literal.(type))("1")>, <(literal.(type))("2")>, <(literal.(type))("3")>); this.assertSizeAndContains(collection2, <(literal.(type))("1")>, <(literal.(type))("2")>, <(literal.(type))("3")>, <(literal.(type))("4")>); } @Test public void newWithoutAll() { ImmutableCollection collection3 = this.newWith(<(literal.(type))("1")>, <(literal.(type))("2")>, <(literal.(type))("3")>, <(literal.(type))("4")>, <(literal.(type))("5")>); ImmutableCollection collection2 = collection3.newWithoutAll(this.newMutableCollectionWith(<(literal.(type))("5")>)); ImmutableCollection collection1 = collection2.newWithoutAll(this.newMutableCollectionWith(<(literal.(type))("4")>)); ImmutableCollection collection0 = collection1.newWithoutAll(this.newMutableCollectionWith(<(literal.(type))("3")>)); ImmutableCollection collection4 = collection0.newWithoutAll(this.newMutableCollectionWith(<(literal.(type))("2")>)); ImmutableCollection collection5 = collection4.newWithoutAll(this.newMutableCollectionWith(<(literal.(type))("1")>)); ImmutableCollection collection6 = collection5.newWithoutAll(this.newMutableCollectionWith(<(literal.(type))("0")>)); this.assertSizeAndContains(collection6); this.assertSizeAndContains(collection5); this.assertSizeAndContains(collection4, <(literal.(type))("1")>); this.assertSizeAndContains(collection0, <(literal.(type))("1")>, <(literal.(type))("2")>); this.assertSizeAndContains(collection1, <(literal.(type))("1")>, <(literal.(type))("2")>, <(literal.(type))("3")>); this.assertSizeAndContains(collection2, <(literal.(type))("1")>, <(literal.(type))("2")>, <(literal.(type))("3")>, <(literal.(type))("4")>); } } >>