import "copyrightAndOthers.stg" import "primitiveEquals.stg" import "primitiveHashCode.stg" import "primitiveLiteral.stg" isTest() ::= "true" targetPath() ::= "org/eclipse/collections/impl/collection/mutable/primitive" fileName(primitive) ::= "AbstractIterableTestCase" class(primitive) ::= << >> body(type, wrapperName, name) ::= << package org.eclipse.collections.impl.collection.mutable.primitive; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.NoSuchElementException; import java.util.Set; import org.eclipse.collections.api.Iterable; import org.eclipse.collections.api.LazyIterable; import org.eclipse.collections.api.RichIterable; import org.eclipse.collections.api.block.function.primitive.ToObjectFunction; import org.eclipse.collections.api.iterator.Iterator; import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.list.primitive.MutableList; import org.eclipse.collections.impl.bag.mutable.primitive.HashBag; import org.eclipse.collections.impl.block.factory.Comparators; import org.eclipse.collections.impl.block.factory.primitive.Predicates; import org.eclipse.collections.impl.factory.Bags; import org.eclipse.collections.impl.factory.Lists; import org.eclipse.collections.impl.factory.Sets; import org.eclipse.collections.impl.factory.primitive.BooleanLists; import org.eclipse.collections.impl.factory.primitive.BooleanSets; import org.eclipse.collections.impl.factory.primitive.ByteLists; import org.eclipse.collections.impl.factory.primitive.ByteSets; import org.eclipse.collections.impl.factory.primitive.CharLists; import org.eclipse.collections.impl.factory.primitive.CharSets; import org.eclipse.collections.impl.factory.primitive.DoubleLists; import org.eclipse.collections.impl.factory.primitive.DoubleSets; import org.eclipse.collections.impl.factory.primitive.FloatLists; import org.eclipse.collections.impl.factory.primitive.FloatSets; import org.eclipse.collections.impl.factory.primitive.IntLists; import org.eclipse.collections.impl.factory.primitive.IntSets; import org.eclipse.collections.impl.factory.primitive.LongLists; import org.eclipse.collections.impl.factory.primitive.LongSets; import org.eclipse.collections.impl.factory.primitive.ShortLists; import org.eclipse.collections.impl.factory.primitive.ShortSets; import org.eclipse.collections.impl.list.Interval; import org.eclipse.collections.impl.list.mutable.primitive.ArrayList; import org.eclipse.collections.impl.set.mutable.primitive.HashSet; import org.eclipse.collections.impl.test.Verify; import org.junit.Assert; import org.junit.Test; /** * Abstract JUnit test for {@link Iterable}s * This file was automatically generated from template file abstractPrimitiveIterableTestCase.stg. */ public abstract class AbstractIterableTestCase { protected abstract Iterable classUnderTest(); protected abstract Iterable newWith(... elements); protected abstract Iterable newMutableCollectionWith(... elements); protected abstract RichIterable\<\> newObjectCollectionWith(... elements); @Test public void newCollectionWith() { Iterable iterable = this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">); Verify.assertSize(3, iterable); Verify.assertSize(4, this.newWith(<["0", "1", "31", "32"]:(literal.(type))(); separator=", ">)); Assert.assertTrue(iterable.containsAll(<["1", "2", "3"]:(literal.(type))(); separator=", ">)); Iterable iterable1 = this.newWith(); Verify.assertEmpty(iterable1); Assert.assertFalse(iterable1.containsAll(<["1", "2", "3"]:(literal.(type))(); separator=", ">)); Iterable iterable2 = this.newWith(<(literal.(type))("1")>); Verify.assertSize(1, iterable2); Assert.assertFalse(iterable2.containsAll(<["1", "2", "3"]:(literal.(type))(); separator=", ">)); } @Test public void newCollection() { Assert.assertEquals(this.newMutableCollectionWith(), this.newWith()); Assert.assertEquals(this.newMutableCollectionWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">), this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">)); Assert.assertEquals(this.newMutableCollectionWith(<["0", "1", "31", "32"]:(literal.(type))(); separator=", ">), this.newWith(<["0", "1", "31", "32"]:(literal.(type))(); separator=", ">)); } @Test public void isEmpty() { Verify.assertEmpty(this.newWith()); Verify.assertNotEmpty(this.classUnderTest()); Verify.assertNotEmpty(this.newWith(<["0", "1", "31", "32"]:(literal.(type))(); separator=", ">)); Verify.assertNotEmpty(this.newWith(<["0", "1", "2"]:(literal.(type))(); separator=", ">)); Verify.assertNotEmpty(this.newWith(<["0", "31"]:(literal.(type))(); separator=", ">)); Verify.assertNotEmpty(this.newWith(<["31", "32"]:(literal.(type))(); separator=", ">)); Verify.assertNotEmpty(this.newWith(<["32", "33"]:(literal.(type))(); separator=", ">)); } @Test public void notEmpty() { Assert.assertFalse(this.newWith().notEmpty()); Assert.assertTrue(this.classUnderTest().notEmpty()); Assert.assertTrue(this.newWith(<["0", "1", "31", "32"]:(literal.(type))(); separator=", ">).notEmpty()); Assert.assertTrue(this.newWith(<["0", "1", "2"]:(literal.(type))(); separator=", ">).notEmpty()); Assert.assertTrue(this.newWith(<["0", "31"]:(literal.(type))(); separator=", ">).notEmpty()); Assert.assertTrue(this.newWith(<["31", "32"]:(literal.(type))(); separator=", ">).notEmpty()); Assert.assertTrue(this.newWith(<["32", "33"]:(literal.(type))(); separator=", ">).notEmpty()); } @Test public void tap() { MutableList tapResult = Lists.mutable.empty(); Iterable collection = this.newWith(<["14", "2", "30", "31", "32", "35", "0", "1"]:(literal.(type))(); separator=", ">); Assert.assertSame(collection, collection.tap(tapResult::add)); Assert.assertEquals(collection.toList(), tapResult); } @Test public void contains() { Iterable iterable = this.newWith(<["14", "2", "30", "31", "32", "35", "0", "1"]:(literal.(type))(); separator=", ">); Assert.assertFalse(iterable.contains(<(literal.(type))("29")>)); Assert.assertFalse(iterable.contains(<(literal.(type))("49")>)); [] numbers = {<["14", "2", "30", "31", "32", "35", "0", "1"]:(literal.(type))(); separator=", ">}; for ( number : numbers) { Assert.assertTrue(iterable.contains(number)); } Assert.assertFalse(iterable.contains(<(literal.(type))("-1")>)); Assert.assertFalse(iterable.contains(<(literal.(type))("29")>)); Assert.assertFalse(iterable.contains(<(literal.(type))("49")>)); Iterable iterable1 = this.newWith(<["0", "1", "1", "2", "2", "2"]:(literal.(type))(); separator=", ">); Assert.assertTrue(iterable1.contains(<(literal.(type))("0")>)); Assert.assertTrue(iterable1.contains(<(literal.(type))("1")>)); Assert.assertTrue(iterable1.contains(<(literal.(type))("2")>)); Assert.assertFalse(iterable1.contains(<(literal.(type))("3")>)); Iterable iterable2 = this.classUnderTest(); for ( each = 1; each \<= iterable2.size(); each++) { Assert.assertTrue(iterable2.contains(each)); } Assert.assertFalse(iterable2.contains(<(castIntToNarrowTypeWithParens.(type))("iterable2.size() + 1")>)); } @Test public void containsAllArray() { Assert.assertTrue(this.classUnderTest().containsAll(this.classUnderTest().toArray())); Assert.assertFalse(this.classUnderTest().containsAll(<(castIntToNarrowTypeWithParens.(type))("this.classUnderTest().size() + 1")>)); Iterable iterable = this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">); Assert.assertTrue(iterable.containsAll(<(literal.(type))("1")>)); Assert.assertTrue(iterable.containsAll(<["1", "2", "3"]:(literal.(type))(); separator=", ">)); Assert.assertFalse(iterable.containsAll(<["1", "2", "3", "4"]:(literal.(type))(); separator=", ">)); Assert.assertFalse(iterable.containsAll(<["1", "2", "4"]:(literal.(type))(); separator=", ">)); Assert.assertFalse(iterable.containsAll(<["4", "5", "6"]:(literal.(type))(); separator=", ">)); Iterable iterable1 = this.newWith(<["14", "2", "30", "32", "35", "0", "1"]:(literal.(type))(); separator=", ">); Assert.assertTrue(iterable1.containsAll(<(literal.(type))("14")>)); Assert.assertTrue(iterable1.containsAll(<(literal.(type))("35")>)); Assert.assertFalse(iterable1.containsAll(<(literal.(type))("-1")>)); Assert.assertTrue(iterable1.containsAll(<["14", "1", "30"]:(literal.(type))(); separator=", ">)); Assert.assertTrue(iterable1.containsAll(<["14", "1", "32"]:(literal.(type))(); separator=", ">)); Assert.assertTrue(iterable1.containsAll(<["14", "1", "35"]:(literal.(type))(); separator=", ">)); Assert.assertFalse(iterable1.containsAll(<["0", "2", "35", "-1"]:(literal.(type))(); separator=", ">)); Assert.assertFalse(iterable1.containsAll(<["31", "-1"]:(literal.(type))(); separator=", ">)); Iterable iterable2 = this.newWith(<["0", "1", "1", "2", "2", "2"]:(literal.(type))(); separator=", ">); Assert.assertTrue(iterable2.containsAll(<(literal.(type))("0")>)); Assert.assertTrue(iterable2.containsAll(<["0", "0", "0"]:(literal.(type))(); separator=", ">)); Assert.assertTrue(iterable2.containsAll(<["0", "1", "1"]:(literal.(type))(); separator=", ">)); Assert.assertTrue(iterable2.containsAll(<["0", "1", "2"]:(literal.(type))(); separator=", ">)); Assert.assertFalse(iterable2.containsAll(<["0", "1", "2", "3", "4"]:(literal.(type))(); separator=", ">)); Assert.assertFalse(iterable2.containsAll(<["3", "4"]:(literal.(type))(); separator=", ">)); int size = 33; [] array = new [size]; for (int i = 0; i \< size; i++) { array[i] = <(castIntToNarrowTypeWithParens.(type))("i + 1")>; } Iterable iterable3 = this.newWith(array); Assert.assertTrue(iterable3.containsAll(<["1", "2", "3"]:(literal.(type))(); separator=", ">)); Assert.assertTrue(iterable3.containsAll()); Assert.assertFalse(iterable3.containsAll(<["3", "4", "5", "33", "34"]:(literal.(type))(); separator=", ">)); Assert.assertTrue(iterable3.containsAll(array)); Iterable iterable4 = Sets.mutable.with(array); Assert.assertTrue(iterable4.containsAll(<["1", "2", "3"]:(literal.(type))(); separator=", ">)); Assert.assertTrue(iterable4.containsAll()); Assert.assertFalse(iterable4.containsAll(<["3", "4", "5", "33", "34"]:(literal.(type))(); separator=", ">)); Assert.assertTrue(iterable4.containsAll(array)); } @Test public void containsAllIterable() { Iterable source = this.classUnderTest(); Assert.assertTrue(source.containsAll(this.classUnderTest())); Assert.assertFalse(source.containsAll(ArrayList.newListWith(<(castIntToNarrowTypeWithParens.(type))("source.size() + 1")>))); Iterable iterable = this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">); Assert.assertTrue(this.newWith().containsAll(new ArrayList())); Assert.assertFalse(this.newWith().containsAll(ArrayList.newListWith(<(literal.(type))("1")>))); Assert.assertTrue(iterable.containsAll(ArrayList.newListWith(<(literal.(type))("1")>))); Assert.assertTrue(iterable.containsAll(ArrayList.newListWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">))); Assert.assertFalse(iterable.containsAll(ArrayList.newListWith(<["1", "2", "3", "4"]:(literal.(type))(); separator=", ">))); Assert.assertFalse(iterable.containsAll(ArrayList.newListWith(<["1", "2", "4"]:(literal.(type))(); separator=", ">))); Assert.assertFalse(iterable.containsAll(ArrayList.newListWith(<["4", "5", "6"]:(literal.(type))(); separator=", ">))); Iterable iterable1 = this.newWith(<["14", "2", "30", "32", "35", "0", "1"]:(literal.(type))(); separator=", ">); Assert.assertTrue(iterable1.containsAll(HashSet.newSetWith(<(literal.(type))("14")>))); Assert.assertTrue(iterable1.containsAll(HashSet.newSetWith(<(literal.(type))("35")>))); Assert.assertFalse(iterable1.containsAll(HashSet.newSetWith(<(literal.(type))("-1")>))); Assert.assertTrue(iterable1.containsAll(HashSet.newSetWith(<["14", "1", "30"]:(literal.(type))(); separator=", ">))); Assert.assertTrue(iterable1.containsAll(HashSet.newSetWith(<["14", "1", "32"]:(literal.(type))(); separator=", ">))); Assert.assertTrue(iterable1.containsAll(HashSet.newSetWith(<["14", "1", "35"]:(literal.(type))(); separator=", ">))); Assert.assertFalse(iterable1.containsAll(HashSet.newSetWith(<["0", "2", "35", "-1"]:(literal.(type))(); separator=", ">))); Assert.assertFalse(iterable1.containsAll(HashSet.newSetWith(<["31", "-1"]:(literal.(type))(); separator=", ">))); Iterable iterable2 = this.newWith(<["0", "1", "1", "2", "2", "2"]:(literal.(type))(); separator=", ">); Assert.assertTrue(iterable2.containsAll(ArrayList.newListWith(<(literal.(type))("0")>))); Assert.assertTrue(iterable2.containsAll(ArrayList.newListWith(<["0", "0", "0"]:(literal.(type))(); separator=", ">))); Assert.assertTrue(iterable2.containsAll(ArrayList.newListWith(<["0", "1", "1"]:(literal.(type))(); separator=", ">))); Assert.assertTrue(iterable2.containsAll(ArrayList.newListWith(<["0", "1", "2"]:(literal.(type))(); separator=", ">))); Assert.assertFalse(iterable2.containsAll(ArrayList.newListWith(<["0", "1", "2", "3", "4"]:(literal.(type))(); separator=", ">))); Assert.assertFalse(iterable2.containsAll(ArrayList.newListWith(<["3", "4"]:(literal.(type))(); separator=", ">))); int size = 33; [] array = new [size]; for (int i = 0; i \< size; i++) { array[i] = <(castIntToNarrowTypeWithParens.(type))("i + 1")>; } Iterable iterable3 = this.newWith(array); Assert.assertTrue(iterable3.containsAll(Lists.immutable.with(<["1", "2", "3"]:(literal.(type))(); separator=", ">))); Assert.assertTrue(iterable3.containsAll(Lists.mutable.empty())); Assert.assertFalse(iterable3.containsAll(Lists.mutable.with(<["3", "4", "5", "33", "34"]:(literal.(type))(); separator=", ">))); Assert.assertTrue(iterable3.containsAll(Lists.immutable.with(array))); Iterable iterable4 = Sets.mutable.with(array); Assert.assertTrue(iterable4.containsAll(Lists.immutable.with(<["1", "2", "3"]:(literal.(type))(); separator=", ">))); Assert.assertTrue(iterable4.containsAll(Lists.mutable.empty())); Assert.assertFalse(iterable4.containsAll(Lists.mutable.with(<["3", "4", "5", "33", "34"]:(literal.(type))(); separator=", ">))); Assert.assertTrue(iterable4.containsAll(Lists.immutable.with(array))); } @Test public void containsAnyArray() { Iterable iterable = this.newWith(<["1", "2", "3", "4", "5"]:(literal.(type))(); separator=", ">); Assert.assertTrue(iterable.containsAny(<["1", "1", "1"]:(literal.(type))(); separator=", ">)); Assert.assertFalse(iterable.containsAny()); Assert.assertTrue(iterable.containsAny(<["1", "2", "3"]:(literal.(type))(); separator=", ">)); Assert.assertFalse(iterable.containsAny(<["6", "7", "8"]:(literal.(type))(); separator=", ">)); Iterable iterable2 = this.newWith(<["0", "1", "3", "7"]:(literal.(type))(); separator=", ">); Assert.assertTrue(iterable2.containsAny(<["3", "3", "1", "9"]:(literal.(type))(); separator=", ">)); Assert.assertFalse(iterable2.containsAny()); Assert.assertTrue(iterable2.containsAny(<["-1", "3", "5"]:(literal.(type))(); separator=", ">)); Assert.assertFalse(iterable2.containsAny(<["2", "4", "6"]:(literal.(type))(); separator=", ">)); int size = 33; [] array = new [size]; [] unmatched = new [size]; for (int i = 0; i \< size; i++) { array[i] = <(castIntToNarrowTypeWithParens.(type))("i + 1")>; unmatched[i] = <(castIntToNarrowTypeWithParens.(type))("i + 34")>; } Iterable iterable3 = this.newWith(array); Assert.assertTrue(iterable3.containsAny(array)); Assert.assertFalse(iterable3.containsAny(unmatched)); Iterable iterable4 = Sets.mutable.with(array); Assert.assertTrue(iterable4.containsAny(array)); Assert.assertFalse(iterable4.containsAny(unmatched)); Iterable emptyIterable = this.newWith(); Assert.assertFalse(emptyIterable.containsAny()); Assert.assertFalse(emptyIterable.containsAny(<["0", "0"]:(literal.(type))(); separator=", ">)); Assert.assertFalse(emptyIterable.containsAny(<(literal.(type))("-1")>)); Assert.assertFalse(emptyIterable.containsAny(<["1", "2", "3"]:(literal.(type))(); separator=", ">)); } @Test public void containsAnyIterable() { Iterable iterable = this.newWith(<["1", "2", "3", "4", "5"]:(literal.(type))(); separator=", ">); Assert.assertTrue(iterable.containsAny(Lists.immutable.with(<["1", "1", "1"]:(literal.(type))(); separator=", ">))); Assert.assertFalse(iterable.containsAny(Lists.mutable.empty())); Assert.assertTrue(iterable.containsAny(Lists.immutable.with(<["1", "2", "3"]:(literal.(type))(); separator=", ">))); Assert.assertFalse(iterable.containsAny(Lists.mutable.with(<["6", "7", "8"]:(literal.(type))(); separator=", ">))); Iterable iterable2 = this.newWith(<["0", "1", "3", "7"]:(literal.(type))(); separator=", ">); Assert.assertTrue(iterable2.containsAny(Sets.immutable.with(<["3", "3", "1", "9"]:(literal.(type))(); separator=", ">))); Assert.assertFalse(iterable2.containsAny(Sets.mutable.empty())); Assert.assertTrue(iterable2.containsAny(Sets.immutable.with(<["-1", "3", "5"]:(literal.(type))(); separator=", ">))); Assert.assertFalse(iterable2.containsAny(Sets.mutable.with(<["2", "4", "6"]:(literal.(type))(); separator=", ">))); Iterable emptyIterable = this.newWith(); Assert.assertFalse(emptyIterable.containsAny(Lists.mutable.empty())); Assert.assertFalse(emptyIterable.containsAny(Lists.immutable.with(<["0", "0"]:(literal.(type))(); separator=", ">))); Assert.assertFalse(emptyIterable.containsAny(Lists.mutable.with(<(literal.(type))("-1")>))); Assert.assertFalse(emptyIterable.containsAny(Lists.immutable.with(<["1", "2", "3"]:(literal.(type))(); separator=", ">))); int size = 33; [] array = new [size]; [] unmatched = new [size]; [] bigger = new [size + 1]; for (int i = 0; i \< size; i++) { array[i] = <(castIntToNarrowTypeWithParens.(type))("i + 1")>; bigger[i] = <(castIntToNarrowTypeWithParens.(type))("i + 1")>; unmatched[i] = <(castIntToNarrowTypeWithParens.(type))("i + 34")>; } bigger[size - 1] = <(literal.(type))("33")>; Iterable iterable3 = this.newWith(array); Assert.assertTrue(iterable3.containsAny(Lists.immutable.with(array))); Assert.assertFalse(iterable3.containsAny(Lists.mutable.with(unmatched))); Assert.assertFalse(iterable3.containsAny(Sets.mutable.with(unmatched))); Assert.assertTrue(iterable3.containsAny(Sets.mutable.with(bigger))); Iterable iterable4 = Sets.mutable.with(array); Assert.assertTrue(iterable4.containsAny(Lists.immutable.with(array))); Assert.assertFalse(iterable4.containsAny(Lists.mutable.with(unmatched))); Assert.assertTrue(iterable4.containsAny(Sets.immutable.with(array))); Assert.assertTrue(iterable4.containsAny(Sets.immutable.with(bigger))); } @Test public void containsNoneArray() { Iterable iterable = this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">); Assert.assertFalse(iterable.containsNone(<["1", "1"]:(literal.(type))(); separator=", ">)); Assert.assertTrue(iterable.containsNone()); Assert.assertFalse(iterable.containsNone(<["3", "4", "5", "6"]:(literal.(type))(); separator=", ">)); Assert.assertTrue(iterable.containsNone(<["7", "8", "11"]:(literal.(type))(); separator=", ">)); Iterable iterable2 = this.newWith(<["0", "1", "3", "7"]:(literal.(type))(); separator=", ">); Assert.assertTrue(iterable2.containsNone(<["2", "4", "6"]:(literal.(type))(); separator=", ">)); Assert.assertTrue(iterable2.containsNone()); Assert.assertFalse(iterable2.containsNone(<["-1", "1", "3"]:(literal.(type))(); separator=", ">)); Assert.assertFalse(iterable2.containsNone(<["7", "3", "1", "0"]:(literal.(type))(); separator=", ">)); int size = 33; [] array = new [size]; [] unmatched = new [size]; for (int i = 0; i \< size; i++) { array[i] = <(castIntToNarrowTypeWithParens.(type))("i + 1")>; unmatched[i] = <(castIntToNarrowTypeWithParens.(type))("i + 34")>; } Iterable iterable3 = this.newWith(array); Assert.assertFalse(iterable3.containsNone(array)); Assert.assertTrue(iterable3.containsNone(unmatched)); Iterable iterable4 = Sets.mutable.with(array); Assert.assertFalse(iterable4.containsNone(array)); Assert.assertTrue(iterable4.containsNone(unmatched)); Iterable emptyIterable = this.newWith(); Assert.assertTrue(emptyIterable.containsNone(<["1", "2", "3"]:(literal.(type))(); separator=", ">)); Assert.assertTrue(emptyIterable.containsNone()); Assert.assertTrue(emptyIterable.containsNone(<["-1", "5"]:(literal.(type))(); separator=", ">)); Assert.assertTrue(emptyIterable.containsNone(<(literal.(type))("0")>)); } @Test public void containsNoneIterable() { Iterable iterable = this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">); Assert.assertFalse(iterable.containsNone(Lists.immutable.with(<["1", "1"]:(literal.(type))(); separator=", ">))); Assert.assertTrue(iterable.containsNone(Lists.mutable.empty())); Assert.assertFalse(iterable.containsNone(Lists.mutable.with(<["3", "4", "5", "6"]:(literal.(type))(); separator=", ">))); Assert.assertTrue(iterable.containsNone(Lists.immutable.with(<["7", "8", "11"]:(literal.(type))(); separator=", ">))); Iterable iterable2 = this.newWith(<["0", "1", "3", "7"]:(literal.(type))(); separator=", ">); Assert.assertTrue(iterable2.containsNone(Sets.immutable.with(<["2", "4", "6"]:(literal.(type))(); separator=", ">))); Assert.assertTrue(iterable2.containsNone(Sets.mutable.empty())); Assert.assertFalse(iterable2.containsNone(Sets.immutable.with(<["-1", "1", "3"]:(literal.(type))(); separator=", ">))); Assert.assertFalse(iterable2.containsNone(Sets.mutable.with(<["7", "3", "1", "0"]:(literal.(type))(); separator=", ">))); Iterable emptyIterable = this.newWith(); Assert.assertTrue(emptyIterable.containsNone(Lists.immutable.with(<["1", "2", "3"]:(literal.(type))(); separator=", ">))); Assert.assertTrue(emptyIterable.containsNone(Lists.mutable.empty())); Assert.assertTrue(emptyIterable.containsNone(Lists.immutable.with(<["-1", "5"]:(literal.(type))(); separator=", ">))); Assert.assertTrue(emptyIterable.containsNone(Lists.mutable.with(<(literal.(type))("0")>))); int size = 33; [] array = new [size]; [] unmatched = new [size]; [] bigger = new [size + 1]; for (int i = 0; i \< size; i++) { array[i] = <(castIntToNarrowTypeWithParens.(type))("i + 1")>; bigger[i] = <(castIntToNarrowTypeWithParens.(type))("i + 1")>; unmatched[i] = <(castIntToNarrowTypeWithParens.(type))("i + 34")>; } bigger[size - 1] = <(literal.(type))("33")>; Iterable iterable3 = this.newWith(array); Assert.assertFalse(iterable3.containsNone(Lists.immutable.with(array))); Assert.assertTrue(iterable3.containsNone(Lists.mutable.with(unmatched))); Assert.assertTrue(iterable3.containsNone(Sets.mutable.with(unmatched))); Assert.assertFalse(iterable3.containsNone(Sets.mutable.with(bigger))); Iterable iterable4 = Sets.mutable.with(array); Assert.assertFalse(iterable4.containsNone(Lists.immutable.with(array))); Assert.assertTrue(iterable4.containsNone(Lists.mutable.with(unmatched))); Assert.assertFalse(iterable4.containsNone(Sets.immutable.with(array))); Assert.assertFalse(iterable4.containsNone(Sets.immutable.with(bigger))); } @Test public abstract void Iterator(); @Test(expected = NoSuchElementException.class) public void Iterator_throws() { Iterator iterator = this.classUnderTest().Iterator(); while (iterator.hasNext()) { iterator.next(); } iterator.next(); } @Test(expected = NoSuchElementException.class) public void Iterator_throws_non_empty_collection() { Iterable iterable = this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">); Iterator iterator = iterable.Iterator(); while (iterator.hasNext()) { iterator.next(); } iterator.next(); } @Test public void forEach() { [] sum = new [1]; this.classUnderTest().forEach(each -> sum[0] += each); int size = this.classUnderTest().size(); long sum1 = (long) ((size * (size + 1)) / 2); Assert.assertEquals(sum1, sum[0]); } @Test public void size() { Verify.assertSize(0, this.newWith()); Verify.assertSize(1, this.newWith(<(literal.(type))("3")>)); Verify.assertSize(3, this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">)); } @Test public void count() { Iterable iterable = this.classUnderTest(); int size = iterable.size(); Assert.assertEquals(size >= 3 ? 3 : size, iterable.count(Predicates.lessThan(<(literal.(type))("4")>))); Assert.assertEquals(2L, this.newWith(<["1", "0", "2"]:(literal.(type))(); separator=", ">).count(Predicates.greaterThan())); Assert.assertEquals(1, this.newWith(<["1"]:(literal.(type))(); separator=", ">).count(Predicates.alwaysTrue())); Assert.assertEquals(0, this.newWith(<["1"]:(literal.(type))(); separator=", ">).count(Predicates.alwaysFalse())); } @Test public void anySatisfy() { Assert.assertTrue(this.newWith(<["1", "-1", "2"]:(literal.(type))(); separator=", ">).anySatisfy(Predicates.greaterThan(<(literal.(type))("0")>))); Assert.assertFalse(this.newWith(<["1", "-1", "2"]:(literal.(type))(); separator=", ">).anySatisfy(Predicates.equal(<(literal.(type))("0")>))); Assert.assertTrue(this.newWith(<["-1", "-1", "-2", "31", "32"]:(literal.(type))(); separator=", ">).anySatisfy(Predicates.greaterThan(<(literal.(type))("0")>))); Assert.assertTrue(this.newWith(<["2", "-1", "-2", "31", "32"]:(literal.(type))(); separator=", ">).anySatisfy(Predicates.greaterThan(<(literal.(type))("0")>))); Assert.assertFalse(this.newWith(<["1", "-1", "31", "32"]:(literal.(type))(); separator=", ">).anySatisfy(Predicates.equal(<(literal.(type))("0")>))); Assert.assertTrue(this.newWith(<["32"]:(literal.(type))(); separator=", ">).anySatisfy(Predicates.greaterThan(<(literal.(type))("0")>))); Iterable iterable = this.newWith(<["0", "1", "2"]:(literal.(type))(); separator=", ">); Assert.assertTrue(iterable.anySatisfy(value -> <(lessThan.(type))("value", {<(literal.(type))("3")>})>)); Assert.assertFalse(iterable.anySatisfy(Predicates.greaterThan(<(literal.(type))("3")>))); Iterable iterable1 = this.classUnderTest(); int size = iterable1.size(); Assert.assertEquals(size > 3, iterable1.anySatisfy(Predicates.greaterThan(<(literal.(type))("3")>))); Assert.assertEquals(size != 0, iterable1.anySatisfy(Predicates.lessThan(<(literal.(type))("3")>))); } @Test public void allSatisfy() { Assert.assertFalse(this.newWith(<["1", "0", "2"]:(literal.(type))(); separator=", ">).allSatisfy(Predicates.greaterThan(<(literal.(type))("0")>))); Assert.assertTrue(this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">).allSatisfy(Predicates.greaterThan(<(literal.(type))("0")>))); Assert.assertFalse(this.newWith(<["1", "0", "31", "32"]:(literal.(type))(); separator=", ">).allSatisfy(Predicates.greaterThan(<(literal.(type))("0")>))); Assert.assertFalse(this.newWith(<["1", "0", "31", "32"]:(literal.(type))(); separator=", ">).allSatisfy(Predicates.greaterThan(<(literal.(type))("0")>))); Assert.assertTrue(this.newWith(<["1", "2", "31", "32"]:(literal.(type))(); separator=", ">).allSatisfy(Predicates.greaterThan(<(literal.(type))("0")>))); Assert.assertFalse(this.newWith(<["32"]:(literal.(type))(); separator=", ">).allSatisfy(Predicates.equal(<(literal.(type))("33")>))); Assert.assertFalse(this.newWith(<["-32"]:(literal.(type))(); separator=", ">).allSatisfy(Predicates.equal(<(literal.(type))("33")>))); Iterable iterable = this.newWith(<["0", "1", "2"]:(literal.(type))(); separator=", ">); Assert.assertFalse(iterable.allSatisfy(value -> <(lessThan.(type))({<(literal.(type))("3")>}, "value")>)); Assert.assertTrue(iterable.allSatisfy(Predicates.lessThan(<(literal.(type))("3")>))); Iterable iterable1 = this.classUnderTest(); int size = iterable1.size(); Assert.assertEquals(size == 0, iterable1.allSatisfy(Predicates.greaterThan(<(literal.(type))("3")>))); Assert.assertEquals(size \< 3, iterable1.allSatisfy(Predicates.lessThan(<(literal.(type))("3")>))); } @Test public void noneSatisfy() { Assert.assertFalse(this.newWith(<["1", "0", "2"]:(literal.(type))(); separator=", ">).noneSatisfy(Predicates.greaterThan(<(literal.(type))("0")>))); Assert.assertFalse(this.newWith(<["1", "0", "2"]:(literal.(type))(); separator=", ">).noneSatisfy(Predicates.equal(<(literal.(type))("0")>))); Assert.assertTrue(this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">).noneSatisfy(Predicates.greaterThan(<(literal.(type))("3")>))); Assert.assertFalse(this.newWith(<["1", "0", "31", "32"]:(literal.(type))(); separator=", ">).noneSatisfy(Predicates.greaterThan(<(literal.(type))("0")>))); Assert.assertFalse(this.newWith(<["1", "0", "31", "32"]:(literal.(type))(); separator=", ">).noneSatisfy(Predicates.greaterThan(<(literal.(type))("0")>))); Assert.assertTrue(this.newWith(<["1", "2", "31", "32"]:(literal.(type))(); separator=", ">).noneSatisfy(Predicates.lessThan(<(literal.(type))("0")>))); Assert.assertFalse(this.newWith(<["32"]:(literal.(type))(); separator=", ">).noneSatisfy(Predicates.greaterThan(<(literal.(type))("0")>))); Iterable iterable = this.newWith(<["0", "1", "2"]:(literal.(type))(); separator=", ">); Assert.assertFalse(iterable.noneSatisfy(value -> <(lessThan.(type))({<(literal.(type))("1")>}, "value")>)); Assert.assertTrue(iterable.noneSatisfy(Predicates.greaterThan(<(literal.(type))("3")>))); Iterable iterable1 = this.classUnderTest(); int size = iterable1.size(); Assert.assertEquals(size \<= 3, iterable1.noneSatisfy(Predicates.greaterThan(<(literal.(type))("3")>))); Assert.assertEquals(size == 0, iterable1.noneSatisfy(Predicates.lessThan(<(literal.(type))("3")>))); } @Test public void collect() { ToObjectFunction\<\> function = parameter -> <(castIntToNarrowTypeWithParens.(type))("parameter - 1")>; Assert.assertEquals(this.newObjectCollectionWith(<["0", "1", "2"]:(literal.(type))(); separator=", ">), this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">).collect(function)); Iterable iterable = this.newWith(<["1", "2", "2", "3", "3", "3"]:(literal.(type))(); separator=", ">); Assert.assertEquals(this.newObjectCollectionWith(<["0", "1", "1", "2", "2", "2"]:(literal.(type))(); separator=", ">), iterable.collect(function)); Assert.assertEquals(this.newObjectCollectionWith(), this.newWith().collect(function)); Assert.assertEquals(this.newObjectCollectionWith(<(literal.(type))("2")>), this.newWith(<(literal.(type))("3")>).collect(function)); } @Test public void collectWithTarget() { ToObjectFunction\<\> function = parameter -> <(castIntToNarrowTypeWithParens.(type))("parameter - 1")>; Assert.assertEquals(Bags.mutable.with(<["0", "1", "2"]:(literal.(type))(); separator=", ">), this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">).collect(function, Bags.mutable.empty())); Iterable iterable = this.newWith(<["1", "2", "2", "3", "3", "3"]:(literal.(type))(); separator=", ">); Assert.assertEquals(Sets.mutable.with(<["0", "1", "2"]:(literal.(type))(); separator=", ">), iterable.collect(function, Sets.mutable.empty())); Assert.assertEquals(Lists.mutable.empty(), this.newWith().collect(function, Lists.mutable.empty())); Assert.assertEquals(Lists.mutable.with(<(literal.(type))("2")>), this.newWith(<(literal.(type))("3")>).collect(function, Lists.mutable.empty())); } @Test public void flatCollectWithTarget() { ToObjectFunction\\>> function = parameter -> Lists.mutable.with(<(castIntToNarrowTypeWithParens.(type))("parameter - 1")>); Assert.assertEquals(Bags.mutable.with(<["0", "1", "2"]:(literal.(type))(); separator=", ">), this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">).flatCollect(function, Bags.mutable.empty())); Iterable iterable = this.newWith(<["1", "2", "2", "3", "3", "3"]:(literal.(type))(); separator=", ">); Assert.assertEquals(Sets.mutable.with(<["0", "1", "2"]:(literal.(type))(); separator=", ">), iterable.flatCollect(function, Sets.mutable.empty())); Assert.assertEquals(Lists.mutable.empty(), this.newWith().flatCollect(function, Lists.mutable.empty())); Assert.assertEquals(Lists.mutable.with(<(literal.(type))("2")>), this.newWith(<(literal.(type))("3")>).flatCollect(function, Lists.mutable.empty())); } @Test public void flatCollectIterableWithTarget() { ToObjectFunction\\>> function = parameter -> Lists.mutable.with(<(castIntToNarrowTypeWithParens.(type))("parameter - 1")>).asLazy(); Assert.assertEquals(Bags.mutable.with(<["0", "1", "2"]:(literal.(type))(); separator=", ">), this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">).flatCollect(function, Bags.mutable.empty())); Iterable iterable = this.newWith(<["1", "2", "2", "3", "3", "3"]:(literal.(type))(); separator=", ">); Assert.assertEquals(Sets.mutable.with(<["0", "1", "2"]:(literal.(type))(); separator=", ">), iterable.flatCollect(function, Sets.mutable.empty())); Assert.assertEquals(Lists.mutable.empty(), this.newWith().flatCollect(function, Lists.mutable.empty())); Assert.assertEquals(Lists.mutable.with(<(literal.(type))("2")>), this.newWith(<(literal.(type))("3")>).flatCollect(function, Lists.mutable.empty())); } @Test public void collectPrimitivesToLists() { Iterable iterable = this.newWith(<["1", "2"]:(literal.(type))(); separator=", ">); Assert.assertEquals( BooleanLists.mutable.with(true, true), iterable.collectBoolean(each -> true, BooleanLists.mutable.empty())); Assert.assertEquals( ByteLists.mutable.with((byte) 1, (byte) 1), iterable.collectByte(each -> (byte) 1, ByteLists.mutable.empty())); Assert.assertEquals( CharLists.mutable.with('a', 'a'), iterable.collectChar(each -> 'a', CharLists.mutable.empty())); Assert.assertEquals( ShortLists.mutable.with((short) 1, (short) 1), iterable.collectShort(each -> (short) 1, ShortLists.mutable.empty())); Assert.assertEquals( IntLists.mutable.with(1, 1), iterable.collectInt(each -> 1, IntLists.mutable.empty())); Assert.assertEquals( FloatLists.mutable.with(1.0f, 1.0f), iterable.collectFloat(each -> 1.0f, FloatLists.mutable.empty())); Assert.assertEquals( LongLists.mutable.with(1L, 1L), iterable.collectLong(each -> 1L, LongLists.mutable.empty())); Assert.assertEquals( DoubleLists.mutable.with(1.0d, 1.0d), iterable.collectDouble(each -> 1.0d, DoubleLists.mutable.empty())); } @Test public void collectPrimitivesToSets() { Iterable iterable = this.newWith(<["1", "2"]:(literal.(type))(); separator=", ">); Assert.assertEquals( BooleanSets.mutable.with(false), iterable.collectBoolean(each -> false, BooleanSets.mutable.empty())); Assert.assertEquals( ByteSets.mutable.with((byte) 2), iterable.collectByte(each -> (byte) 2, ByteSets.mutable.empty())); Assert.assertEquals( CharSets.mutable.with('b'), iterable.collectChar(each -> 'b', CharSets.mutable.empty())); Assert.assertEquals( ShortSets.mutable.with((short) 2), iterable.collectShort(each -> (short) 2, ShortSets.mutable.empty())); Assert.assertEquals( IntSets.mutable.with(2), iterable.collectInt(each -> 2, IntSets.mutable.empty())); Assert.assertEquals( FloatSets.mutable.with(2.0f), iterable.collectFloat(each -> 2.0f, FloatSets.mutable.empty())); Assert.assertEquals( LongSets.mutable.with(2L), iterable.collectLong(each -> 2L, LongSets.mutable.empty())); Assert.assertEquals( DoubleSets.mutable.with(2.0d), iterable.collectDouble(each -> 2.0d, DoubleSets.mutable.empty())); } @Test public void select() { Iterable iterable = this.classUnderTest(); int size = iterable.size(); Verify.assertSize(size >= 3 ? 3 : size, iterable.select(Predicates.lessThan(<(literal.(type))("4")>))); Verify.assertSize(size >= 2 ? 2 : size, iterable.select(Predicates.lessThan(<(literal.(type))("3")>))); Iterable iterable1 = this.newWith(<["0", "1", "2", "2", "3", "3", "3"]:(literal.(type))(); separator=", ">); Assert.assertEquals(this.newMutableCollectionWith(<["0", "1"]:(literal.(type))(); separator=", ">), iterable1.select(Predicates.lessThan(<(literal.(type))("2")>))); Assert.assertEquals(this.newMutableCollectionWith(<["2", "2", "3", "3", "3"]:(literal.(type))(); separator=", ">), iterable1.select(Predicates.greaterThan(<(literal.(type))("1")>))); Iterable iterable2 = this.newWith(<["0"]:(literal.(type))(); separator=", ">); Verify.assertSize(iterable2.size() == 1 ? 1 : 0, iterable2.select(Predicates.alwaysTrue())); Verify.assertSize(0, iterable2.select(Predicates.alwaysFalse())); } @Test public void selectWithTarget() { Iterable iterable = this.classUnderTest(); int size = iterable.size(); Verify.assertSize(size >= 3 ? 3 : size, iterable.select(Predicates.lessThan(<(literal.(type))("4")>), Sets.mutable.empty())); Verify.assertSize(size >= 2 ? 2 : size, iterable.select(Predicates.lessThan(<(literal.(type))("3")>), Sets.mutable.empty())); Iterable iterable1 = this.newWith(<["0", "1", "2", "2", "3", "3", "3"]:(literal.(type))(); separator=", ">); Assert.assertEquals(Sets.mutable.with(<["0", "1"]:(literal.(type))(); separator=", ">), iterable1.select(Predicates.lessThan(<(literal.(type))("2")>), Sets.mutable.empty())); Assert.assertEquals(Sets.mutable.with(<["2", "3"]:(literal.(type))(); separator=", ">), iterable1.select(Predicates.greaterThan(<(literal.(type))("1")>), Sets.mutable.empty())); } @Test public void reject() { Iterable iterable = this.classUnderTest(); int size = iterable.size(); Verify.assertSize(size \<= 3 ? 0 : size - 3, iterable.reject(Predicates.lessThan(<(literal.(type))("4")>))); Verify.assertSize(size \<= 2 ? 0 : size - 2, iterable.reject(Predicates.lessThan(<(literal.(type))("3")>))); Iterable iterable1 = this.newWith(<["0", "1", "2", "2", "3", "3", "3"]:(literal.(type))(); separator=", ">); Assert.assertEquals(this.newMutableCollectionWith(<["2", "2", "3", "3", "3"]:(literal.(type))(); separator=", ">), iterable1.reject(Predicates.lessThan(<(literal.(type))("2")>))); Assert.assertEquals(this.newMutableCollectionWith(<["0", "1"]:(literal.(type))(); separator=", ">), iterable1.reject(Predicates.greaterThan(<(literal.(type))("1")>))); Iterable iterable2 = this.newWith(<["0"]:(literal.(type))(); separator=", ">); Verify.assertSize(iterable2.size() == 1 ? 1 : 0, iterable2.reject(Predicates.alwaysFalse())); Verify.assertSize(0, iterable2.reject(Predicates.alwaysTrue())); } @Test public void rejectWithTarget() { Iterable iterable = this.classUnderTest(); int size = iterable.size(); Verify.assertSize(size \<= 3 ? 0 : size - 3, iterable.reject(Predicates.lessThan(<(literal.(type))("4")>), Sets.mutable.empty())); Verify.assertSize(size \<= 2 ? 0 : size - 2, iterable.reject(Predicates.lessThan(<(literal.(type))("3")>), Sets.mutable.empty())); Iterable iterable1 = this.newWith(<["0", "1", "2", "2", "3", "3", "3"]:(literal.(type))(); separator=", ">); Assert.assertEquals(Sets.mutable.with(<["2", "3"]:(literal.(type))(); separator=", ">), iterable1.reject(Predicates.lessThan(<(literal.(type))("2")>), Sets.mutable.empty())); Assert.assertEquals(Sets.mutable.with(<["0", "1"]:(literal.(type))(); separator=", ">), iterable1.reject(Predicates.greaterThan(<(literal.(type))("1")>), Sets.mutable.empty())); } @Test public void detectIfNone() { Iterable iterable = this.classUnderTest(); int size = iterable.size(); Assert.assertEquals(size >= 4 ? <(wideLiteral.(type))("4")> : <(wideLiteral.(type))("0")>, iterable.detectIfNone(Predicates.equal(<(literal.(type))("4")>), <(literal.(type))("0")>)<(wideDelta.(type))>); Assert.assertEquals(size >= 2 ? <(wideLiteral.(type))("2")> : <(wideLiteral.(type))("0")>, iterable.detectIfNone(Predicates.equal(<(literal.(type))("2")>), <(literal.(type))("0")>)<(wideDelta.(type))>); Assert.assertEquals(size > 0 ? <(wideLiteral.(type))("1")> : <(wideLiteral.(type))("0")>, iterable.detectIfNone(Predicates.lessThan(<(literal.(type))("2")>), <(literal.(type))("0")>)<(wideDelta.(type))>); Assert.assertEquals(size > 3 ? <(wideLiteral.(type))("4")> : <(wideLiteral.(type))("0")>, iterable.detectIfNone(Predicates.greaterThan(<(literal.(type))("3")>), <(literal.(type))("0")>)<(wideDelta.(type))>); Iterable iterable1 = this.newWith(<["0", "1", "2", "2", "3", "3", "3"]:(literal.(type))(); separator=", ">); Assert.assertEquals(<(wideLiteral.(type))("0")>, iterable1.detectIfNone(Predicates.lessThan(<(literal.(type))("1")>), <(literal.(type))("4")>)<(delta.(type))>); Assert.assertEquals(<(wideLiteral.(type))("3")>, iterable1.detectIfNone(Predicates.greaterThan(<(literal.(type))("2")>), <(literal.(type))("4")>)<(delta.(type))>); Assert.assertEquals(<(wideLiteral.(type))("4")>, iterable1.detectIfNone(Predicates.greaterThan(<(literal.(type))("4")>), <(literal.(type))("4")>)<(delta.(type))>); } @Test public void max() { <(maxTests.(type))(type, name)> } @Test(expected = NoSuchElementException.class) public void max_throws_emptyCollection() { this.newWith().max(); } @Test public void min() { <(minTests.(type))(type, name)> } @Test(expected = NoSuchElementException.class) public void min_throws_emptyCollection() { this.newWith().min(); } @Test public void minIfEmpty() { Assert.assertEquals(<(wideLiteral.(type))("5")>, this.newWith().minIfEmpty(<(literal.(type))("5")>)<(wideDelta.(type))>); Assert.assertEquals(<(wideLiteral.(type))("0")>, this.newWith().minIfEmpty(<(literal.(type))("0")>)<(wideDelta.(type))>); Assert.assertEquals(<(wideLiteral.(type))("0")>, this.newWith(<["1", "0", "9", "7"]:(literal.(type))(); separator=", ">).minIfEmpty(<(literal.(type))("5")>)<(wideDelta.(type))>); int size = this.classUnderTest().size(); Assert.assertEquals(size == 0 ? <(literal.(type))("5")> : <(literal.(type))("1")>, this.classUnderTest().minIfEmpty(<(literal.(type))("5")>)<(wideDelta.(type))>); } @Test public void maxIfEmpty() { Assert.assertEquals(<(wideLiteral.(type))("5")>, this.newWith().maxIfEmpty(<(literal.(type))("5")>)<(wideDelta.(type))>); Assert.assertEquals(<(wideLiteral.(type))("0")>, this.newWith().maxIfEmpty(<(literal.(type))("0")>)<(wideDelta.(type))>); Assert.assertEquals(<(wideLiteral.(type))("9")>, this.newWith(<["1", "0", "9", "7"]:(literal.(type))(); separator=", ">).maxIfEmpty(<(literal.(type))("5")>)<(wideDelta.(type))>); int size = this.classUnderTest().size(); Assert.assertEquals(size == 0 ? <(literal.(type))("5")> : size, this.classUnderTest().maxIfEmpty(<(literal.(type))("5")>)<(wideDelta.(type))>); } @Test public void sum() { int size = this.classUnderTest().size(); long sum = (long) ((size * (size + 1)) / 2); Assert.assertEquals(sum, this.classUnderTest().sum()<(wideDelta.(type))>); Assert.assertEquals(<(wideLiteral.(type))("10")>, this.newWith(<["0", "1", "2", "3", "4"]:(literal.(type))(); separator=", ">).sum()<(wideDelta.(type))>); Assert.assertEquals(<(wideLiteral.(type))("93")>, this.newWith(<["30", "31", "32"]:(literal.(type))(); separator=", ">).sum()); } @Test public void summaryStatistics() { int size = this.classUnderTest().size(); long sum = (long) ((size * (size + 1)) / 2); Assert.assertEquals(sum, this.classUnderTest().summaryStatistics().getSum()<(wideDelta.(type))>); Assert.assertEquals(<(wideLiteral.(type))("10")>, this.newWith(<["0", "1", "2", "3", "4"]:(literal.(type))(); separator=", ">).summaryStatistics().getSum()<(wideDelta.(type))>); Assert.assertEquals(<(wideLiteral.(type))("93")>, this.newWith(<["30", "31", "32"]:(literal.(type))(); separator=", ">).summaryStatistics().getSum()); } @Test public void sumConsistentRounding() { Iterable iterable = this.newWith(Interval.oneTo(100_000) .toList() .shuffleThis() .collect(i -> 1.0f / (i.floatValue() * i.floatValue() * i.floatValue() * i.floatValue())) .toArray()); // The test only ensures the consistency/stability of rounding. This is not meant to test the "correctness" of the float calculation result. // Indeed the lower bits of this calculation result are always incorrect due to the information loss of original float values. Assert.assertEquals( 1.082323233761663, iterable.sum(), 1.0e-15); } @Test public void sumConsistentRounding() { Iterable iterable = this.newWith(Interval.oneTo(100_000) .toList() .shuffleThis() .collect(i -> <["1.0"]:(decimalLiteral.(type))()> / (i.Value() * i.Value() * i.Value() * i.Value())) .toArray()); Assert.assertEquals( 1.082323233711138, iterable.sum(), 1.0e-15); } @Test public void average() { int size = this.classUnderTest().size(); long sum = (long) ((size * (size + 1)) / 2); double average = sum / size; Assert.assertEquals(average, this.classUnderTest().average(), 0.0); Assert.assertEquals(2.5, this.newWith(<["1", "2", "3", "4"]:(literal.(type))(); separator=", ">).average(), 0.0); Assert.assertEquals(2.5, this.newWith(<["1", "2", "3", "4"]:(literal.(type))(); separator=", ">).average(), 0.0); Assert.assertEquals(31.0, this.newWith(<["30", "30", "31", "31", "32", "32"]:(literal.(type))(); separator=", ">).average(), 0.0); } @Test(expected = ArithmeticException.class) public void averageThrowsOnEmpty() { this.newWith().average(); } /** * @since 9.0 */ @Test public void averageIfEmpty() { Assert.assertEquals(2.5, this.newWith().averageIfEmpty(2.5), 0.0); int size = this.classUnderTest().size(); long sum = (long) ((size * (size + 1)) / 2); double average = sum / size; Assert.assertEquals(average, this.classUnderTest().averageIfEmpty(0.0), 0.0); Assert.assertEquals(2.5, this.newWith(<["1", "2", "3", "4"]:(literal.(type))(); separator=", ">).averageIfEmpty(0.0), 0.0); Assert.assertEquals(2.5, this.newWith(<["1", "2", "3", "4"]:(literal.(type))(); separator=", ">).averageIfEmpty(0.0), 0.0); Assert.assertEquals(31.0, this.newWith(<["30", "30", "31", "31", "32", "32"]:(literal.(type))(); separator=", ">).averageIfEmpty(0.0), 0.0); } @Test public void median() { Assert.assertEquals(1.0, this.newWith(<["1"]:(literal.(type))(); separator=", ">).median(), 0.0); Assert.assertEquals(2.5, this.newWith(<["1", "2", "3", "4"]:(literal.(type))(); separator=", ">).median(), 0.0); Assert.assertEquals(3.0, this.newWith(<["1", "2", "3", "4", "5"]:(literal.(type))(); separator=", ">).median(), 0.0); Assert.assertEquals(31.0, this.newWith(<["30", "30", "31", "31", "32"]:(literal.(type))(); separator=", ">).median(), 0.0); Assert.assertEquals(30.5, this.newWith(<["1", "30", "30", "31", "31", "32"]:(literal.(type))(); separator=", ">).median(), 0.0); } @Test(expected = ArithmeticException.class) public void medianThrowsOnEmpty() { this.newWith().median(); } /** * @since 9.0 */ @Test public void medianIfEmpty() { Assert.assertEquals(2.5, this.newWith().medianIfEmpty(2.5), 0.0); Assert.assertEquals(1.0, this.newWith(<["1"]:(literal.(type))(); separator=", ">).medianIfEmpty(0.0), 0.0); Assert.assertEquals(2.5, this.newWith(<["1", "2", "3", "4"]:(literal.(type))(); separator=", ">).medianIfEmpty(0.0), 0.0); Assert.assertEquals(3.0, this.newWith(<["1", "2", "3", "4", "5"]:(literal.(type))(); separator=", ">).medianIfEmpty(0.0), 0.0); Assert.assertEquals(31.0, this.newWith(<["30", "30", "31", "31", "32"]:(literal.(type))(); separator=", ">).medianIfEmpty(0.0), 0.0); Assert.assertEquals(30.5, this.newWith(<["1", "30", "30", "31", "31", "32"]:(literal.(type))(); separator=", ">).medianIfEmpty(0.0), 0.0); } @Test public void toArray() { Assert.assertEquals(this.classUnderTest().size(), this.classUnderTest().toArray().length); Iterable iterable = this.newWith(<["1", "2"]:(literal.(type))(); separator=", ">); Assert.assertTrue(Arrays.equals(new []{<["1", "2"]:(literal.(type))(); separator=", ">}, iterable.toArray()) || Arrays.equals(new []{<["2", "1"]:(literal.(type))(); separator=", ">}, iterable.toArray())); Assert.assertTrue(Arrays.equals(new []{<["0", "1"]:(literal.(type))(); separator=", ">}, this.newWith(<["0", "1"]:(literal.(type))(); separator=", ">).toArray()) || Arrays.equals(new []{<["1", "0"]:(literal.(type))(); separator=", ">}, this.newWith(<["0", "1"]:(literal.(type))(); separator=", ">).toArray())); Assert.assertTrue(Arrays.equals(new []{<["1", "31"]:(literal.(type))(); separator=", ">}, this.newWith(<["1", "31"]:(literal.(type))(); separator=", ">).toArray()) || Arrays.equals(new []{<["31", "1"]:(literal.(type))(); separator=", ">}, this.newWith(<["1", "31"]:(literal.(type))(); separator=", ">).toArray())); Assert.assertTrue(Arrays.equals(new []{<["31", "35"]:(literal.(type))(); separator=", ">}, this.newWith(<["31", "35"]:(literal.(type))(); separator=", ">).toArray()) || Arrays.equals(new []{<["35", "31"]:(literal.(type))(); separator=", ">}, this.newWith(<["31", "35"]:(literal.(type))(); separator=", ">).toArray())); Assert.assertArrayEquals(new []{}, this.newWith().toArray()<(delta.(type))>); Assert.assertArrayEquals(new []{<(literal.(type))("32")>}, this.newWith(<(literal.(type))("32")>).toArray()<(delta.(type))>); } @Test public void toArrayWithTargetArray() { [] originalAsSortedArray = this.classUnderTest().toSortedArray(); [] target = new [this.classUnderTest().size()]; Assert.assertSame(target, this.classUnderTest().toArray(target)); Arrays.sort(target); Assert.assertTrue(Arrays.equals(originalAsSortedArray, target)); if (this.classUnderTest().size() > 0) { [] targetTooSmall = new [this.classUnderTest().size() - 1]; [] result = this.classUnderTest().toArray(targetTooSmall); Assert.assertNotSame(targetTooSmall, result); Arrays.sort(result); Assert.assertTrue(Arrays.equals(this.classUnderTest().toSortedArray(), result)); } [] targetTooBig = new [this.classUnderTest().size() + 1]; [] bigResult = this.classUnderTest().toArray(targetTooBig); Assert.assertSame(targetTooBig, bigResult); Arrays.sort(targetTooBig); for (int i = 0; i \< originalAsSortedArray.length; i++) { Assert.assertEquals(originalAsSortedArray[i], bigResult[i + 1]<(delta.(type))>); } } @Test public void toSortedArray() { Iterable iterable = this.classUnderTest(); int size = iterable.size(); [] array = new [size]; for (int i = 0; i \< size; i++) { array[i] = <(castIntToNarrowTypeWithParens.(type))("i + 1")>; } Assert.assertArrayEquals(array, iterable.toSortedArray()<(delta.(type))>); Assert.assertArrayEquals(new []{<["1", "3", "7", "9"]:(literal.(type))(); separator=", ">}, this.newWith(<["3", "1", "9", "7"]:(literal.(type))(); separator=", ">).toSortedArray()<(delta.(type))>); } @Test public void testEquals() { Iterable iterable1 = this.newWith(<["1", "2", "3", "4"]:(literal.(type))(); separator=", ">); Iterable iterable2 = this.newWith(<["1", "2", "3", "4"]:(literal.(type))(); separator=", ">); Iterable iterable3 = this.newWith(<["5", "6", "7", "8"]:(literal.(type))(); separator=", ">); Iterable iterable4 = this.newWith(<["5", "6", "7"]:(literal.(type))(); separator=", ">); Iterable iterable5 = this.newWith(<["0", "1", "1", "2", "2", "2"]:(literal.(type))(); separator=", ">); Iterable iterable6 = this.newWith(<["1", "31", "32"]:(literal.(type))(); separator=", ">); Iterable iterable7 = this.newWith(<["35", "31", "1"]:(literal.(type))(); separator=", ">); Iterable iterable8 = this.newWith(<["32", "31", "1", "50"]:(literal.(type))(); separator=", ">); Iterable iterable9 = this.newWith(<["0", "1", "2"]:(literal.(type))(); separator=", ">); Iterable iterable10 = this.newWith(<["0", "1", "3"]:(literal.(type))(); separator=", ">); Iterable iterable11 = this.newWith(<["3", "1", "2"]:(literal.(type))(); separator=", ">); Iterable iterable12 = this.newWith(<["3"]:(literal.(type))(); separator=", ">); Verify.assertEqualsAndHashCode(iterable1, iterable2); Verify.assertPostSerializedEqualsAndHashCode(iterable1); Verify.assertPostSerializedEqualsAndHashCode(iterable12); Verify.assertPostSerializedEqualsAndHashCode(iterable5); Verify.assertPostSerializedEqualsAndHashCode(iterable6); Assert.assertNotEquals(iterable12, iterable11); Assert.assertNotEquals(iterable1, iterable3); Assert.assertNotEquals(iterable1, iterable4); Assert.assertNotEquals(iterable6, iterable7); Assert.assertNotEquals(iterable6, iterable8); Assert.assertNotEquals(iterable9, iterable10); Assert.assertNotEquals(iterable9, iterable11); Assert.assertNotEquals(this.newWith(), this.newWith(<(literal.(type))("100")>)); } @Test public void testHashCode() { Assert.assertEquals(this.newObjectCollectionWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">).hashCode(), this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">).hashCode()); Assert.assertEquals(this.newObjectCollectionWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">).hashCode(), this.newWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">).hashCode()); Assert.assertEquals(this.newObjectCollectionWith(<["32"]:(literal.(type))(); separator=", ">).hashCode(), this.newWith(<["32"]:(literal.(type))(); separator=", ">).hashCode()); Assert.assertNotEquals(this.newObjectCollectionWith(<["32"]:(literal.(type))(); separator=", ">).hashCode(), this.newWith(<["0"]:(literal.(type))(); separator=", ">).hashCode()); Assert.assertEquals(this.newObjectCollectionWith(<["31", "32", "50"]:(literal.(type))(); separator=", ">).hashCode(), this.newWith(<["31", "32", "50"]:(literal.(type))(); separator=", ">).hashCode()); Assert.assertEquals(this.newObjectCollectionWith(<["32", "50", "60"]:(literal.(type))(); separator=", ">).hashCode(), this.newWith(<["32", "50", "60"]:(literal.(type))(); separator=", ">).hashCode()); Assert.assertEquals(this.newObjectCollectionWith().hashCode(), this.newWith().hashCode()); } @Test public void testToString() { Assert.assertEquals("[]", this.newWith().toString()); Assert.assertEquals("[<(toStringLiteral.(type))("1")>]", this.newWith(<(literal.(type))("1")>).toString()); Assert.assertEquals("[<(toStringLiteral.(type))("31")>]", this.newWith(<(literal.(type))("31")>).toString()); Assert.assertEquals("[<(toStringLiteral.(type))("32")>]", this.newWith(<(literal.(type))("32")>).toString()); Iterable iterable = this.newWith(<["1", "2"]:(literal.(type))(); separator=", ">); Assert.assertTrue("[<["1", "2"]:(toStringLiteral.(type))(); separator=", ">]".equals(iterable.toString()) || "[<["2", "1"]:(toStringLiteral.(type))(); separator=", ">]".equals(iterable.toString())); Iterable iterable1 = this.newWith(<["0", "31"]:(literal.(type))(); separator=", ">); Assert.assertTrue( iterable1.toString(), iterable1.toString().equals("[<["0", "31"]:(toStringLiteral.(type))(); separator=", ">]") || iterable1.toString().equals("[<["31", "0"]:(toStringLiteral.(type))(); separator=", ">]")); Iterable iterable2 = this.newWith(<["31", "32"]:(literal.(type))(); separator=", ">); Assert.assertTrue( iterable2.toString(), iterable2.toString().equals("[<["31", "32"]:(toStringLiteral.(type))(); separator=", ">]") || iterable2.toString().equals("[<["32", "31"]:(toStringLiteral.(type))(); separator=", ">]")); Iterable iterable3 = this.newWith(<["32", "33"]:(literal.(type))(); separator=", ">); Assert.assertTrue( iterable3.toString(), iterable3.toString().equals("[<["32", "33"]:(toStringLiteral.(type))(); separator=", ">]") || iterable3.toString().equals("[<["33", "32"]:(toStringLiteral.(type))(); separator=", ">]")); Iterable iterable4 = this.newWith(<["0", "1"]:(literal.(type))(); separator=", ">); Assert.assertTrue( iterable4.toString(), iterable4.toString().equals("[<["0", "1"]:(toStringLiteral.(type))(); separator=", ">]") || iterable4.toString().equals("[<["1", "0"]:(toStringLiteral.(type))(); separator=", ">]")); } @Test public void makeString() { Iterable iterable = this.classUnderTest(); Assert.assertEquals("<(toStringLiteral.(type))("1")>", this.newWith(<(literal.(type))("1")>).makeString("/")); Assert.assertEquals("<(toStringLiteral.(type))("31")>", this.newWith(<(literal.(type))("31")>).makeString()); Assert.assertEquals("<(toStringLiteral.(type))("32")>", this.newWith(<(literal.(type))("32")>).makeString()); Assert.assertEquals(iterable.toString(), iterable.makeString("[", ", ", "]")); Assert.assertEquals("", this.newWith().makeString()); Assert.assertEquals("", this.newWith().makeString("/")); Assert.assertEquals("[]", this.newWith().makeString("[", ", ", "]")); Iterable iterable1 = this.newWith(<["0", "31"]:(literal.(type))(); separator=", ">); Assert.assertTrue( iterable1.makeString(), iterable1.makeString().equals("<["0", "31"]:(toStringLiteral.(type))(); separator=", ">") || iterable1.makeString().equals("<["31", "0"]:(toStringLiteral.(type))(); separator=", ">")); Iterable iterable2 = this.newWith(<["31", "32"]:(literal.(type))(); separator=", ">); Assert.assertTrue( iterable2.makeString("[", "/", "]"), iterable2.makeString("[", "/", "]").equals("[<["31", "32"]:(toStringLiteral.(type))(); separator="/">]") || iterable2.makeString("[", "/", "]").equals("[<["32", "31"]:(toStringLiteral.(type))(); separator="/">]")); Iterable iterable3 = this.newWith(<["32", "33"]:(literal.(type))(); separator=", ">); Assert.assertTrue( iterable3.makeString("/"), iterable3.makeString("/").equals("<["32", "33"]:(toStringLiteral.(type))(); separator="/">") || iterable3.makeString("/").equals("<["33", "32"]:(toStringLiteral.(type))(); separator="/">")); Iterable iterable4 = this.newWith(<["1", "2"]:(literal.(type))(); separator=", ">); Assert.assertTrue("<["1", "2"]:(toStringLiteral.(type))(); separator=", ">".equals(iterable4.makeString()) || "<["2", "1"]:(toStringLiteral.(type))(); separator=", ">".equals(iterable4.makeString())); Assert.assertTrue("<["1", "2"]:(toStringLiteral.(type))(); separator="/">".equals(iterable4.makeString("/")) || "<["2", "1"]:(toStringLiteral.(type))(); separator="/">".equals(iterable4.makeString("/"))); Assert.assertTrue("[<["1", "2"]:(toStringLiteral.(type))(); separator="/">]".equals(iterable4.makeString("[", "/", "]")) || "[<["2", "1"]:(toStringLiteral.(type))(); separator="/">]".equals(iterable4.makeString("[", "/", "]"))); Iterable iterable5 = this.newWith(<["0", "1"]:(literal.(type))(); separator=", ">); Assert.assertTrue( iterable5.makeString(), iterable5.makeString().equals("<["0", "1"]:(toStringLiteral.(type))(); separator=", ">") || iterable5.makeString().equals("<["1", "0"]:(toStringLiteral.(type))(); separator=", ">")); Assert.assertTrue( iterable5.makeString("[", "/", "]"), iterable5.makeString("[", "/", "]").equals("[<["0", "1"]:(toStringLiteral.(type))(); separator="/">]") || iterable5.makeString("[", "/", "]").equals("[<["1", "0"]:(toStringLiteral.(type))(); separator="/">]")); Assert.assertTrue( iterable5.makeString("/"), iterable5.makeString("/").equals("<["0", "1"]:(toStringLiteral.(type))(); separator="/">") || iterable5.makeString("/").equals("<["1", "0"]:(toStringLiteral.(type))(); separator="/">")); } @Test public void appendString() { StringBuilder appendable = new StringBuilder(); this.newWith().appendString(appendable); Assert.assertEquals("", appendable.toString()); this.newWith().appendString(appendable, "/"); Assert.assertEquals("", appendable.toString()); this.newWith().appendString(appendable, "[", ", ", "]"); Assert.assertEquals("[]", appendable.toString()); StringBuilder appendable1 = new StringBuilder(); this.newWith(<(literal.(type))("1")>).appendString(appendable1); Assert.assertEquals("<(toStringLiteral.(type))("1")>", appendable1.toString()); StringBuilder appendable2 = new StringBuilder(); Iterable iterable = this.newWith(<["1", "2"]:(literal.(type))(); separator=", ">); iterable.appendString(appendable2); Assert.assertTrue("<["1", "2"]:(toStringLiteral.(type))(); separator=", ">".equals(appendable2.toString()) || "<["2", "1"]:(toStringLiteral.(type))(); separator=", ">".equals(appendable2.toString())); StringBuilder appendable3 = new StringBuilder(); iterable.appendString(appendable3, "/"); Assert.assertTrue("<["1", "2"]:(toStringLiteral.(type))(); separator="/">".equals(appendable3.toString()) || "<["2", "1"]:(toStringLiteral.(type))(); separator="/">".equals(appendable3.toString())); StringBuilder appendable4 = new StringBuilder(); iterable.appendString(appendable4, "[", ", ", "]"); Assert.assertEquals(iterable.toString(), appendable4.toString()); StringBuilder appendable5 = new StringBuilder(); this.newWith(<(literal.(type))("31")>).appendString(appendable5); Assert.assertEquals("<(toStringLiteral.(type))("31")>", appendable5.toString()); StringBuilder appendable6 = new StringBuilder(); this.newWith(<(literal.(type))("32")>).appendString(appendable6); Assert.assertEquals("<(toStringLiteral.(type))("32")>", appendable6.toString()); StringBuilder appendable7 = new StringBuilder(); Iterable iterable1 = this.newWith(<["0", "31"]:(literal.(type))(); separator=", ">); iterable1.appendString(appendable7); Assert.assertTrue(appendable7.toString(), "<["0", "31"]:(toStringLiteral.(type))(); separator=", ">".equals(appendable7.toString()) || "<["31", "0"]:(toStringLiteral.(type))(); separator=", ">".equals(appendable7.toString())); StringBuilder appendable8 = new StringBuilder(); Iterable iterable2 = this.newWith(<["31", "32"]:(literal.(type))(); separator=", ">); iterable2.appendString(appendable8, "/"); Assert.assertTrue(appendable8.toString(), "<["31", "32"]:(toStringLiteral.(type))(); separator="/">".equals(appendable8.toString()) || "<["32", "31"]:(toStringLiteral.(type))(); separator="/">".equals(appendable8.toString())); StringBuilder appendable9 = new StringBuilder(); Iterable iterable4 = this.newWith(<["32", "33"]:(literal.(type))(); separator=", ">); iterable4.appendString(appendable9, "[", "/", "]"); Assert.assertTrue(appendable9.toString(), "[<["32", "33"]:(toStringLiteral.(type))(); separator="/">]".equals(appendable9.toString()) || "[<["33", "32"]:(toStringLiteral.(type))(); separator="/">]".equals(appendable9.toString())); StringBuilder appendable10 = new StringBuilder(); Iterable iterable5 = this.newWith(<["0", "1"]:(literal.(type))(); separator=", ">); iterable5.appendString(appendable10); Assert.assertTrue(appendable10.toString(), "<["0", "1"]:(toStringLiteral.(type))(); separator=", ">".equals(appendable10.toString()) || "<["1", "0"]:(toStringLiteral.(type))(); separator=", ">".equals(appendable10.toString())); StringBuilder appendable11 = new StringBuilder(); iterable5.appendString(appendable11, "/"); Assert.assertTrue(appendable11.toString(), "<["0", "1"]:(toStringLiteral.(type))(); separator="/">".equals(appendable11.toString()) || "<["1", "0"]:(toStringLiteral.(type))(); separator="/">".equals(appendable11.toString())); StringBuilder appendable12 = new StringBuilder(); iterable5.appendString(appendable12, "[", "/", "]"); Assert.assertTrue(appendable12.toString(), "[<["0", "1"]:(toStringLiteral.(type))(); separator="/">]".equals(appendable12.toString()) || "[<["1", "0"]:(toStringLiteral.(type))(); separator="/">]".equals(appendable12.toString())); } @Test public void toList() { Iterable iterable = this.newWith(<["31", "32"]:(literal.(type))(); separator=", ">); Assert.assertTrue(ArrayList.newListWith(<["31", "32"]:(literal.(type))(); separator=", ">).equals(iterable.toList()) || ArrayList.newListWith(<["32", "31"]:(literal.(type))(); separator=", ">).equals(iterable.toList())); Assert.assertEquals(ArrayList.newListWith(<(literal.(type))("0")>), this.newWith(<(literal.(type))("0")>).toList()); Assert.assertEquals(ArrayList.newListWith(<(literal.(type))("31")>), this.newWith(<(literal.(type))("31")>).toList()); Assert.assertEquals(ArrayList.newListWith(<(literal.(type))("32")>), this.newWith(<(literal.(type))("32")>).toList()); Assert.assertEquals(new ArrayList(), this.newWith().toList()); } @Test public void toSortedList() { Assert.assertEquals(ArrayList.newListWith(), this.newWith().toSortedList()); Assert.assertEquals(ArrayList.newListWith(<(literal.(type))("1")>), this.newWith(<(literal.(type))("1")>).toSortedList()); Assert.assertEquals(ArrayList.newListWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">), this.newWith(<["0", "31", "1"]:(literal.(type))(); separator=", ">).toSortedList()); Assert.assertEquals(ArrayList.newListWith(<["0", "1", "31", "32"]:(literal.(type))(); separator=", ">), this.newWith(<["0", "31", "32", "1"]:(literal.(type))(); separator=", ">).toSortedList()); } @Test public void toSortedListByComparator() { Iterable iterable = this.newWith(<["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]:(literal.(type))(); separator=", ">); MutableList result = iterable.toSortedList((a, b) -> (int) ((int) ((int) a & 1) - ((int) b & 1))); // odd/even comparator Assert.assertNotSame(iterable, result); result .collectBoolean(e -> e % 2 == 0, BooleanLists.mutable.of()) .forEachWithIndex((e, i) -> Assert.assertEquals("index " + i, i \< 5, e)); } @Test public void toSortedListByFunctionNaturalOrder() { MutableList\ list = Lists.mutable.of("Foo", "Bar", "Baz", "Waldo", "Qux"); Iterable index = this.newMutableCollectionWith(<["0", "1", "2", "3", "4"]:(literal.(type))(); separator=", ">); MutableList result = index.toSortedListBy(i -> list.get((int) i)); Assert.assertNotSame(index, result); Assert.assertEquals(ArrayList.newListWith(<["1", "2", "0", "4", "3"]:(literal.(type))(); separator=", ">), result); } @Test public void toSortedListByFunctionWithComparator() { MutableList\ list = Lists.mutable.of("Foo", "Bar", "Baz", "Waldo", "Qux"); Iterable index = this.newMutableCollectionWith(<["0", "1", "2", "3", "4"]:(literal.(type))(); separator=", ">); MutableList result = index.toSortedListBy(i -> list.get((int) i), Comparators.naturalOrder().reversed()); Assert.assertNotSame(index, result); Assert.assertEquals(ArrayList.newListWith(<["3", "4", "0", "2", "1"]:(literal.(type))(); separator=", ">), result); } @Test public void toSet() { Assert.assertEquals(HashSet.newSetWith(), this.newWith().toSet()); Assert.assertEquals(HashSet.newSetWith(<["1"]:(literal.(type))(); separator=", ">), this.newWith(<(literal.(type))("1")>).toSet()); Assert.assertEquals(HashSet.newSetWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">), this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">).toSet()); Assert.assertEquals(HashSet.newSetWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">), this.newWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">).toSet()); Assert.assertEquals(HashSet.newSetWith(<["0", "1", "31", "32"]:(literal.(type))(); separator=", ">), this.newWith(<["0", "1", "31", "32"]:(literal.(type))(); separator=", ">).toSet()); Assert.assertEquals(HashSet.newSetWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">), this.newWith(<["1", "2", "2", "3", "3", "3"]:(literal.(type))(); separator=", ">).toSet()); } @Test public void toBag() { Assert.assertEquals(new HashBag(), this.newWith().toBag()); Assert.assertEquals(HashBag.newBagWith(<["1"]:(literal.(type))(); separator=", ">), this.newWith(<(literal.(type))("1")>).toBag()); Assert.assertEquals(HashBag.newBagWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">), this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">).toBag()); Assert.assertEquals(HashBag.newBagWith(<["1", "2", "2", "3", "3", "3"]:(literal.(type))(); separator=", ">), this.newWith(<["1", "2", "2", "3", "3", "3"]:(literal.(type))(); separator=", ">).toBag()); Assert.assertEquals(HashBag.newBagWith(<["0", "1", "31", "32"]:(literal.(type))(); separator=", ">), this.newWith(<["0", "1", "31", "32"]:(literal.(type))(); separator=", ">).toBag()); } @Test public void asLazy() { Iterable iterable = this.classUnderTest(); Assert.assertEquals(iterable.toBag(), iterable.asLazy().toBag()); Verify.assertInstanceOf(LazyIterable.class, iterable.asLazy()); Iterable iterable1 = this.newWith(<["1", "2", "2", "3", "3", "3"]:(literal.(type))(); separator=", ">); Assert.assertEquals(iterable1.toBag(), iterable1.asLazy().toBag()); Verify.assertInstanceOf(LazyIterable.class, iterable1.asLazy()); Iterable iterable2 = this.newWith(<["1", "2", "2", "3", "3", "3"]:(literal.(type))(); separator=", ">); Assert.assertEquals(iterable2.toBag(), iterable2.asLazy().toBag()); Verify.assertInstanceOf(LazyIterable.class, iterable2.asLazy()); Iterable iterable3 = this.newWith(); Assert.assertEquals(iterable3.toBag(), iterable3.asLazy().toBag()); Verify.assertInstanceOf(LazyIterable.class, iterable3.asLazy()); Iterable iterable4 = this.newWith(<["1"]:(literal.(type))(); separator=", ">); Assert.assertEquals(iterable4.toBag(), iterable4.asLazy().toBag()); Verify.assertInstanceOf(LazyIterable.class, iterable4.asLazy()); } @Test public void injectInto() { Iterable iterable1 = this.newWith(<["0", "2", "31"]:(literal.(type))(); separator=", ">); sum1 = iterable1.injectInto(.valueOf(<(literal.(type))("0")>), ( result, value) -> .valueOf(() (result + value + 1))); Assert.assertEquals(.valueOf(<(literal.(type))("36")>), sum1); Iterable iterable2 = this.newWith(<[ "1", "2", "31"]:(literal.(type))(); separator=", ">); sum2 = iterable2.injectInto(.valueOf(<(literal.(type))("0")>), ( result, value) -> .valueOf(() (result + value + 1))); Assert.assertEquals(.valueOf(<(literal.(type))("37")>), sum2); Iterable iterable3 = this.newWith(<["0", "1", "2", "31"]:(literal.(type))(); separator=", ">); sum3 = iterable3.injectInto(.valueOf(<(literal.(type))("0")>), ( result, value) -> .valueOf(() (result + value + 1))); Assert.assertEquals(.valueOf(<(literal.(type))("38")>), sum3); } @Test public void injectIntoBoolean() { Iterable iterable1 = this.newWith(<["0", "2", "31"]:(literal.(type))(); separator=", ">); boolean sum1 = iterable1.injectIntoBoolean(false, (boolean result, value) -> (boolean) (result || value == <(literal.(type))("0")>)); Assert.assertEquals(true, sum1); Iterable iterable2 = this.newWith(<[ "1", "2", "31"]:(literal.(type))(); separator=", ">); boolean sum2 = iterable2.injectIntoBoolean(false, (boolean result, value) -> (boolean) (result || value == <(literal.(type))("0")>)); Assert.assertEquals(false, sum2); } @Test(expected = NoSuchElementException.class) public void reduceOnEmptyThrows() { this.newWith().reduce((<(wideType.(type))> result, value) -> <(castWideType.(type))>result + <(castWideType.(type))>value + <(wideLiteral.(type))("1")>); } @Test public void reduce() { Iterable iterable1 = this.newWith(<["0", "2", "31"]:(literal.(type))(); separator=", ">); <(wideType.(type))> sum1 = iterable1.reduce((<(wideType.(type))> result, value) -> <(castWideType.(type))>result + <(castWideType.(type))>value + <(wideLiteral.(type))("1")>); Assert.assertEquals(<(wideLiteral.(type))("35")>, sum1, 0.001); Iterable iterable2 = this.newWith(<[ "1", "2", "31"]:(literal.(type))(); separator=", ">); <(wideType.(type))> sum2 = iterable2.reduce((<(wideType.(type))> result, value) -> <(castWideType.(type))>result + <(castWideType.(type))>value + <(wideLiteral.(type))("1")>); Assert.assertEquals(<(wideLiteral.(type))("36")>, sum2, 0.001); Iterable iterable3 = this.newWith(<["0", "1", "2", "31"]:(literal.(type))(); separator=", ">); <(wideType.(type))> sum3 = iterable3.reduce((<(wideType.(type))> result, value) -> <(castWideType.(type))>result + <(castWideType.(type))>value + <(wideLiteral.(type))("1")>); Assert.assertEquals(<(wideLiteral.(type))("37")>, sum3, 0.001); } @Test public void reduceIfEmpty() { <(wideType.(type))> empty1 = this.newWith().reduceIfEmpty((<(wideType.(type))> result, value) -> <(castWideType.(type))>result + <(castWideType.(type))>value + <(wideLiteral.(type))("1")>, <(wideLiteral.(type))("1")>); Assert.assertEquals(<(wideLiteral.(type))("1")>, empty1, 0.001); <(wideType.(type))> empty2 = this.newWith().reduceIfEmpty((<(wideType.(type))> result, value) -> <(castWideType.(type))>result + <(castWideType.(type))>value + <(wideLiteral.(type))("1")>, <(wideLiteral.(type))("0")>); Assert.assertEquals(<(wideLiteral.(type))("0")>, empty2, 0.001); Iterable iterable1 = this.newWith(<["0", "2", "31"]:(literal.(type))(); separator=", ">); <(wideType.(type))> sum1 = iterable1.reduceIfEmpty((<(wideType.(type))> result, value) -> <(castWideType.(type))>result + <(castWideType.(type))>value + <(wideLiteral.(type))("1")>, <(wideLiteral.(type))("0")>); Assert.assertEquals(<(wideLiteral.(type))("35")>, sum1, 0.001); Iterable iterable2 = this.newWith(<[ "1", "2", "31"]:(literal.(type))(); separator=", ">); <(wideType.(type))> sum2 = iterable2.reduceIfEmpty((<(wideType.(type))> result, value) -> <(castWideType.(type))>result + <(castWideType.(type))>value + <(wideLiteral.(type))("1")>, <(wideLiteral.(type))("0")>); Assert.assertEquals(<(wideLiteral.(type))("36")>, sum2, 0.001); Iterable iterable3 = this.newWith(<["0", "1", "2", "31"]:(literal.(type))(); separator=", ">); <(wideType.(type))> sum3 = iterable3.reduceIfEmpty((<(wideType.(type))> result, value) -> <(castWideType.(type))>result + <(castWideType.(type))>value + <(wideLiteral.(type))("1")>, <(wideLiteral.(type))("0")>); Assert.assertEquals(<(wideLiteral.(type))("37")>, sum3, 0.001); } @Test public void chunk() { Iterable iterable = this.newWith(<["0", "1", "2", "3", "4", "5"]:(literal.(type))(); separator=", ">); Assert.assertEquals( Lists.mutable.with( this.newMutableCollectionWith(<["0"]:(literal.(type))(); separator=", ">), this.newMutableCollectionWith(<["1"]:(literal.(type))(); separator=", ">), this.newMutableCollectionWith(<["2"]:(literal.(type))(); separator=", ">), this.newMutableCollectionWith(<["3"]:(literal.(type))(); separator=", ">), this.newMutableCollectionWith(<["4"]:(literal.(type))(); separator=", ">), this.newMutableCollectionWith(<["5"]:(literal.(type))(); separator=", ">)).toSet(), iterable.chunk(1).toSet()); Assert.assertEquals( Lists.mutable.with( this.newMutableCollectionWith(<["0", "1"]:(literal.(type))(); separator=", ">), this.newMutableCollectionWith(<["2", "3"]:(literal.(type))(); separator=", ">), this.newMutableCollectionWith(<["4", "5"]:(literal.(type))(); separator=", ">)).toSet(), iterable.chunk(2).toSet()); Assert.assertEquals( Lists.mutable.with( this.newMutableCollectionWith(<["0", "1", "2"]:(literal.(type))(); separator=", ">), this.newMutableCollectionWith(<["3", "4", "5"]:(literal.(type))(); separator=", ">)).toSet(), iterable.chunk(3).toSet()); Assert.assertEquals( Lists.mutable.with( this.newMutableCollectionWith(<["0", "1", "2", "3"]:(literal.(type))(); separator=", ">), this.newMutableCollectionWith(<["4", "5"]:(literal.(type))(); separator=", ">)).toSet(), iterable.chunk(4).toSet()); Assert.assertEquals( Lists.mutable.with(this.newMutableCollectionWith(<["0", "1", "2", "3", "4", "5"]:(literal.(type))(); separator=", ">)).toSet(), iterable.chunk(6).toSet()); Assert.assertEquals( Lists.mutable.with(this.newMutableCollectionWith(<["0", "1", "2", "3", "4", "5"]:(literal.(type))(); separator=", ">)).toSet(), iterable.chunk(7).toSet()); Assert.assertEquals(Lists.mutable.with(), this.newWith().chunk(1)); Assert.assertEquals(Lists.mutable.with(this.newMutableCollectionWith(<["0"]:(literal.(type))(); separator=", ">)), this.newWith(<["0"]:(literal.(type))(); separator=", ">).chunk(1)); Assert.assertEquals(Lists.mutable.with(), this.newWith().chunk(1)); Assert.assertThrows(IllegalArgumentException.class, () -> iterable.chunk(0)); Assert.assertThrows(IllegalArgumentException.class, () -> iterable.chunk(-1)); Assert.assertThrows(IllegalArgumentException.class, () -> this.newMutableCollectionWith().chunk(-1)); } } >> kahanSumTests ::= [ "float": "kahanFloatSumTest", "double": "kahanDoubleSumTest", "default": "noTest" ] kahanFloatSumTest() ::= << >> kahanDoubleSumTest() ::= << >> noTest() ::= "" maxTests ::= [ "byte": "intMaxTest", "short": "intMaxTest", "char": "charMaxTest", "int": "intMaxTest", "long": "intMaxTest", "float": "floatMaxTest", "double": "floatMaxTest" ] intMaxTest(type, name) ::= << Assert.assertEquals(<(wideLiteral.(type))("9")>, this.newWith(<["-1", "-2", "9"]:(literal.(type))(); separator=", ">).max()<(wideDelta.(type))>); Assert.assertEquals(<(wideLiteral.(type))("-1")>, this.newWith(<["-1", "-2", "-9"]:(literal.(type))(); separator=", ">).max()<(wideDelta.(type))>); Assert.assertEquals(<(wideLiteral.(type))("32")>, this.newWith(<["1", "0", "9", "30", "31", "32"]:(literal.(type))(); separator=", ">).max()<(wideDelta.(type))>); Assert.assertEquals(<(wideLiteral.(type))("32")>, this.newWith(<["-1", "0", "9", "30", "31", "32"]:(literal.(type))(); separator=", ">).max()<(wideDelta.(type))>); Assert.assertEquals(<(wideLiteral.(type))("31")>, this.newWith(<["31", "0", "30"]:(literal.(type))(); separator=", ">).max()<(wideDelta.(type))>); Assert.assertEquals(<(wideLiteral.(type))("39")>, this.newWith(<["32", "39", "35"]:(literal.(type))(); separator=", ">).max()<(wideDelta.(type))>); Assert.assertEquals(this.classUnderTest().size(), this.classUnderTest().max()<(delta.(type))>); >> charMaxTest(type, name) ::= << Assert.assertEquals(<(literal.(type))("-1")>, this.newWith(<["-1", "-2", "9"]:(literal.(type))(); separator=", ">).max()<(wideDelta.(type))>); Assert.assertEquals(<(literal.(type))("32")>, this.newWith(<["1", "0", "9", "30", "31", "32"]:(literal.(type))(); separator=", ">).max()<(wideDelta.(type))>); Assert.assertEquals(<(literal.(type))("-1")>, this.newWith(<["-1", "0", "9", "30", "31", "32"]:(literal.(type))(); separator=", ">).max()<(wideDelta.(type))>); Assert.assertEquals(<(literal.(type))("31")>, this.newWith(<["31", "0", "30"]:(literal.(type))(); separator=", ">).max()<(wideDelta.(type))>); Assert.assertEquals(<(literal.(type))("39")>, this.newWith(<["32", "39", "35"]:(literal.(type))(); separator=", ">).max()<(wideDelta.(type))>); Assert.assertEquals(this.classUnderTest().size(), this.classUnderTest().max()<(wideDelta.(type))>); >> floatMaxTest(type, name) ::= << Assert.assertEquals(32.5, this.newWith(<["-1.5", "31.8", "32.5"]:(decimalLiteral.(type))(); separator=", ">).max()<(wideDelta.(type))>); Assert.assertEquals(-1.5, this.newWith(<["-1.5", "-31.8", "-32.5"]:(decimalLiteral.(type))(); separator=", ">).max()<(wideDelta.(type))>); Assert.assertEquals(.POSITIVE_INFINITY, this.newWith(<["-1.5", "31.8", "32.5"]:(decimalLiteral.(type))(); separator=", ">, .POSITIVE_INFINITY).max()<(wideDelta.(type))>); Assert.assertEquals(.NaN, this.newWith(<["-1.5", "31.8", "32.5"]:(decimalLiteral.(type))(); separator=", ">, .NaN, 31.5f).max()<(wideDelta.(type))>); Assert.assertEquals(32.5, this.newWith(<["-1.5", "31.8", "32.5"]:(decimalLiteral.(type))(); separator=", ">, .NEGATIVE_INFINITY, 31.5f).max()<(wideDelta.(type))>); >> minTests ::= [ "byte": "intMinTest", "short": "intMinTest", "char": "charMinTest", "int": "intMinTest", "long": "intMinTest", "float": "floatMinTest", "double": "floatMinTest" ] intMinTest(type, name) ::= << Assert.assertEquals(<(wideLiteral.(type))("-2")>, this.newWith(<["-1", "-2", "9"]:(literal.(type))(); separator=", ">).min()<(wideDelta.(type))>); Assert.assertEquals(<(wideLiteral.(type))("0")>, this.newWith(<["1", "0", "9", "30", "31", "32"]:(literal.(type))(); separator=", ">).min()<(wideDelta.(type))>); Assert.assertEquals(<(wideLiteral.(type))("-1")>, this.newWith(<["-1", "0", "9", "30", "31", "32"]:(literal.(type))(); separator=", ">).min()<(wideDelta.(type))>); Assert.assertEquals(<(wideLiteral.(type))("31")>, this.newWith(<["31", "32", "33"]:(literal.(type))(); separator=", ">).min()<(wideDelta.(type))>); Assert.assertEquals(<(wideLiteral.(type))("32")>, this.newWith(<["32", "39", "35"]:(literal.(type))(); separator=", ">).min()<(wideDelta.(type))>); Assert.assertEquals(<(wideLiteral.(type))("1")>, this.classUnderTest().min()<(wideDelta.(type))>); >> charMinTest(type, name) ::= << Assert.assertEquals(<(wideLiteral.(type))("9")>, this.newWith(<["-1", "-2", "9"]:(literal.(type))(); separator=", ">).min()<(wideDelta.(type))>); Assert.assertEquals(<(wideLiteral.(type))("0")>, this.newWith(<["1", "0", "9", "30", "31", "32"]:(literal.(type))(); separator=", ">).min()<(wideDelta.(type))>); Assert.assertEquals(<(wideLiteral.(type))("0")>, this.newWith(<["-1", "0", "9", "30", "31", "32"]:(literal.(type))(); separator=", ">).min()<(wideDelta.(type))>); Assert.assertEquals(<(wideLiteral.(type))("31")>, this.newWith(<["31", "32", "33"]:(literal.(type))(); separator=", ">).min()<(wideDelta.(type))>); Assert.assertEquals(<(wideLiteral.(type))("32")>, this.newWith(<["32", "39", "35"]:(literal.(type))(); separator=", ">).min()<(wideDelta.(type))>); Assert.assertEquals(<(wideLiteral.(type))("1")>, this.classUnderTest().min()<(wideDelta.(type))>); >> floatMinTest(type, name) ::= << Assert.assertEquals(-1.5, this.newWith(<["-1.5", "31.5", "32.5"]:(decimalLiteral.(type))(); separator=", ">).min()<(wideDelta.(type))>); Assert.assertEquals(1.5, this.newWith(<["1.5", "31.0", "30.0"]:(decimalLiteral.(type))(); separator=", ">, .POSITIVE_INFINITY).min()<(wideDelta.(type))>); Assert.assertEquals(31.5, this.newWith(<["31.5", "32.5"]:(decimalLiteral.(type))(); separator=", ">, .NaN).min()<(wideDelta.(type))>); Assert.assertEquals(.NEGATIVE_INFINITY, this.newWith(<["-1.5", "31.5", "32.5"]:(decimalLiteral.(type))(); separator=", ">, .NEGATIVE_INFINITY, 31.5f).min()<(wideDelta.(type))>); >> NaNTests(key) ::= << @Test public void contains_() { Iterable primitiveIterable = this.newWith(.); Set\<\> hashSet = new HashSet\<>(); Assert.assertTrue(hashSet.add(.)); Assert.assertTrue(hashSet.contains(.)); Assert.assertTrue(primitiveIterable.contains(.)); } >> NaNEqualsTests() ::= << @Test public void testEquals_NaN() { Iterable iterable1 = this.newWith(.NaN); Set\<\> hashSet1 = new HashSet\<>(); hashSet1.add(.NaN); Iterable iterable2 = this.newWith(.NaN); Set\<\> hashSet2 = new HashSet\<>(); hashSet2.add(.NaN); Iterable iterable3 = this.newWith(.POSITIVE_INFINITY); Set\<\> hashSet3 = new HashSet\<>(); hashSet3.add(.POSITIVE_INFINITY); Iterable iterable4 = this.newWith(.POSITIVE_INFINITY); Set\<\> hashSet4 = new HashSet\<>(); hashSet4.add(.POSITIVE_INFINITY); Iterable iterable5 = this.newWith(.NEGATIVE_INFINITY); Set\<\> hashSet5 = new HashSet\<>(); hashSet5.add(.NEGATIVE_INFINITY); Iterable iterable6 = this.newWith(.NEGATIVE_INFINITY); Set\<\> hashSet6 = new HashSet\<>(); hashSet6.add(.NEGATIVE_INFINITY); Assert.assertEquals(hashSet1, hashSet2); Assert.assertEquals(iterable1, iterable2); Assert.assertEquals(hashSet3, hashSet4); Assert.assertEquals(iterable3, iterable4); Assert.assertEquals(hashSet5, hashSet6); Assert.assertEquals(iterable5, iterable6); Assert.assertNotEquals(hashSet1, hashSet3); Assert.assertNotEquals(iterable1, iterable3); Assert.assertNotEquals(hashSet3, hashSet5); Assert.assertNotEquals(iterable3, iterable5); Assert.assertNotEquals(hashSet5, hashSet1); Assert.assertNotEquals(iterable5, iterable1); } >> differentNaNs() ::= << @Test public void contains_different_NaNs() { nan1 = ; Iterable primitiveIterable = this.newWith(.BitsTo(nan1)); Set\<\> hashSet = new HashSet\<>(); hashSet.add(.BitsTo(nan1)); nan2 = ; Assert.assertEquals(hashSet.contains(.BitsTo(nan2)), primitiveIterable.contains(.BitsTo(nan2))); } >> ZeroTests() ::= << @Test public void contains_zero() { Iterable iterable = this.newWith(<(literal.(type))("0")>); Set\<\> hashSet = new HashSet\<>(); hashSet.add(<(literal.(type))("0")>); Assert.assertTrue(hashSet.contains(<(literal.(type))("0")>)); Assert.assertFalse(hashSet.contains(-<(literal.(type))("0")>)); Assert.assertTrue(iterable.contains(<(literal.(type))("0")>)); Assert.assertFalse(iterable.contains(-<(literal.(type))("0")>)); } >> NaNBits1 ::= [ "float": "0x7f800001", "double": "0x7ff0000000000001L", "default": "no matching bits" ] NaNBits2 ::= [ "float": "0xff800001", "double": "0xfff0000000000001L", "default": "no matching bits" ] injectIntoPrimitiveTest(toName, toType, toFloatingPoint) ::= << @Test public void injectInto() { Iterable iterable1 = this.newWith(<["0", "2", "31"]:(literal.(type))(); separator=", ">); sum1 = iterable1.injectInto(<(literal.(toType))("0")>, ( result, value) -> () (result + value + 1)); Assert.assertEquals(<(literal.(toType))("36")>, sum1, 0.001); Iterable iterable2 = this.newWith(<[ "1", "2", "31"]:(literal.(type))(); separator=", ">); sum2 = iterable2.injectInto(<(literal.(toType))("0")>, ( result, value) -> () (result + value + 1)); Assert.assertEquals(<(literal.(toType))("37")>, sum2, 0.001); Iterable iterable3 = this.newWith(<["0", "1", "2", "31"]:(literal.(type))(); separator=", ">); sum3 = iterable3.injectInto(<(literal.(toType))("0")>, ( result, value) -> () (result + value + 1)); Assert.assertEquals(<(literal.(toType))("38")>, sum3, 0.001); } >>