| 1 |
import "copyrightAndOthers.stg" |
| 2 |
import "primitiveEquals.stg" |
| 3 |
import "primitiveHashCode.stg" |
| 4 |
import "primitiveLiteral.stg" |
| 5 |
|
| 6 |
isTest() ::= "true" |
| 7 |
|
| 8 |
targetPath() ::= "org/eclipse/collections/impl/collection/mutable/primitive" |
| 9 |
|
| 10 |
fileName(primitive) ::= "Abstract<primitive.name>IterableTestCase" |
| 11 |
|
| 12 |
class(primitive) ::= << |
| 13 |
<body(primitive.type, primitive.wrapperName, primitive.name)> |
| 14 |
>> |
| 15 |
|
| 16 |
body(type, wrapperName, name) ::= << |
| 17 |
<copyrightAndOthers()> |
| 18 |
|
| 19 |
package org.eclipse.collections.impl.collection.mutable.primitive; |
| 20 |
|
| 21 |
import java.util.Arrays; |
| 22 |
<if(primitive.floatingPoint)>import java.util.HashSet;<endif> |
| 23 |
import java.util.List; |
| 24 |
import java.util.NoSuchElementException; |
| 25 |
<if(primitive.floatingPoint)>import java.util.Set;<endif> |
| 26 |
|
| 27 |
import org.eclipse.collections.api.<name>Iterable; |
| 28 |
import org.eclipse.collections.api.Lazy<name>Iterable; |
| 29 |
import org.eclipse.collections.api.RichIterable; |
| 30 |
import org.eclipse.collections.api.block.function.primitive.<name>ToObjectFunction; |
| 31 |
import org.eclipse.collections.api.iterator.<name>Iterator; |
| 32 |
import org.eclipse.collections.api.list.MutableList; |
| 33 |
import org.eclipse.collections.api.list.primitive.Mutable<name>List; |
| 34 |
import org.eclipse.collections.impl.bag.mutable.primitive.<name>HashBag; |
| 35 |
import org.eclipse.collections.impl.block.factory.Comparators; |
| 36 |
import org.eclipse.collections.impl.block.factory.primitive.<name>Predicates; |
| 37 |
import org.eclipse.collections.impl.factory.Bags; |
| 38 |
import org.eclipse.collections.impl.factory.Lists; |
| 39 |
import org.eclipse.collections.impl.factory.Sets; |
| 40 |
import org.eclipse.collections.impl.factory.primitive.BooleanLists; |
| 41 |
import org.eclipse.collections.impl.factory.primitive.BooleanSets; |
| 42 |
import org.eclipse.collections.impl.factory.primitive.ByteLists; |
| 43 |
import org.eclipse.collections.impl.factory.primitive.ByteSets; |
| 44 |
import org.eclipse.collections.impl.factory.primitive.CharLists; |
| 45 |
import org.eclipse.collections.impl.factory.primitive.CharSets; |
| 46 |
import org.eclipse.collections.impl.factory.primitive.DoubleLists; |
| 47 |
import org.eclipse.collections.impl.factory.primitive.DoubleSets; |
| 48 |
import org.eclipse.collections.impl.factory.primitive.FloatLists; |
| 49 |
import org.eclipse.collections.impl.factory.primitive.FloatSets; |
| 50 |
import org.eclipse.collections.impl.factory.primitive.IntLists; |
| 51 |
import org.eclipse.collections.impl.factory.primitive.IntSets; |
| 52 |
import org.eclipse.collections.impl.factory.primitive.LongLists; |
| 53 |
import org.eclipse.collections.impl.factory.primitive.LongSets; |
| 54 |
import org.eclipse.collections.impl.factory.primitive.ShortLists; |
| 55 |
import org.eclipse.collections.impl.factory.primitive.ShortSets; |
| 56 |
<if(primitive.floatingPoint)>import org.eclipse.collections.impl.list.Interval;<endif> |
| 57 |
import org.eclipse.collections.impl.list.mutable.primitive.<name>ArrayList; |
| 58 |
import org.eclipse.collections.impl.set.mutable.primitive.<name>HashSet; |
| 59 |
import org.eclipse.collections.impl.test.Verify; |
| 60 |
import org.junit.Assert; |
| 61 |
import org.junit.Test; |
| 62 |
|
| 63 |
/** |
| 64 |
* Abstract JUnit test for {@link <name>Iterable}s |
| 65 |
* This file was automatically generated from template file abstractPrimitiveIterableTestCase.stg. |
| 66 |
*/ |
| 67 |
public abstract class Abstract<name>IterableTestCase |
| 68 |
{ |
| 69 |
protected abstract <name>Iterable classUnderTest(); |
| 70 |
|
| 71 |
protected abstract <name>Iterable newWith(<type>... elements); |
| 72 |
|
| 73 |
protected abstract <name>Iterable newMutableCollectionWith(<type>... elements); |
| 74 |
|
| 75 |
protected abstract RichIterable\<<wrapperName>\> newObjectCollectionWith(<wrapperName>... elements); |
| 76 |
|
| 77 |
@Test |
| 78 |
public void newCollectionWith() |
| 79 |
{ |
| 80 |
<name>Iterable iterable = this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">); |
| 81 |
Verify.assertSize(3, iterable); |
| 82 |
Verify.assertSize(4, this.newWith(<["0", "1", "31", "32"]:(literal.(type))(); separator=", ">)); |
| 83 |
Assert.assertTrue(iterable.containsAll(<["1", "2", "3"]:(literal.(type))(); separator=", ">)); |
| 84 |
|
| 85 |
<name>Iterable iterable1 = this.newWith(); |
| 86 |
Verify.assertEmpty(iterable1); |
| 87 |
Assert.assertFalse(iterable1.containsAll(<["1", "2", "3"]:(literal.(type))(); separator=", ">)); |
| 88 |
|
| 89 |
<name>Iterable iterable2 = this.newWith(<(literal.(type))("1")>); |
| 90 |
Verify.assertSize(1, iterable2); |
| 91 |
Assert.assertFalse(iterable2.containsAll(<["1", "2", "3"]:(literal.(type))(); separator=", ">)); |
| 92 |
} |
| 93 |
|
| 94 |
@Test |
| 95 |
public void newCollection() |
| 96 |
{ |
| 97 |
Assert.assertEquals(this.newMutableCollectionWith(), this.newWith()); |
| 98 |
Assert.assertEquals(this.newMutableCollectionWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">), this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">)); |
| 99 |
Assert.assertEquals(this.newMutableCollectionWith(<["0", "1", "31", "32"]:(literal.(type))(); separator=", ">), this.newWith(<["0", "1", "31", "32"]:(literal.(type))(); separator=", ">)); |
| 100 |
} |
| 101 |
|
| 102 |
@Test |
| 103 |
public void isEmpty() |
| 104 |
{ |
| 105 |
Verify.assertEmpty(this.newWith()); |
| 106 |
Verify.assertNotEmpty(this.classUnderTest()); |
| 107 |
Verify.assertNotEmpty(this.newWith(<["0", "1", "31", "32"]:(literal.(type))(); separator=", ">)); |
| 108 |
Verify.assertNotEmpty(this.newWith(<["0", "1", "2"]:(literal.(type))(); separator=", ">)); |
| 109 |
Verify.assertNotEmpty(this.newWith(<["0", "31"]:(literal.(type))(); separator=", ">)); |
| 110 |
Verify.assertNotEmpty(this.newWith(<["31", "32"]:(literal.(type))(); separator=", ">)); |
| 111 |
Verify.assertNotEmpty(this.newWith(<["32", "33"]:(literal.(type))(); separator=", ">)); |
| 112 |
} |
| 113 |
|
| 114 |
@Test |
| 115 |
public void notEmpty() |
| 116 |
{ |
| 117 |
Assert.assertFalse(this.newWith().notEmpty()); |
| 118 |
Assert.assertTrue(this.classUnderTest().notEmpty()); |
| 119 |
Assert.assertTrue(this.newWith(<["0", "1", "31", "32"]:(literal.(type))(); separator=", ">).notEmpty()); |
| 120 |
Assert.assertTrue(this.newWith(<["0", "1", "2"]:(literal.(type))(); separator=", ">).notEmpty()); |
| 121 |
Assert.assertTrue(this.newWith(<["0", "31"]:(literal.(type))(); separator=", ">).notEmpty()); |
| 122 |
Assert.assertTrue(this.newWith(<["31", "32"]:(literal.(type))(); separator=", ">).notEmpty()); |
| 123 |
Assert.assertTrue(this.newWith(<["32", "33"]:(literal.(type))(); separator=", ">).notEmpty()); |
| 124 |
} |
| 125 |
|
| 126 |
@Test |
| 127 |
public void tap() |
| 128 |
{ |
| 129 |
Mutable<name>List tapResult = <name>Lists.mutable.empty(); |
| 130 |
<name>Iterable collection = this.newWith(<["14", "2", "30", "31", "32", "35", "0", "1"]:(literal.(type))(); separator=", ">); |
| 131 |
Assert.assertSame(collection, collection.tap(tapResult::add)); |
| 132 |
Assert.assertEquals(collection.toList(), tapResult); |
| 133 |
} |
| 134 |
|
| 135 |
@Test |
| 136 |
public void contains() |
| 137 |
{ |
| 138 |
<name>Iterable iterable = this.newWith(<["14", "2", "30", "31", "32", "35", "0", "1"]:(literal.(type))(); separator=", ">); |
| 139 |
Assert.assertFalse(iterable.contains(<(literal.(type))("29")>)); |
| 140 |
Assert.assertFalse(iterable.contains(<(literal.(type))("49")>)); |
| 141 |
|
| 142 |
<type>[] numbers = {<["14", "2", "30", "31", "32", "35", "0", "1"]:(literal.(type))(); separator=", ">}; |
| 143 |
for (<type> number : numbers) |
| 144 |
{ |
| 145 |
Assert.assertTrue(iterable.contains(number)); |
| 146 |
} |
| 147 |
|
| 148 |
Assert.assertFalse(iterable.contains(<(literal.(type))("-1")>)); |
| 149 |
Assert.assertFalse(iterable.contains(<(literal.(type))("29")>)); |
| 150 |
Assert.assertFalse(iterable.contains(<(literal.(type))("49")>)); |
| 151 |
|
| 152 |
<name>Iterable iterable1 = this.newWith(<["0", "1", "1", "2", "2", "2"]:(literal.(type))(); separator=", ">); |
| 153 |
Assert.assertTrue(iterable1.contains(<(literal.(type))("0")>)); |
| 154 |
Assert.assertTrue(iterable1.contains(<(literal.(type))("1")>)); |
| 155 |
Assert.assertTrue(iterable1.contains(<(literal.(type))("2")>)); |
| 156 |
Assert.assertFalse(iterable1.contains(<(literal.(type))("3")>)); |
| 157 |
|
| 158 |
<name>Iterable iterable2 = this.classUnderTest(); |
| 159 |
for (<type> each = 1; each \<= iterable2.size(); each++) |
| 160 |
{ |
| 161 |
Assert.assertTrue(iterable2.contains(each)); |
| 162 |
} |
| 163 |
Assert.assertFalse(iterable2.contains(<(castIntToNarrowTypeWithParens.(type))("iterable2.size() + 1")>)); |
| 164 |
} |
| 165 |
|
| 166 |
<if(primitive.floatingPoint)> |
| 167 |
<NaNTests("NaN")> |
| 168 |
<NaNTests("NEGATIVE_INFINITY")> |
| 169 |
<NaNTests("POSITIVE_INFINITY")> |
| 170 |
<ZeroTests()> |
| 171 |
<NaNEqualsTests()> |
| 172 |
<differentNaNs()> |
| 173 |
<endif> |
| 174 |
@Test |
| 175 |
public void containsAllArray() |
| 176 |
{ |
| 177 |
Assert.assertTrue(this.classUnderTest().containsAll(this.classUnderTest().toArray())); |
| 178 |
Assert.assertFalse(this.classUnderTest().containsAll(<(castIntToNarrowTypeWithParens.(type))("this.classUnderTest().size() + 1")>)); |
| 179 |
|
| 180 |
<name>Iterable iterable = this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">); |
| 181 |
Assert.assertTrue(iterable.containsAll(<(literal.(type))("1")>)); |
| 182 |
Assert.assertTrue(iterable.containsAll(<["1", "2", "3"]:(literal.(type))(); separator=", ">)); |
| 183 |
Assert.assertFalse(iterable.containsAll(<["1", "2", "3", "4"]:(literal.(type))(); separator=", ">)); |
| 184 |
Assert.assertFalse(iterable.containsAll(<["1", "2", "4"]:(literal.(type))(); separator=", ">)); |
| 185 |
Assert.assertFalse(iterable.containsAll(<["4", "5", "6"]:(literal.(type))(); separator=", ">)); |
| 186 |
|
| 187 |
<name>Iterable iterable1 = this.newWith(<["14", "2", "30", "32", "35", "0", "1"]:(literal.(type))(); separator=", ">); |
| 188 |
Assert.assertTrue(iterable1.containsAll(<(literal.(type))("14")>)); |
| 189 |
Assert.assertTrue(iterable1.containsAll(<(literal.(type))("35")>)); |
| 190 |
Assert.assertFalse(iterable1.containsAll(<(literal.(type))("-1")>)); |
| 191 |
Assert.assertTrue(iterable1.containsAll(<["14", "1", "30"]:(literal.(type))(); separator=", ">)); |
| 192 |
Assert.assertTrue(iterable1.containsAll(<["14", "1", "32"]:(literal.(type))(); separator=", ">)); |
| 193 |
Assert.assertTrue(iterable1.containsAll(<["14", "1", "35"]:(literal.(type))(); separator=", ">)); |
| 194 |
Assert.assertFalse(iterable1.containsAll(<["0", "2", "35", "-1"]:(literal.(type))(); separator=", ">)); |
| 195 |
Assert.assertFalse(iterable1.containsAll(<["31", "-1"]:(literal.(type))(); separator=", ">)); |
| 196 |
|
| 197 |
<name>Iterable iterable2 = this.newWith(<["0", "1", "1", "2", "2", "2"]:(literal.(type))(); separator=", ">); |
| 198 |
Assert.assertTrue(iterable2.containsAll(<(literal.(type))("0")>)); |
| 199 |
Assert.assertTrue(iterable2.containsAll(<["0", "0", "0"]:(literal.(type))(); separator=", ">)); |
| 200 |
Assert.assertTrue(iterable2.containsAll(<["0", "1", "1"]:(literal.(type))(); separator=", ">)); |
| 201 |
Assert.assertTrue(iterable2.containsAll(<["0", "1", "2"]:(literal.(type))(); separator=", ">)); |
| 202 |
Assert.assertFalse(iterable2.containsAll(<["0", "1", "2", "3", "4"]:(literal.(type))(); separator=", ">)); |
| 203 |
Assert.assertFalse(iterable2.containsAll(<["3", "4"]:(literal.(type))(); separator=", ">)); |
| 204 |
|
| 205 |
int size = 33; |
| 206 |
<type>[] array = new <type>[size]; |
| 207 |
for (int i = 0; i \< size; i++) |
| 208 |
{ |
| 209 |
array[i] = <(castIntToNarrowTypeWithParens.(type))("i + 1")>; |
| 210 |
} |
| 211 |
|
| 212 |
<name>Iterable iterable3 = this.newWith(array); |
| 213 |
Assert.assertTrue(iterable3.containsAll(<["1", "2", "3"]:(literal.(type))(); separator=", ">)); |
| 214 |
Assert.assertTrue(iterable3.containsAll()); |
| 215 |
Assert.assertFalse(iterable3.containsAll(<["3", "4", "5", "33", "34"]:(literal.(type))(); separator=", ">)); |
| 216 |
Assert.assertTrue(iterable3.containsAll(array)); |
| 217 |
|
| 218 |
<name>Iterable iterable4 = <name>Sets.mutable.with(array); |
| 219 |
Assert.assertTrue(iterable4.containsAll(<["1", "2", "3"]:(literal.(type))(); separator=", ">)); |
| 220 |
Assert.assertTrue(iterable4.containsAll()); |
| 221 |
Assert.assertFalse(iterable4.containsAll(<["3", "4", "5", "33", "34"]:(literal.(type))(); separator=", ">)); |
| 222 |
Assert.assertTrue(iterable4.containsAll(array)); |
| 223 |
} |
| 224 |
|
| 225 |
@Test |
| 226 |
public void containsAllIterable() |
| 227 |
{ |
| 228 |
<name>Iterable source = this.classUnderTest(); |
| 229 |
Assert.assertTrue(source.containsAll(this.classUnderTest())); |
| 230 |
Assert.assertFalse(source.containsAll(<name>ArrayList.newListWith(<(castIntToNarrowTypeWithParens.(type))("source.size() + 1")>))); |
| 231 |
|
| 232 |
<name>Iterable iterable = this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">); |
| 233 |
Assert.assertTrue(this.newWith().containsAll(new <name>ArrayList())); |
| 234 |
Assert.assertFalse(this.newWith().containsAll(<name>ArrayList.newListWith(<(literal.(type))("1")>))); |
| 235 |
Assert.assertTrue(iterable.containsAll(<name>ArrayList.newListWith(<(literal.(type))("1")>))); |
| 236 |
Assert.assertTrue(iterable.containsAll(<name>ArrayList.newListWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">))); |
| 237 |
Assert.assertFalse(iterable.containsAll(<name>ArrayList.newListWith(<["1", "2", "3", "4"]:(literal.(type))(); separator=", ">))); |
| 238 |
Assert.assertFalse(iterable.containsAll(<name>ArrayList.newListWith(<["1", "2", "4"]:(literal.(type))(); separator=", ">))); |
| 239 |
Assert.assertFalse(iterable.containsAll(<name>ArrayList.newListWith(<["4", "5", "6"]:(literal.(type))(); separator=", ">))); |
| 240 |
|
| 241 |
<name>Iterable iterable1 = this.newWith(<["14", "2", "30", "32", "35", "0", "1"]:(literal.(type))(); separator=", ">); |
| 242 |
Assert.assertTrue(iterable1.containsAll(<name>HashSet.newSetWith(<(literal.(type))("14")>))); |
| 243 |
Assert.assertTrue(iterable1.containsAll(<name>HashSet.newSetWith(<(literal.(type))("35")>))); |
| 244 |
Assert.assertFalse(iterable1.containsAll(<name>HashSet.newSetWith(<(literal.(type))("-1")>))); |
| 245 |
Assert.assertTrue(iterable1.containsAll(<name>HashSet.newSetWith(<["14", "1", "30"]:(literal.(type))(); separator=", ">))); |
| 246 |
Assert.assertTrue(iterable1.containsAll(<name>HashSet.newSetWith(<["14", "1", "32"]:(literal.(type))(); separator=", ">))); |
| 247 |
Assert.assertTrue(iterable1.containsAll(<name>HashSet.newSetWith(<["14", "1", "35"]:(literal.(type))(); separator=", ">))); |
| 248 |
Assert.assertFalse(iterable1.containsAll(<name>HashSet.newSetWith(<["0", "2", "35", "-1"]:(literal.(type))(); separator=", ">))); |
| 249 |
Assert.assertFalse(iterable1.containsAll(<name>HashSet.newSetWith(<["31", "-1"]:(literal.(type))(); separator=", ">))); |
| 250 |
|
| 251 |
<name>Iterable iterable2 = this.newWith(<["0", "1", "1", "2", "2", "2"]:(literal.(type))(); separator=", ">); |
| 252 |
Assert.assertTrue(iterable2.containsAll(<name>ArrayList.newListWith(<(literal.(type))("0")>))); |
| 253 |
Assert.assertTrue(iterable2.containsAll(<name>ArrayList.newListWith(<["0", "0", "0"]:(literal.(type))(); separator=", ">))); |
| 254 |
Assert.assertTrue(iterable2.containsAll(<name>ArrayList.newListWith(<["0", "1", "1"]:(literal.(type))(); separator=", ">))); |
| 255 |
Assert.assertTrue(iterable2.containsAll(<name>ArrayList.newListWith(<["0", "1", "2"]:(literal.(type))(); separator=", ">))); |
| 256 |
Assert.assertFalse(iterable2.containsAll(<name>ArrayList.newListWith(<["0", "1", "2", "3", "4"]:(literal.(type))(); separator=", ">))); |
| 257 |
Assert.assertFalse(iterable2.containsAll(<name>ArrayList.newListWith(<["3", "4"]:(literal.(type))(); separator=", ">))); |
| 258 |
|
| 259 |
int size = 33; |
| 260 |
<type>[] array = new <type>[size]; |
| 261 |
for (int i = 0; i \< size; i++) |
| 262 |
{ |
| 263 |
array[i] = <(castIntToNarrowTypeWithParens.(type))("i + 1")>; |
| 264 |
} |
| 265 |
|
| 266 |
<name>Iterable iterable3 = this.newWith(array); |
| 267 |
Assert.assertTrue(iterable3.containsAll(<name>Lists.immutable.with(<["1", "2", "3"]:(literal.(type))(); separator=", ">))); |
| 268 |
Assert.assertTrue(iterable3.containsAll(<name>Lists.mutable.empty())); |
| 269 |
Assert.assertFalse(iterable3.containsAll(<name>Lists.mutable.with(<["3", "4", "5", "33", "34"]:(literal.(type))(); separator=", ">))); |
| 270 |
Assert.assertTrue(iterable3.containsAll(<name>Lists.immutable.with(array))); |
| 271 |
|
| 272 |
<name>Iterable iterable4 = <name>Sets.mutable.with(array); |
| 273 |
Assert.assertTrue(iterable4.containsAll(<name>Lists.immutable.with(<["1", "2", "3"]:(literal.(type))(); separator=", ">))); |
| 274 |
Assert.assertTrue(iterable4.containsAll(<name>Lists.mutable.empty())); |
| 275 |
Assert.assertFalse(iterable4.containsAll(<name>Lists.mutable.with(<["3", "4", "5", "33", "34"]:(literal.(type))(); separator=", ">))); |
| 276 |
Assert.assertTrue(iterable4.containsAll(<name>Lists.immutable.with(array))); |
| 277 |
} |
| 278 |
|
| 279 |
@Test |
| 280 |
public void containsAnyArray() |
| 281 |
{ |
| 282 |
<name>Iterable iterable = this.newWith(<["1", "2", "3", "4", "5"]:(literal.(type))(); separator=", ">); |
| 283 |
Assert.assertTrue(iterable.containsAny(<["1", "1", "1"]:(literal.(type))(); separator=", ">)); |
| 284 |
Assert.assertFalse(iterable.containsAny()); |
| 285 |
Assert.assertTrue(iterable.containsAny(<["1", "2", "3"]:(literal.(type))(); separator=", ">)); |
| 286 |
Assert.assertFalse(iterable.containsAny(<["6", "7", "8"]:(literal.(type))(); separator=", ">)); |
| 287 |
|
| 288 |
<name>Iterable iterable2 = this.newWith(<["0", "1", "3", "7"]:(literal.(type))(); separator=", ">); |
| 289 |
Assert.assertTrue(iterable2.containsAny(<["3", "3", "1", "9"]:(literal.(type))(); separator=", ">)); |
| 290 |
Assert.assertFalse(iterable2.containsAny()); |
| 291 |
Assert.assertTrue(iterable2.containsAny(<["-1", "3", "5"]:(literal.(type))(); separator=", ">)); |
| 292 |
Assert.assertFalse(iterable2.containsAny(<["2", "4", "6"]:(literal.(type))(); separator=", ">)); |
| 293 |
|
| 294 |
int size = 33; |
| 295 |
<type>[] array = new <type>[size]; |
| 296 |
<type>[] unmatched = new <type>[size]; |
| 297 |
for (int i = 0; i \< size; i++) |
| 298 |
{ |
| 299 |
array[i] = <(castIntToNarrowTypeWithParens.(type))("i + 1")>; |
| 300 |
unmatched[i] = <(castIntToNarrowTypeWithParens.(type))("i + 34")>; |
| 301 |
} |
| 302 |
<name>Iterable iterable3 = this.newWith(array); |
| 303 |
Assert.assertTrue(iterable3.containsAny(array)); |
| 304 |
Assert.assertFalse(iterable3.containsAny(unmatched)); |
| 305 |
|
| 306 |
<name>Iterable iterable4 = <name>Sets.mutable.with(array); |
| 307 |
Assert.assertTrue(iterable4.containsAny(array)); |
| 308 |
Assert.assertFalse(iterable4.containsAny(unmatched)); |
| 309 |
|
| 310 |
<name>Iterable emptyIterable = this.newWith(); |
| 311 |
Assert.assertFalse(emptyIterable.containsAny()); |
| 312 |
Assert.assertFalse(emptyIterable.containsAny(<["0", "0"]:(literal.(type))(); separator=", ">)); |
| 313 |
Assert.assertFalse(emptyIterable.containsAny(<(literal.(type))("-1")>)); |
| 314 |
Assert.assertFalse(emptyIterable.containsAny(<["1", "2", "3"]:(literal.(type))(); separator=", ">)); |
| 315 |
} |
| 316 |
|
| 317 |
@Test |
| 318 |
public void containsAnyIterable() |
| 319 |
{ |
| 320 |
<name>Iterable iterable = this.newWith(<["1", "2", "3", "4", "5"]:(literal.(type))(); separator=", ">); |
| 321 |
Assert.assertTrue(iterable.containsAny(<name>Lists.immutable.with(<["1", "1", "1"]:(literal.(type))(); separator=", ">))); |
| 322 |
Assert.assertFalse(iterable.containsAny(<name>Lists.mutable.empty())); |
| 323 |
Assert.assertTrue(iterable.containsAny(<name>Lists.immutable.with(<["1", "2", "3"]:(literal.(type))(); separator=", ">))); |
| 324 |
Assert.assertFalse(iterable.containsAny(<name>Lists.mutable.with(<["6", "7", "8"]:(literal.(type))(); separator=", ">))); |
| 325 |
|
| 326 |
<name>Iterable iterable2 = this.newWith(<["0", "1", "3", "7"]:(literal.(type))(); separator=", ">); |
| 327 |
Assert.assertTrue(iterable2.containsAny(<name>Sets.immutable.with(<["3", "3", "1", "9"]:(literal.(type))(); separator=", ">))); |
| 328 |
Assert.assertFalse(iterable2.containsAny(<name>Sets.mutable.empty())); |
| 329 |
Assert.assertTrue(iterable2.containsAny(<name>Sets.immutable.with(<["-1", "3", "5"]:(literal.(type))(); separator=", ">))); |
| 330 |
Assert.assertFalse(iterable2.containsAny(<name>Sets.mutable.with(<["2", "4", "6"]:(literal.(type))(); separator=", ">))); |
| 331 |
|
| 332 |
<name>Iterable emptyIterable = this.newWith(); |
| 333 |
Assert.assertFalse(emptyIterable.containsAny(<name>Lists.mutable.empty())); |
| 334 |
Assert.assertFalse(emptyIterable.containsAny(<name>Lists.immutable.with(<["0", "0"]:(literal.(type))(); separator=", ">))); |
| 335 |
Assert.assertFalse(emptyIterable.containsAny(<name>Lists.mutable.with(<(literal.(type))("-1")>))); |
| 336 |
Assert.assertFalse(emptyIterable.containsAny(<name>Lists.immutable.with(<["1", "2", "3"]:(literal.(type))(); separator=", ">))); |
| 337 |
|
| 338 |
int size = 33; |
| 339 |
<type>[] array = new <type>[size]; |
| 340 |
<type>[] unmatched = new <type>[size]; |
| 341 |
<type>[] bigger = new <type>[size + 1]; |
| 342 |
for (int i = 0; i \< size; i++) |
| 343 |
{ |
| 344 |
array[i] = <(castIntToNarrowTypeWithParens.(type))("i + 1")>; |
| 345 |
bigger[i] = <(castIntToNarrowTypeWithParens.(type))("i + 1")>; |
| 346 |
unmatched[i] = <(castIntToNarrowTypeWithParens.(type))("i + 34")>; |
| 347 |
} |
| 348 |
bigger[size - 1] = <(literal.(type))("33")>; |
| 349 |
|
| 350 |
<name>Iterable iterable3 = this.newWith(array); |
| 351 |
Assert.assertTrue(iterable3.containsAny(<name>Lists.immutable.with(array))); |
| 352 |
Assert.assertFalse(iterable3.containsAny(<name>Lists.mutable.with(unmatched))); |
| 353 |
Assert.assertFalse(iterable3.containsAny(<name>Sets.mutable.with(unmatched))); |
| 354 |
Assert.assertTrue(iterable3.containsAny(<name>Sets.mutable.with(bigger))); |
| 355 |
|
| 356 |
<name>Iterable iterable4 = <name>Sets.mutable.with(array); |
| 357 |
Assert.assertTrue(iterable4.containsAny(<name>Lists.immutable.with(array))); |
| 358 |
Assert.assertFalse(iterable4.containsAny(<name>Lists.mutable.with(unmatched))); |
| 359 |
Assert.assertTrue(iterable4.containsAny(<name>Sets.immutable.with(array))); |
| 360 |
Assert.assertTrue(iterable4.containsAny(<name>Sets.immutable.with(bigger))); |
| 361 |
} |
| 362 |
|
| 363 |
@Test |
| 364 |
public void containsNoneArray() |
| 365 |
{ |
| 366 |
<name>Iterable iterable = this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">); |
| 367 |
Assert.assertFalse(iterable.containsNone(<["1", "1"]:(literal.(type))(); separator=", ">)); |
| 368 |
Assert.assertTrue(iterable.containsNone()); |
| 369 |
Assert.assertFalse(iterable.containsNone(<["3", "4", "5", "6"]:(literal.(type))(); separator=", ">)); |
| 370 |
Assert.assertTrue(iterable.containsNone(<["7", "8", "11"]:(literal.(type))(); separator=", ">)); |
| 371 |
|
| 372 |
<name>Iterable iterable2 = this.newWith(<["0", "1", "3", "7"]:(literal.(type))(); separator=", ">); |
| 373 |
Assert.assertTrue(iterable2.containsNone(<["2", "4", "6"]:(literal.(type))(); separator=", ">)); |
| 374 |
Assert.assertTrue(iterable2.containsNone()); |
| 375 |
Assert.assertFalse(iterable2.containsNone(<["-1", "1", "3"]:(literal.(type))(); separator=", ">)); |
| 376 |
Assert.assertFalse(iterable2.containsNone(<["7", "3", "1", "0"]:(literal.(type))(); separator=", ">)); |
| 377 |
|
| 378 |
int size = 33; |
| 379 |
<type>[] array = new <type>[size]; |
| 380 |
<type>[] unmatched = new <type>[size]; |
| 381 |
for (int i = 0; i \< size; i++) |
| 382 |
{ |
| 383 |
array[i] = <(castIntToNarrowTypeWithParens.(type))("i + 1")>; |
| 384 |
unmatched[i] = <(castIntToNarrowTypeWithParens.(type))("i + 34")>; |
| 385 |
} |
| 386 |
<name>Iterable iterable3 = this.newWith(array); |
| 387 |
Assert.assertFalse(iterable3.containsNone(array)); |
| 388 |
Assert.assertTrue(iterable3.containsNone(unmatched)); |
| 389 |
|
| 390 |
<name>Iterable iterable4 = <name>Sets.mutable.with(array); |
| 391 |
Assert.assertFalse(iterable4.containsNone(array)); |
| 392 |
Assert.assertTrue(iterable4.containsNone(unmatched)); |
| 393 |
|
| 394 |
<name>Iterable emptyIterable = this.newWith(); |
| 395 |
Assert.assertTrue(emptyIterable.containsNone(<["1", "2", "3"]:(literal.(type))(); separator=", ">)); |
| 396 |
Assert.assertTrue(emptyIterable.containsNone()); |
| 397 |
Assert.assertTrue(emptyIterable.containsNone(<["-1", "5"]:(literal.(type))(); separator=", ">)); |
| 398 |
Assert.assertTrue(emptyIterable.containsNone(<(literal.(type))("0")>)); |
| 399 |
} |
| 400 |
|
| 401 |
@Test |
| 402 |
public void containsNoneIterable() |
| 403 |
{ |
| 404 |
<name>Iterable iterable = this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">); |
| 405 |
Assert.assertFalse(iterable.containsNone(<name>Lists.immutable.with(<["1", "1"]:(literal.(type))(); separator=", ">))); |
| 406 |
Assert.assertTrue(iterable.containsNone(<name>Lists.mutable.empty())); |
| 407 |
Assert.assertFalse(iterable.containsNone(<name>Lists.mutable.with(<["3", "4", "5", "6"]:(literal.(type))(); separator=", ">))); |
| 408 |
Assert.assertTrue(iterable.containsNone(<name>Lists.immutable.with(<["7", "8", "11"]:(literal.(type))(); separator=", ">))); |
| 409 |
|
| 410 |
<name>Iterable iterable2 = this.newWith(<["0", "1", "3", "7"]:(literal.(type))(); separator=", ">); |
| 411 |
Assert.assertTrue(iterable2.containsNone(<name>Sets.immutable.with(<["2", "4", "6"]:(literal.(type))(); separator=", ">))); |
| 412 |
Assert.assertTrue(iterable2.containsNone(<name>Sets.mutable.empty())); |
| 413 |
Assert.assertFalse(iterable2.containsNone(<name>Sets.immutable.with(<["-1", "1", "3"]:(literal.(type))(); separator=", ">))); |
| 414 |
Assert.assertFalse(iterable2.containsNone(<name>Sets.mutable.with(<["7", "3", "1", "0"]:(literal.(type))(); separator=", ">))); |
| 415 |
|
| 416 |
<name>Iterable emptyIterable = this.newWith(); |
| 417 |
Assert.assertTrue(emptyIterable.containsNone(<name>Lists.immutable.with(<["1", "2", "3"]:(literal.(type))(); separator=", ">))); |
| 418 |
Assert.assertTrue(emptyIterable.containsNone(<name>Lists.mutable.empty())); |
| 419 |
Assert.assertTrue(emptyIterable.containsNone(<name>Lists.immutable.with(<["-1", "5"]:(literal.(type))(); separator=", ">))); |
| 420 |
Assert.assertTrue(emptyIterable.containsNone(<name>Lists.mutable.with(<(literal.(type))("0")>))); |
| 421 |
|
| 422 |
int size = 33; |
| 423 |
<type>[] array = new <type>[size]; |
| 424 |
<type>[] unmatched = new <type>[size]; |
| 425 |
<type>[] bigger = new <type>[size + 1]; |
| 426 |
for (int i = 0; i \< size; i++) |
| 427 |
{ |
| 428 |
array[i] = <(castIntToNarrowTypeWithParens.(type))("i + 1")>; |
| 429 |
bigger[i] = <(castIntToNarrowTypeWithParens.(type))("i + 1")>; |
| 430 |
unmatched[i] = <(castIntToNarrowTypeWithParens.(type))("i + 34")>; |
| 431 |
} |
| 432 |
bigger[size - 1] = <(literal.(type))("33")>; |
| 433 |
|
| 434 |
<name>Iterable iterable3 = this.newWith(array); |
| 435 |
Assert.assertFalse(iterable3.containsNone(<name>Lists.immutable.with(array))); |
| 436 |
Assert.assertTrue(iterable3.containsNone(<name>Lists.mutable.with(unmatched))); |
| 437 |
Assert.assertTrue(iterable3.containsNone(<name>Sets.mutable.with(unmatched))); |
| 438 |
Assert.assertFalse(iterable3.containsNone(<name>Sets.mutable.with(bigger))); |
| 439 |
|
| 440 |
<name>Iterable iterable4 = <name>Sets.mutable.with(array); |
| 441 |
Assert.assertFalse(iterable4.containsNone(<name>Lists.immutable.with(array))); |
| 442 |
Assert.assertTrue(iterable4.containsNone(<name>Lists.mutable.with(unmatched))); |
| 443 |
Assert.assertFalse(iterable4.containsNone(<name>Sets.immutable.with(array))); |
| 444 |
Assert.assertFalse(iterable4.containsNone(<name>Sets.immutable.with(bigger))); |
| 445 |
} |
| 446 |
|
| 447 |
@Test |
| 448 |
public abstract void <type>Iterator(); |
| 449 |
|
| 450 |
@Test(expected = NoSuchElementException.class) |
| 451 |
public void <type>Iterator_throws() |
| 452 |
{ |
| 453 |
<name>Iterator iterator = this.classUnderTest().<type>Iterator(); |
| 454 |
while (iterator.hasNext()) |
| 455 |
{ |
| 456 |
iterator.next(); |
| 457 |
} |
| 458 |
iterator.next(); |
| 459 |
} |
| 460 |
|
| 461 |
@Test(expected = NoSuchElementException.class) |
| 462 |
public void <type>Iterator_throws_non_empty_collection() |
| 463 |
{ |
| 464 |
<name>Iterable iterable = this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">); |
| 465 |
<name>Iterator iterator = iterable.<type>Iterator(); |
| 466 |
while (iterator.hasNext()) |
| 467 |
{ |
| 468 |
iterator.next(); |
| 469 |
} |
| 470 |
iterator.next(); |
| 471 |
} |
| 472 |
|
| 473 |
@Test |
| 474 |
public void forEach() |
| 475 |
{ |
| 476 |
<wideType.(type)>[] sum = new <wideType.(type)>[1]; |
| 477 |
this.classUnderTest().forEach(each -> sum[0] += each); |
| 478 |
|
| 479 |
int size = this.classUnderTest().size(); |
| 480 |
long sum1 = (long) ((size * (size + 1)) / 2); |
| 481 |
Assert.assertEquals(sum1, sum[0]<wideDelta.(type)>); |
| 482 |
} |
| 483 |
|
| 484 |
@Test |
| 485 |
public void size() |
| 486 |
{ |
| 487 |
Verify.assertSize(0, this.newWith()); |
| 488 |
Verify.assertSize(1, this.newWith(<(literal.(type))("3")>)); |
| 489 |
Verify.assertSize(3, this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">)); |
| 490 |
} |
| 491 |
|
| 492 |
@Test |
| 493 |
public void count() |
| 494 |
{ |
| 495 |
<name>Iterable iterable = this.classUnderTest(); |
| 496 |
int size = iterable.size(); |
| 497 |
Assert.assertEquals(size >= 3 ? 3 : size, iterable.count(<name>Predicates.lessThan(<(literal.(type))("4")>))); |
| 498 |
Assert.assertEquals(2L, this.newWith(<["1", "0", "2"]:(literal.(type))(); separator=", ">).count(<name>Predicates.greaterThan(<zero.(type)>))); |
| 499 |
|
| 500 |
Assert.assertEquals(1, this.newWith(<["1"]:(literal.(type))(); separator=", ">).count(<name>Predicates.alwaysTrue())); |
| 501 |
Assert.assertEquals(0, this.newWith(<["1"]:(literal.(type))(); separator=", ">).count(<name>Predicates.alwaysFalse())); |
| 502 |
} |
| 503 |
|
| 504 |
@Test |
| 505 |
public void anySatisfy() |
| 506 |
{ |
| 507 |
Assert.assertTrue(this.newWith(<["1", "-1", "2"]:(literal.(type))(); separator=", ">).anySatisfy(<name>Predicates.greaterThan(<(literal.(type))("0")>))); |
| 508 |
Assert.assertFalse(this.newWith(<["1", "-1", "2"]:(literal.(type))(); separator=", ">).anySatisfy(<name>Predicates.equal(<(literal.(type))("0")>))); |
| 509 |
Assert.assertTrue(this.newWith(<["-1", "-1", "-2", "31", "32"]:(literal.(type))(); separator=", ">).anySatisfy(<name>Predicates.greaterThan(<(literal.(type))("0")>))); |
| 510 |
Assert.assertTrue(this.newWith(<["2", "-1", "-2", "31", "32"]:(literal.(type))(); separator=", ">).anySatisfy(<name>Predicates.greaterThan(<(literal.(type))("0")>))); |
| 511 |
Assert.assertFalse(this.newWith(<["1", "-1", "31", "32"]:(literal.(type))(); separator=", ">).anySatisfy(<name>Predicates.equal(<(literal.(type))("0")>))); |
| 512 |
Assert.assertTrue(this.newWith(<["32"]:(literal.(type))(); separator=", ">).anySatisfy(<name>Predicates.greaterThan(<(literal.(type))("0")>))); |
| 513 |
<name>Iterable iterable = this.newWith(<["0", "1", "2"]:(literal.(type))(); separator=", ">); |
| 514 |
Assert.assertTrue(iterable.anySatisfy(value -> <(lessThan.(type))("value", {<(literal.(type))("3")>})>)); |
| 515 |
Assert.assertFalse(iterable.anySatisfy(<name>Predicates.greaterThan(<(literal.(type))("3")>))); |
| 516 |
|
| 517 |
<name>Iterable iterable1 = this.classUnderTest(); |
| 518 |
int size = iterable1.size(); |
| 519 |
Assert.assertEquals(size > 3, iterable1.anySatisfy(<name>Predicates.greaterThan(<(literal.(type))("3")>))); |
| 520 |
Assert.assertEquals(size != 0, iterable1.anySatisfy(<name>Predicates.lessThan(<(literal.(type))("3")>))); |
| 521 |
} |
| 522 |
|
| 523 |
@Test |
| 524 |
public void allSatisfy() |
| 525 |
{ |
| 526 |
Assert.assertFalse(this.newWith(<["1", "0", "2"]:(literal.(type))(); separator=", ">).allSatisfy(<name>Predicates.greaterThan(<(literal.(type))("0")>))); |
| 527 |
Assert.assertTrue(this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">).allSatisfy(<name>Predicates.greaterThan(<(literal.(type))("0")>))); |
| 528 |
Assert.assertFalse(this.newWith(<["1", "0", "31", "32"]:(literal.(type))(); separator=", ">).allSatisfy(<name>Predicates.greaterThan(<(literal.(type))("0")>))); |
| 529 |
Assert.assertFalse(this.newWith(<["1", "0", "31", "32"]:(literal.(type))(); separator=", ">).allSatisfy(<name>Predicates.greaterThan(<(literal.(type))("0")>))); |
| 530 |
Assert.assertTrue(this.newWith(<["1", "2", "31", "32"]:(literal.(type))(); separator=", ">).allSatisfy(<name>Predicates.greaterThan(<(literal.(type))("0")>))); |
| 531 |
Assert.assertFalse(this.newWith(<["32"]:(literal.(type))(); separator=", ">).allSatisfy(<name>Predicates.equal(<(literal.(type))("33")>))); |
| 532 |
Assert.assertFalse(this.newWith(<["-32"]:(literal.(type))(); separator=", ">).allSatisfy(<name>Predicates.equal(<(literal.(type))("33")>))); |
| 533 |
<name>Iterable iterable = this.newWith(<["0", "1", "2"]:(literal.(type))(); separator=", ">); |
| 534 |
Assert.assertFalse(iterable.allSatisfy(value -> <(lessThan.(type))({<(literal.(type))("3")>}, "value")>)); |
| 535 |
Assert.assertTrue(iterable.allSatisfy(<name>Predicates.lessThan(<(literal.(type))("3")>))); |
| 536 |
|
| 537 |
<name>Iterable iterable1 = this.classUnderTest(); |
| 538 |
int size = iterable1.size(); |
| 539 |
Assert.assertEquals(size == 0, iterable1.allSatisfy(<name>Predicates.greaterThan(<(literal.(type))("3")>))); |
| 540 |
Assert.assertEquals(size \< 3, iterable1.allSatisfy(<name>Predicates.lessThan(<(literal.(type))("3")>))); |
| 541 |
} |
| 542 |
|
| 543 |
@Test |
| 544 |
public void noneSatisfy() |
| 545 |
{ |
| 546 |
Assert.assertFalse(this.newWith(<["1", "0", "2"]:(literal.(type))(); separator=", ">).noneSatisfy(<name>Predicates.greaterThan(<(literal.(type))("0")>))); |
| 547 |
Assert.assertFalse(this.newWith(<["1", "0", "2"]:(literal.(type))(); separator=", ">).noneSatisfy(<name>Predicates.equal(<(literal.(type))("0")>))); |
| 548 |
Assert.assertTrue(this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">).noneSatisfy(<name>Predicates.greaterThan(<(literal.(type))("3")>))); |
| 549 |
Assert.assertFalse(this.newWith(<["1", "0", "31", "32"]:(literal.(type))(); separator=", ">).noneSatisfy(<name>Predicates.greaterThan(<(literal.(type))("0")>))); |
| 550 |
Assert.assertFalse(this.newWith(<["1", "0", "31", "32"]:(literal.(type))(); separator=", ">).noneSatisfy(<name>Predicates.greaterThan(<(literal.(type))("0")>))); |
| 551 |
Assert.assertTrue(this.newWith(<["1", "2", "31", "32"]:(literal.(type))(); separator=", ">).noneSatisfy(<name>Predicates.lessThan(<(literal.(type))("0")>))); |
| 552 |
Assert.assertFalse(this.newWith(<["32"]:(literal.(type))(); separator=", ">).noneSatisfy(<name>Predicates.greaterThan(<(literal.(type))("0")>))); |
| 553 |
<name>Iterable iterable = this.newWith(<["0", "1", "2"]:(literal.(type))(); separator=", ">); |
| 554 |
Assert.assertFalse(iterable.noneSatisfy(value -> <(lessThan.(type))({<(literal.(type))("1")>}, "value")>)); |
| 555 |
Assert.assertTrue(iterable.noneSatisfy(<name>Predicates.greaterThan(<(literal.(type))("3")>))); |
| 556 |
|
| 557 |
<name>Iterable iterable1 = this.classUnderTest(); |
| 558 |
int size = iterable1.size(); |
| 559 |
Assert.assertEquals(size \<= 3, iterable1.noneSatisfy(<name>Predicates.greaterThan(<(literal.(type))("3")>))); |
| 560 |
Assert.assertEquals(size == 0, iterable1.noneSatisfy(<name>Predicates.lessThan(<(literal.(type))("3")>))); |
| 561 |
} |
| 562 |
|
| 563 |
@Test |
| 564 |
public void collect() |
| 565 |
{ |
| 566 |
<name>ToObjectFunction\<<wrapperName>\> function = parameter -> <(castIntToNarrowTypeWithParens.(type))("parameter - 1")>; |
| 567 |
Assert.assertEquals(this.newObjectCollectionWith(<["0", "1", "2"]:(literal.(type))(); separator=", ">), this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">).collect(function)); |
| 568 |
<name>Iterable iterable = this.newWith(<["1", "2", "2", "3", "3", "3"]:(literal.(type))(); separator=", ">); |
| 569 |
Assert.assertEquals(this.newObjectCollectionWith(<["0", "1", "1", "2", "2", "2"]:(literal.(type))(); separator=", ">), iterable.collect(function)); |
| 570 |
Assert.assertEquals(this.newObjectCollectionWith(), this.newWith().collect(function)); |
| 571 |
Assert.assertEquals(this.newObjectCollectionWith(<(literal.(type))("2")>), this.newWith(<(literal.(type))("3")>).collect(function)); |
| 572 |
} |
| 573 |
|
| 574 |
@Test |
| 575 |
public void collectWithTarget() |
| 576 |
{ |
| 577 |
<name>ToObjectFunction\<<wrapperName>\> function = parameter -> <(castIntToNarrowTypeWithParens.(type))("parameter - 1")>; |
| 578 |
Assert.assertEquals(Bags.mutable.with(<["0", "1", "2"]:(literal.(type))(); separator=", ">), this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">).collect(function, Bags.mutable.empty())); |
| 579 |
<name>Iterable iterable = this.newWith(<["1", "2", "2", "3", "3", "3"]:(literal.(type))(); separator=", ">); |
| 580 |
Assert.assertEquals(Sets.mutable.with(<["0", "1", "2"]:(literal.(type))(); separator=", ">), iterable.collect(function, Sets.mutable.empty())); |
| 581 |
Assert.assertEquals(Lists.mutable.empty(), this.newWith().collect(function, Lists.mutable.empty())); |
| 582 |
Assert.assertEquals(Lists.mutable.with(<(literal.(type))("2")>), this.newWith(<(literal.(type))("3")>).collect(function, Lists.mutable.empty())); |
| 583 |
} |
| 584 |
|
| 585 |
@Test |
| 586 |
public void flatCollectWithTarget() |
| 587 |
{ |
| 588 |
<name>ToObjectFunction\<List\<<wrapperName>\>> function = parameter -> Lists.mutable.with(<(castIntToNarrowTypeWithParens.(type))("parameter - 1")>); |
| 589 |
Assert.assertEquals(Bags.mutable.with(<["0", "1", "2"]:(literal.(type))(); separator=", ">), this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">).flatCollect(function, Bags.mutable.empty())); |
| 590 |
<name>Iterable iterable = this.newWith(<["1", "2", "2", "3", "3", "3"]:(literal.(type))(); separator=", ">); |
| 591 |
Assert.assertEquals(Sets.mutable.with(<["0", "1", "2"]:(literal.(type))(); separator=", ">), iterable.flatCollect(function, Sets.mutable.empty())); |
| 592 |
Assert.assertEquals(Lists.mutable.empty(), this.newWith().flatCollect(function, Lists.mutable.empty())); |
| 593 |
Assert.assertEquals(Lists.mutable.with(<(literal.(type))("2")>), this.newWith(<(literal.(type))("3")>).flatCollect(function, Lists.mutable.empty())); |
| 594 |
} |
| 595 |
|
| 596 |
@Test |
| 597 |
public void flatCollectIterableWithTarget() |
| 598 |
{ |
| 599 |
<name>ToObjectFunction\<Iterable\<<wrapperName>\>> function = parameter -> Lists.mutable.with(<(castIntToNarrowTypeWithParens.(type))("parameter - 1")>).asLazy(); |
| 600 |
Assert.assertEquals(Bags.mutable.with(<["0", "1", "2"]:(literal.(type))(); separator=", ">), this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">).flatCollect(function, Bags.mutable.empty())); |
| 601 |
<name>Iterable iterable = this.newWith(<["1", "2", "2", "3", "3", "3"]:(literal.(type))(); separator=", ">); |
| 602 |
Assert.assertEquals(Sets.mutable.with(<["0", "1", "2"]:(literal.(type))(); separator=", ">), iterable.flatCollect(function, Sets.mutable.empty())); |
| 603 |
Assert.assertEquals(Lists.mutable.empty(), this.newWith().flatCollect(function, Lists.mutable.empty())); |
| 604 |
Assert.assertEquals(Lists.mutable.with(<(literal.(type))("2")>), this.newWith(<(literal.(type))("3")>).flatCollect(function, Lists.mutable.empty())); |
| 605 |
} |
| 606 |
|
| 607 |
@Test |
| 608 |
public void collectPrimitivesToLists() |
| 609 |
{ |
| 610 |
<name>Iterable iterable = this.newWith(<["1", "2"]:(literal.(type))(); separator=", ">); |
| 611 |
Assert.assertEquals( |
| 612 |
BooleanLists.mutable.with(true, true), |
| 613 |
iterable.collectBoolean(each -> true, BooleanLists.mutable.empty())); |
| 614 |
Assert.assertEquals( |
| 615 |
ByteLists.mutable.with((byte) 1, (byte) 1), |
| 616 |
iterable.collectByte(each -> (byte) 1, ByteLists.mutable.empty())); |
| 617 |
Assert.assertEquals( |
| 618 |
CharLists.mutable.with('a', 'a'), |
| 619 |
iterable.collectChar(each -> 'a', CharLists.mutable.empty())); |
| 620 |
Assert.assertEquals( |
| 621 |
ShortLists.mutable.with((short) 1, (short) 1), |
| 622 |
iterable.collectShort(each -> (short) 1, ShortLists.mutable.empty())); |
| 623 |
Assert.assertEquals( |
| 624 |
IntLists.mutable.with(1, 1), |
| 625 |
iterable.collectInt(each -> 1, IntLists.mutable.empty())); |
| 626 |
Assert.assertEquals( |
| 627 |
FloatLists.mutable.with(1.0f, 1.0f), |
| 628 |
iterable.collectFloat(each -> 1.0f, FloatLists.mutable.empty())); |
| 629 |
Assert.assertEquals( |
| 630 |
LongLists.mutable.with(1L, 1L), |
| 631 |
iterable.collectLong(each -> 1L, LongLists.mutable.empty())); |
| 632 |
Assert.assertEquals( |
| 633 |
DoubleLists.mutable.with(1.0d, 1.0d), |
| 634 |
iterable.collectDouble(each -> 1.0d, DoubleLists.mutable.empty())); |
| 635 |
} |
| 636 |
|
| 637 |
@Test |
| 638 |
public void collectPrimitivesToSets() |
| 639 |
{ |
| 640 |
<name>Iterable iterable = this.newWith(<["1", "2"]:(literal.(type))(); separator=", ">); |
| 641 |
Assert.assertEquals( |
| 642 |
BooleanSets.mutable.with(false), |
| 643 |
iterable.collectBoolean(each -> false, BooleanSets.mutable.empty())); |
| 644 |
Assert.assertEquals( |
| 645 |
ByteSets.mutable.with((byte) 2), |
| 646 |
iterable.collectByte(each -> (byte) 2, ByteSets.mutable.empty())); |
| 647 |
Assert.assertEquals( |
| 648 |
CharSets.mutable.with('b'), |
| 649 |
iterable.collectChar(each -> 'b', CharSets.mutable.empty())); |
| 650 |
Assert.assertEquals( |
| 651 |
ShortSets.mutable.with((short) 2), |
| 652 |
iterable.collectShort(each -> (short) 2, ShortSets.mutable.empty())); |
| 653 |
Assert.assertEquals( |
| 654 |
IntSets.mutable.with(2), |
| 655 |
iterable.collectInt(each -> 2, IntSets.mutable.empty())); |
| 656 |
Assert.assertEquals( |
| 657 |
FloatSets.mutable.with(2.0f), |
| 658 |
iterable.collectFloat(each -> 2.0f, FloatSets.mutable.empty())); |
| 659 |
Assert.assertEquals( |
| 660 |
LongSets.mutable.with(2L), |
| 661 |
iterable.collectLong(each -> 2L, LongSets.mutable.empty())); |
| 662 |
Assert.assertEquals( |
| 663 |
DoubleSets.mutable.with(2.0d), |
| 664 |
iterable.collectDouble(each -> 2.0d, DoubleSets.mutable.empty())); |
| 665 |
} |
| 666 |
|
| 667 |
@Test |
| 668 |
public void select() |
| 669 |
{ |
| 670 |
<name>Iterable iterable = this.classUnderTest(); |
| 671 |
int size = iterable.size(); |
| 672 |
Verify.assertSize(size >= 3 ? 3 : size, iterable.select(<name>Predicates.lessThan(<(literal.(type))("4")>))); |
| 673 |
Verify.assertSize(size >= 2 ? 2 : size, iterable.select(<name>Predicates.lessThan(<(literal.(type))("3")>))); |
| 674 |
<name>Iterable iterable1 = this.newWith(<["0", "1", "2", "2", "3", "3", "3"]:(literal.(type))(); separator=", ">); |
| 675 |
Assert.assertEquals(this.newMutableCollectionWith(<["0", "1"]:(literal.(type))(); separator=", ">), iterable1.select(<name>Predicates.lessThan(<(literal.(type))("2")>))); |
| 676 |
Assert.assertEquals(this.newMutableCollectionWith(<["2", "2", "3", "3", "3"]:(literal.(type))(); separator=", ">), iterable1.select(<name>Predicates.greaterThan(<(literal.(type))("1")>))); |
| 677 |
|
| 678 |
<name>Iterable iterable2 = this.newWith(<["0"]:(literal.(type))(); separator=", ">); |
| 679 |
Verify.assertSize(iterable2.size() == 1 ? 1 : 0, iterable2.select(<name>Predicates.alwaysTrue())); |
| 680 |
Verify.assertSize(0, iterable2.select(<name>Predicates.alwaysFalse())); |
| 681 |
} |
| 682 |
|
| 683 |
@Test |
| 684 |
public void selectWithTarget() |
| 685 |
{ |
| 686 |
<name>Iterable iterable = this.classUnderTest(); |
| 687 |
int size = iterable.size(); |
| 688 |
Verify.assertSize(size >= 3 ? 3 : size, iterable.select(<name>Predicates.lessThan(<(literal.(type))("4")>), <name>Sets.mutable.empty())); |
| 689 |
Verify.assertSize(size >= 2 ? 2 : size, iterable.select(<name>Predicates.lessThan(<(literal.(type))("3")>), <name>Sets.mutable.empty())); |
| 690 |
<name>Iterable iterable1 = this.newWith(<["0", "1", "2", "2", "3", "3", "3"]:(literal.(type))(); separator=", ">); |
| 691 |
Assert.assertEquals(<name>Sets.mutable.with(<["0", "1"]:(literal.(type))(); separator=", ">), iterable1.select(<name>Predicates.lessThan(<(literal.(type))("2")>), <name>Sets.mutable.empty())); |
| 692 |
Assert.assertEquals(<name>Sets.mutable.with(<["2", "3"]:(literal.(type))(); separator=", ">), iterable1.select(<name>Predicates.greaterThan(<(literal.(type))("1")>), <name>Sets.mutable.empty())); |
| 693 |
} |
| 694 |
|
| 695 |
@Test |
| 696 |
public void reject() |
| 697 |
{ |
| 698 |
<name>Iterable iterable = this.classUnderTest(); |
| 699 |
int size = iterable.size(); |
| 700 |
Verify.assertSize(size \<= 3 ? 0 : size - 3, iterable.reject(<name>Predicates.lessThan(<(literal.(type))("4")>))); |
| 701 |
Verify.assertSize(size \<= 2 ? 0 : size - 2, iterable.reject(<name>Predicates.lessThan(<(literal.(type))("3")>))); |
| 702 |
<name>Iterable iterable1 = this.newWith(<["0", "1", "2", "2", "3", "3", "3"]:(literal.(type))(); separator=", ">); |
| 703 |
Assert.assertEquals(this.newMutableCollectionWith(<["2", "2", "3", "3", "3"]:(literal.(type))(); separator=", ">), iterable1.reject(<name>Predicates.lessThan(<(literal.(type))("2")>))); |
| 704 |
Assert.assertEquals(this.newMutableCollectionWith(<["0", "1"]:(literal.(type))(); separator=", ">), iterable1.reject(<name>Predicates.greaterThan(<(literal.(type))("1")>))); |
| 705 |
|
| 706 |
<name>Iterable iterable2 = this.newWith(<["0"]:(literal.(type))(); separator=", ">); |
| 707 |
Verify.assertSize(iterable2.size() == 1 ? 1 : 0, iterable2.reject(<name>Predicates.alwaysFalse())); |
| 708 |
Verify.assertSize(0, iterable2.reject(<name>Predicates.alwaysTrue())); |
| 709 |
} |
| 710 |
|
| 711 |
@Test |
| 712 |
public void rejectWithTarget() |
| 713 |
{ |
| 714 |
<name>Iterable iterable = this.classUnderTest(); |
| 715 |
int size = iterable.size(); |
| 716 |
Verify.assertSize(size \<= 3 ? 0 : size - 3, iterable.reject(<name>Predicates.lessThan(<(literal.(type))("4")>), <name>Sets.mutable.empty())); |
| 717 |
Verify.assertSize(size \<= 2 ? 0 : size - 2, iterable.reject(<name>Predicates.lessThan(<(literal.(type))("3")>), <name>Sets.mutable.empty())); |
| 718 |
<name>Iterable iterable1 = this.newWith(<["0", "1", "2", "2", "3", "3", "3"]:(literal.(type))(); separator=", ">); |
| 719 |
Assert.assertEquals(<name>Sets.mutable.with(<["2", "3"]:(literal.(type))(); separator=", ">), iterable1.reject(<name>Predicates.lessThan(<(literal.(type))("2")>), <name>Sets.mutable.empty())); |
| 720 |
Assert.assertEquals(<name>Sets.mutable.with(<["0", "1"]:(literal.(type))(); separator=", ">), iterable1.reject(<name>Predicates.greaterThan(<(literal.(type))("1")>), <name>Sets.mutable.empty())); |
| 721 |
} |
| 722 |
|
| 723 |
@Test |
| 724 |
public void detectIfNone() |
| 725 |
{ |
| 726 |
<name>Iterable iterable = this.classUnderTest(); |
| 727 |
int size = iterable.size(); |
| 728 |
Assert.assertEquals(size >= 4 ? <(wideLiteral.(type))("4")> : <(wideLiteral.(type))("0")>, iterable.detectIfNone(<name>Predicates.equal(<(literal.(type))("4")>), <(literal.(type))("0")>)<(wideDelta.(type))>); |
| 729 |
Assert.assertEquals(size >= 2 ? <(wideLiteral.(type))("2")> : <(wideLiteral.(type))("0")>, iterable.detectIfNone(<name>Predicates.equal(<(literal.(type))("2")>), <(literal.(type))("0")>)<(wideDelta.(type))>); |
| 730 |
Assert.assertEquals(size > 0 ? <(wideLiteral.(type))("1")> : <(wideLiteral.(type))("0")>, iterable.detectIfNone(<name>Predicates.lessThan(<(literal.(type))("2")>), <(literal.(type))("0")>)<(wideDelta.(type))>); |
| 731 |
Assert.assertEquals(size > 3 ? <(wideLiteral.(type))("4")> : <(wideLiteral.(type))("0")>, iterable.detectIfNone(<name>Predicates.greaterThan(<(literal.(type))("3")>), <(literal.(type))("0")>)<(wideDelta.(type))>); |
| 732 |
|
| 733 |
<name>Iterable iterable1 = this.newWith(<["0", "1", "2", "2", "3", "3", "3"]:(literal.(type))(); separator=", ">); |
| 734 |
Assert.assertEquals(<(wideLiteral.(type))("0")>, iterable1.detectIfNone(<name>Predicates.lessThan(<(literal.(type))("1")>), <(literal.(type))("4")>)<(delta.(type))>); |
| 735 |
Assert.assertEquals(<(wideLiteral.(type))("3")>, iterable1.detectIfNone(<name>Predicates.greaterThan(<(literal.(type))("2")>), <(literal.(type))("4")>)<(delta.(type))>); |
| 736 |
Assert.assertEquals(<(wideLiteral.(type))("4")>, iterable1.detectIfNone(<name>Predicates.greaterThan(<(literal.(type))("4")>), <(literal.(type))("4")>)<(delta.(type))>); |
| 737 |
} |
| 738 |
|
| 739 |
@Test |
| 740 |
public void max() |
| 741 |
{ |
| 742 |
<(maxTests.(type))(type, name)> |
| 743 |
} |
| 744 |
|
| 745 |
@Test(expected = NoSuchElementException.class) |
| 746 |
public void max_throws_emptyCollection() |
| 747 |
{ |
| 748 |
this.newWith().max(); |
| 749 |
} |
| 750 |
|
| 751 |
@Test |
| 752 |
public void min() |
| 753 |
{ |
| 754 |
<(minTests.(type))(type, name)> |
| 755 |
} |
| 756 |
|
| 757 |
@Test(expected = NoSuchElementException.class) |
| 758 |
public void min_throws_emptyCollection() |
| 759 |
{ |
| 760 |
this.newWith().min(); |
| 761 |
} |
| 762 |
|
| 763 |
@Test |
| 764 |
public void minIfEmpty() |
| 765 |
{ |
| 766 |
Assert.assertEquals(<(wideLiteral.(type))("5")>, this.newWith().minIfEmpty(<(literal.(type))("5")>)<(wideDelta.(type))>); |
| 767 |
Assert.assertEquals(<(wideLiteral.(type))("0")>, this.newWith().minIfEmpty(<(literal.(type))("0")>)<(wideDelta.(type))>); |
| 768 |
Assert.assertEquals(<(wideLiteral.(type))("0")>, this.newWith(<["1", "0", "9", "7"]:(literal.(type))(); separator=", ">).minIfEmpty(<(literal.(type))("5")>)<(wideDelta.(type))>); |
| 769 |
int size = this.classUnderTest().size(); |
| 770 |
Assert.assertEquals(size == 0 ? <(literal.(type))("5")> : <(literal.(type))("1")>, this.classUnderTest().minIfEmpty(<(literal.(type))("5")>)<(wideDelta.(type))>); |
| 771 |
} |
| 772 |
|
| 773 |
@Test |
| 774 |
public void maxIfEmpty() |
| 775 |
{ |
| 776 |
Assert.assertEquals(<(wideLiteral.(type))("5")>, this.newWith().maxIfEmpty(<(literal.(type))("5")>)<(wideDelta.(type))>); |
| 777 |
Assert.assertEquals(<(wideLiteral.(type))("0")>, this.newWith().maxIfEmpty(<(literal.(type))("0")>)<(wideDelta.(type))>); |
| 778 |
Assert.assertEquals(<(wideLiteral.(type))("9")>, this.newWith(<["1", "0", "9", "7"]:(literal.(type))(); separator=", ">).maxIfEmpty(<(literal.(type))("5")>)<(wideDelta.(type))>); |
| 779 |
int size = this.classUnderTest().size(); |
| 780 |
Assert.assertEquals(size == 0 ? <(literal.(type))("5")> : size, this.classUnderTest().maxIfEmpty(<(literal.(type))("5")>)<(wideDelta.(type))>); |
| 781 |
} |
| 782 |
|
| 783 |
@Test |
| 784 |
public void sum() |
| 785 |
{ |
| 786 |
int size = this.classUnderTest().size(); |
| 787 |
long sum = (long) ((size * (size + 1)) / 2); |
| 788 |
Assert.assertEquals(sum, this.classUnderTest().sum()<(wideDelta.(type))>); |
| 789 |
Assert.assertEquals(<(wideLiteral.(type))("10")>, this.newWith(<["0", "1", "2", "3", "4"]:(literal.(type))(); separator=", ">).sum()<(wideDelta.(type))>); |
| 790 |
Assert.assertEquals(<(wideLiteral.(type))("93")>, this.newWith(<["30", "31", "32"]:(literal.(type))(); separator=", ">).sum()<wideDelta.(type)>); |
| 791 |
} |
| 792 |
|
| 793 |
@Test |
| 794 |
public void summaryStatistics() |
| 795 |
{ |
| 796 |
int size = this.classUnderTest().size(); |
| 797 |
long sum = (long) ((size * (size + 1)) / 2); |
| 798 |
Assert.assertEquals(sum, this.classUnderTest().summaryStatistics().getSum()<(wideDelta.(type))>); |
| 799 |
Assert.assertEquals(<(wideLiteral.(type))("10")>, this.newWith(<["0", "1", "2", "3", "4"]:(literal.(type))(); separator=", ">).summaryStatistics().getSum()<(wideDelta.(type))>); |
| 800 |
Assert.assertEquals(<(wideLiteral.(type))("93")>, this.newWith(<["30", "31", "32"]:(literal.(type))(); separator=", ">).summaryStatistics().getSum()<wideDelta.(type)>); |
| 801 |
} |
| 802 |
|
| 803 |
<if(primitive.floatPrimitive)>@Test |
| 804 |
public void sumConsistentRounding() |
| 805 |
{ |
| 806 |
<name>Iterable iterable = this.newWith(Interval.oneTo(100_000) |
| 807 |
.toList() |
| 808 |
.shuffleThis() |
| 809 |
.collect<name>(i -> 1.0f / (i.floatValue() * i.floatValue() * i.floatValue() * i.floatValue())) |
| 810 |
.toArray()); |
| 811 |
|
| 812 |
// The test only ensures the consistency/stability of rounding. This is not meant to test the "correctness" of the float calculation result. |
| 813 |
// Indeed the lower bits of this calculation result are always incorrect due to the information loss of original float values. |
| 814 |
Assert.assertEquals( |
| 815 |
1.082323233761663, |
| 816 |
iterable.sum(), |
| 817 |
1.0e-15); |
| 818 |
} |
| 819 |
|
| 820 |
<elseif(primitive.doublePrimitive)>@Test |
| 821 |
public void sumConsistentRounding() |
| 822 |
{ |
| 823 |
<name>Iterable iterable = this.newWith(Interval.oneTo(100_000) |
| 824 |
.toList() |
| 825 |
.shuffleThis() |
| 826 |
.collect<name>(i -> <["1.0"]:(decimalLiteral.(type))()> / (i.<type>Value() * i.<type>Value() * i.<type>Value() * i.<type>Value())) |
| 827 |
.toArray()); |
| 828 |
|
| 829 |
Assert.assertEquals( |
| 830 |
1.082323233711138, |
| 831 |
iterable.sum(), |
| 832 |
1.0e-15); |
| 833 |
} |
| 834 |
|
| 835 |
<endif> |
| 836 |
@Test |
| 837 |
public void average() |
| 838 |
{ |
| 839 |
int size = this.classUnderTest().size(); |
| 840 |
long sum = (long) ((size * (size + 1)) / 2); |
| 841 |
double average = sum / size; |
| 842 |
Assert.assertEquals(average, this.classUnderTest().average(), 0.0); |
| 843 |
Assert.assertEquals(2.5, this.newWith(<["1", "2", "3", "4"]:(literal.(type))(); separator=", ">).average(), 0.0); |
| 844 |
Assert.assertEquals(2.5, this.newWith(<["1", "2", "3", "4"]:(literal.(type))(); separator=", ">).average(), 0.0); |
| 845 |
Assert.assertEquals(31.0, this.newWith(<["30", "30", "31", "31", "32", "32"]:(literal.(type))(); separator=", ">).average(), 0.0); |
| 846 |
} |
| 847 |
|
| 848 |
@Test(expected = ArithmeticException.class) |
| 849 |
public void averageThrowsOnEmpty() |
| 850 |
{ |
| 851 |
this.newWith().average(); |
| 852 |
} |
| 853 |
|
| 854 |
/** |
| 855 |
* @since 9.0 |
| 856 |
*/ |
| 857 |
@Test |
| 858 |
public void averageIfEmpty() |
| 859 |
{ |
| 860 |
Assert.assertEquals(2.5, this.newWith().averageIfEmpty(2.5), 0.0); |
| 861 |
int size = this.classUnderTest().size(); |
| 862 |
long sum = (long) ((size * (size + 1)) / 2); |
| 863 |
double average = sum / size; |
| 864 |
Assert.assertEquals(average, this.classUnderTest().averageIfEmpty(0.0), 0.0); |
| 865 |
Assert.assertEquals(2.5, this.newWith(<["1", "2", "3", "4"]:(literal.(type))(); separator=", ">).averageIfEmpty(0.0), 0.0); |
| 866 |
Assert.assertEquals(2.5, this.newWith(<["1", "2", "3", "4"]:(literal.(type))(); separator=", ">).averageIfEmpty(0.0), 0.0); |
| 867 |
Assert.assertEquals(31.0, this.newWith(<["30", "30", "31", "31", "32", "32"]:(literal.(type))(); separator=", ">).averageIfEmpty(0.0), 0.0); |
| 868 |
} |
| 869 |
|
| 870 |
@Test |
| 871 |
public void median() |
| 872 |
{ |
| 873 |
Assert.assertEquals(1.0, this.newWith(<["1"]:(literal.(type))(); separator=", ">).median(), 0.0); |
| 874 |
Assert.assertEquals(2.5, this.newWith(<["1", "2", "3", "4"]:(literal.(type))(); separator=", ">).median(), 0.0); |
| 875 |
Assert.assertEquals(3.0, this.newWith(<["1", "2", "3", "4", "5"]:(literal.(type))(); separator=", ">).median(), 0.0); |
| 876 |
Assert.assertEquals(31.0, this.newWith(<["30", "30", "31", "31", "32"]:(literal.(type))(); separator=", ">).median(), 0.0); |
| 877 |
Assert.assertEquals(30.5, this.newWith(<["1", "30", "30", "31", "31", "32"]:(literal.(type))(); separator=", ">).median(), 0.0); |
| 878 |
} |
| 879 |
|
| 880 |
@Test(expected = ArithmeticException.class) |
| 881 |
public void medianThrowsOnEmpty() |
| 882 |
{ |
| 883 |
this.newWith().median(); |
| 884 |
} |
| 885 |
|
| 886 |
/** |
| 887 |
* @since 9.0 |
| 888 |
*/ |
| 889 |
@Test |
| 890 |
public void medianIfEmpty() |
| 891 |
{ |
| 892 |
Assert.assertEquals(2.5, this.newWith().medianIfEmpty(2.5), 0.0); |
| 893 |
Assert.assertEquals(1.0, this.newWith(<["1"]:(literal.(type))(); separator=", ">).medianIfEmpty(0.0), 0.0); |
| 894 |
Assert.assertEquals(2.5, this.newWith(<["1", "2", "3", "4"]:(literal.(type))(); separator=", ">).medianIfEmpty(0.0), 0.0); |
| 895 |
Assert.assertEquals(3.0, this.newWith(<["1", "2", "3", "4", "5"]:(literal.(type))(); separator=", ">).medianIfEmpty(0.0), 0.0); |
| 896 |
Assert.assertEquals(31.0, this.newWith(<["30", "30", "31", "31", "32"]:(literal.(type))(); separator=", ">).medianIfEmpty(0.0), 0.0); |
| 897 |
Assert.assertEquals(30.5, this.newWith(<["1", "30", "30", "31", "31", "32"]:(literal.(type))(); separator=", ">).medianIfEmpty(0.0), 0.0); |
| 898 |
} |
| 899 |
|
| 900 |
@Test |
| 901 |
public void toArray() |
| 902 |
{ |
| 903 |
Assert.assertEquals(this.classUnderTest().size(), this.classUnderTest().toArray().length); |
| 904 |
<name>Iterable iterable = this.newWith(<["1", "2"]:(literal.(type))(); separator=", ">); |
| 905 |
Assert.assertTrue(Arrays.equals(new <type>[]{<["1", "2"]:(literal.(type))(); separator=", ">}, iterable.toArray()) |
| 906 |
|| Arrays.equals(new <type>[]{<["2", "1"]:(literal.(type))(); separator=", ">}, iterable.toArray())); |
| 907 |
Assert.assertTrue(Arrays.equals(new <type>[]{<["0", "1"]:(literal.(type))(); separator=", ">}, this.newWith(<["0", "1"]:(literal.(type))(); separator=", ">).toArray()) |
| 908 |
|| Arrays.equals(new <type>[]{<["1", "0"]:(literal.(type))(); separator=", ">}, this.newWith(<["0", "1"]:(literal.(type))(); separator=", ">).toArray())); |
| 909 |
Assert.assertTrue(Arrays.equals(new <type>[]{<["1", "31"]:(literal.(type))(); separator=", ">}, this.newWith(<["1", "31"]:(literal.(type))(); separator=", ">).toArray()) |
| 910 |
|| Arrays.equals(new <type>[]{<["31", "1"]:(literal.(type))(); separator=", ">}, this.newWith(<["1", "31"]:(literal.(type))(); separator=", ">).toArray())); |
| 911 |
Assert.assertTrue(Arrays.equals(new <type>[]{<["31", "35"]:(literal.(type))(); separator=", ">}, this.newWith(<["31", "35"]:(literal.(type))(); separator=", ">).toArray()) |
| 912 |
|| Arrays.equals(new <type>[]{<["35", "31"]:(literal.(type))(); separator=", ">}, this.newWith(<["31", "35"]:(literal.(type))(); separator=", ">).toArray())); |
| 913 |
Assert.assertArrayEquals(new <type>[]{}, this.newWith().toArray()<(delta.(type))>); |
| 914 |
Assert.assertArrayEquals(new <type>[]{<(literal.(type))("32")>}, this.newWith(<(literal.(type))("32")>).toArray()<(delta.(type))>); |
| 915 |
} |
| 916 |
|
| 917 |
@Test |
| 918 |
public void toArrayWithTargetArray() |
| 919 |
{ |
| 920 |
<type>[] originalAsSortedArray = this.classUnderTest().toSortedArray(); |
| 921 |
|
| 922 |
<type>[] target = new <type>[this.classUnderTest().size()]; |
| 923 |
|
| 924 |
Assert.assertSame(target, this.classUnderTest().toArray(target)); |
| 925 |
Arrays.sort(target); |
| 926 |
Assert.assertTrue(Arrays.equals(originalAsSortedArray, target)); |
| 927 |
|
| 928 |
if (this.classUnderTest().size() > 0) |
| 929 |
{ |
| 930 |
<type>[] targetTooSmall = new <type>[this.classUnderTest().size() - 1]; |
| 931 |
<type>[] result = this.classUnderTest().toArray(targetTooSmall); |
| 932 |
Assert.assertNotSame(targetTooSmall, result); |
| 933 |
Arrays.sort(result); |
| 934 |
Assert.assertTrue(Arrays.equals(this.classUnderTest().toSortedArray(), result)); |
| 935 |
} |
| 936 |
|
| 937 |
<type>[] targetTooBig = new <type>[this.classUnderTest().size() + 1]; |
| 938 |
<type>[] bigResult = this.classUnderTest().toArray(targetTooBig); |
| 939 |
Assert.assertSame(targetTooBig, bigResult); |
| 940 |
Arrays.sort(targetTooBig); |
| 941 |
for (int i = 0; i \< originalAsSortedArray.length; i++) |
| 942 |
{ |
| 943 |
Assert.assertEquals(originalAsSortedArray[i], bigResult[i + 1]<(delta.(type))>); |
| 944 |
} |
| 945 |
} |
| 946 |
|
| 947 |
@Test |
| 948 |
public void toSortedArray() |
| 949 |
{ |
| 950 |
<name>Iterable iterable = this.classUnderTest(); |
| 951 |
int size = iterable.size(); |
| 952 |
<type>[] array = new <type>[size]; |
| 953 |
for (int i = 0; i \< size; i++) |
| 954 |
{ |
| 955 |
array[i] = <(castIntToNarrowTypeWithParens.(type))("i + 1")>; |
| 956 |
} |
| 957 |
|
| 958 |
Assert.assertArrayEquals(array, iterable.toSortedArray()<(delta.(type))>); |
| 959 |
Assert.assertArrayEquals(new <type>[]{<["1", "3", "7", "9"]:(literal.(type))(); separator=", ">}, |
| 960 |
this.newWith(<["3", "1", "9", "7"]:(literal.(type))(); separator=", ">).toSortedArray()<(delta.(type))>); |
| 961 |
} |
| 962 |
|
| 963 |
@Test |
| 964 |
public void testEquals() |
| 965 |
{ |
| 966 |
<name>Iterable iterable1 = this.newWith(<["1", "2", "3", "4"]:(literal.(type))(); separator=", ">); |
| 967 |
<name>Iterable iterable2 = this.newWith(<["1", "2", "3", "4"]:(literal.(type))(); separator=", ">); |
| 968 |
<name>Iterable iterable3 = this.newWith(<["5", "6", "7", "8"]:(literal.(type))(); separator=", ">); |
| 969 |
<name>Iterable iterable4 = this.newWith(<["5", "6", "7"]:(literal.(type))(); separator=", ">); |
| 970 |
<name>Iterable iterable5 = this.newWith(<["0", "1", "1", "2", "2", "2"]:(literal.(type))(); separator=", ">); |
| 971 |
<name>Iterable iterable6 = this.newWith(<["1", "31", "32"]:(literal.(type))(); separator=", ">); |
| 972 |
<name>Iterable iterable7 = this.newWith(<["35", "31", "1"]:(literal.(type))(); separator=", ">); |
| 973 |
<name>Iterable iterable8 = this.newWith(<["32", "31", "1", "50"]:(literal.(type))(); separator=", ">); |
| 974 |
<name>Iterable iterable9 = this.newWith(<["0", "1", "2"]:(literal.(type))(); separator=", ">); |
| 975 |
<name>Iterable iterable10 = this.newWith(<["0", "1", "3"]:(literal.(type))(); separator=", ">); |
| 976 |
<name>Iterable iterable11 = this.newWith(<["3", "1", "2"]:(literal.(type))(); separator=", ">); |
| 977 |
<name>Iterable iterable12 = this.newWith(<["3"]:(literal.(type))(); separator=", ">); |
| 978 |
|
| 979 |
Verify.assertEqualsAndHashCode(iterable1, iterable2); |
| 980 |
Verify.assertPostSerializedEqualsAndHashCode(iterable1); |
| 981 |
Verify.assertPostSerializedEqualsAndHashCode(iterable12); |
| 982 |
Verify.assertPostSerializedEqualsAndHashCode(iterable5); |
| 983 |
Verify.assertPostSerializedEqualsAndHashCode(iterable6); |
| 984 |
Assert.assertNotEquals(iterable12, iterable11); |
| 985 |
Assert.assertNotEquals(iterable1, iterable3); |
| 986 |
Assert.assertNotEquals(iterable1, iterable4); |
| 987 |
Assert.assertNotEquals(iterable6, iterable7); |
| 988 |
Assert.assertNotEquals(iterable6, iterable8); |
| 989 |
Assert.assertNotEquals(iterable9, iterable10); |
| 990 |
Assert.assertNotEquals(iterable9, iterable11); |
| 991 |
Assert.assertNotEquals(this.newWith(), this.newWith(<(literal.(type))("100")>)); |
| 992 |
} |
| 993 |
|
| 994 |
@Test |
| 995 |
public void testHashCode() |
| 996 |
{ |
| 997 |
Assert.assertEquals(this.newObjectCollectionWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">).hashCode(), this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">).hashCode()); |
| 998 |
Assert.assertEquals(this.newObjectCollectionWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">).hashCode(), this.newWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">).hashCode()); |
| 999 |
Assert.assertEquals(this.newObjectCollectionWith(<["32"]:(literal.(type))(); separator=", ">).hashCode(), this.newWith(<["32"]:(literal.(type))(); separator=", ">).hashCode()); |
| 1000 |
Assert.assertNotEquals(this.newObjectCollectionWith(<["32"]:(literal.(type))(); separator=", ">).hashCode(), this.newWith(<["0"]:(literal.(type))(); separator=", ">).hashCode()); |
| 1001 |
Assert.assertEquals(this.newObjectCollectionWith(<["31", "32", "50"]:(literal.(type))(); separator=", ">).hashCode(), this.newWith(<["31", "32", "50"]:(literal.(type))(); separator=", ">).hashCode()); |
| 1002 |
Assert.assertEquals(this.newObjectCollectionWith(<["32", "50", "60"]:(literal.(type))(); separator=", ">).hashCode(), this.newWith(<["32", "50", "60"]:(literal.(type))(); separator=", ">).hashCode()); |
| 1003 |
Assert.assertEquals(this.newObjectCollectionWith().hashCode(), this.newWith().hashCode()); |
| 1004 |
} |
| 1005 |
|
| 1006 |
@Test |
| 1007 |
public void testToString() |
| 1008 |
{ |
| 1009 |
Assert.assertEquals("[]", this.newWith().toString()); |
| 1010 |
Assert.assertEquals("[<(toStringLiteral.(type))("1")>]", this.newWith(<(literal.(type))("1")>).toString()); |
| 1011 |
Assert.assertEquals("[<(toStringLiteral.(type))("31")>]", this.newWith(<(literal.(type))("31")>).toString()); |
| 1012 |
Assert.assertEquals("[<(toStringLiteral.(type))("32")>]", this.newWith(<(literal.(type))("32")>).toString()); |
| 1013 |
|
| 1014 |
<name>Iterable iterable = this.newWith(<["1", "2"]:(literal.(type))(); separator=", ">); |
| 1015 |
Assert.assertTrue("[<["1", "2"]:(toStringLiteral.(type))(); separator=", ">]".equals(iterable.toString()) |
| 1016 |
|| "[<["2", "1"]:(toStringLiteral.(type))(); separator=", ">]".equals(iterable.toString())); |
| 1017 |
|
| 1018 |
<name>Iterable iterable1 = this.newWith(<["0", "31"]:(literal.(type))(); separator=", ">); |
| 1019 |
Assert.assertTrue( |
| 1020 |
iterable1.toString(), |
| 1021 |
iterable1.toString().equals("[<["0", "31"]:(toStringLiteral.(type))(); separator=", ">]") |
| 1022 |
|| iterable1.toString().equals("[<["31", "0"]:(toStringLiteral.(type))(); separator=", ">]")); |
| 1023 |
|
| 1024 |
<name>Iterable iterable2 = this.newWith(<["31", "32"]:(literal.(type))(); separator=", ">); |
| 1025 |
Assert.assertTrue( |
| 1026 |
iterable2.toString(), |
| 1027 |
iterable2.toString().equals("[<["31", "32"]:(toStringLiteral.(type))(); separator=", ">]") |
| 1028 |
|| iterable2.toString().equals("[<["32", "31"]:(toStringLiteral.(type))(); separator=", ">]")); |
| 1029 |
|
| 1030 |
<name>Iterable iterable3 = this.newWith(<["32", "33"]:(literal.(type))(); separator=", ">); |
| 1031 |
Assert.assertTrue( |
| 1032 |
iterable3.toString(), |
| 1033 |
iterable3.toString().equals("[<["32", "33"]:(toStringLiteral.(type))(); separator=", ">]") |
| 1034 |
|| iterable3.toString().equals("[<["33", "32"]:(toStringLiteral.(type))(); separator=", ">]")); |
| 1035 |
|
| 1036 |
<name>Iterable iterable4 = this.newWith(<["0", "1"]:(literal.(type))(); separator=", ">); |
| 1037 |
Assert.assertTrue( |
| 1038 |
iterable4.toString(), |
| 1039 |
iterable4.toString().equals("[<["0", "1"]:(toStringLiteral.(type))(); separator=", ">]") |
| 1040 |
|| iterable4.toString().equals("[<["1", "0"]:(toStringLiteral.(type))(); separator=", ">]")); |
| 1041 |
} |
| 1042 |
|
| 1043 |
@Test |
| 1044 |
public void makeString() |
| 1045 |
{ |
| 1046 |
<name>Iterable iterable = this.classUnderTest(); |
| 1047 |
Assert.assertEquals("<(toStringLiteral.(type))("1")>", this.newWith(<(literal.(type))("1")>).makeString("/")); |
| 1048 |
Assert.assertEquals("<(toStringLiteral.(type))("31")>", this.newWith(<(literal.(type))("31")>).makeString()); |
| 1049 |
Assert.assertEquals("<(toStringLiteral.(type))("32")>", this.newWith(<(literal.(type))("32")>).makeString()); |
| 1050 |
Assert.assertEquals(iterable.toString(), iterable.makeString("[", ", ", "]")); |
| 1051 |
Assert.assertEquals("", this.newWith().makeString()); |
| 1052 |
Assert.assertEquals("", this.newWith().makeString("/")); |
| 1053 |
Assert.assertEquals("[]", this.newWith().makeString("[", ", ", "]")); |
| 1054 |
|
| 1055 |
<name>Iterable iterable1 = this.newWith(<["0", "31"]:(literal.(type))(); separator=", ">); |
| 1056 |
Assert.assertTrue( |
| 1057 |
iterable1.makeString(), |
| 1058 |
iterable1.makeString().equals("<["0", "31"]:(toStringLiteral.(type))(); separator=", ">") |
| 1059 |
|| iterable1.makeString().equals("<["31", "0"]:(toStringLiteral.(type))(); separator=", ">")); |
| 1060 |
|
| 1061 |
<name>Iterable iterable2 = this.newWith(<["31", "32"]:(literal.(type))(); separator=", ">); |
| 1062 |
Assert.assertTrue( |
| 1063 |
iterable2.makeString("[", "/", "]"), |
| 1064 |
iterable2.makeString("[", "/", "]").equals("[<["31", "32"]:(toStringLiteral.(type))(); separator="/">]") |
| 1065 |
|| iterable2.makeString("[", "/", "]").equals("[<["32", "31"]:(toStringLiteral.(type))(); separator="/">]")); |
| 1066 |
|
| 1067 |
<name>Iterable iterable3 = this.newWith(<["32", "33"]:(literal.(type))(); separator=", ">); |
| 1068 |
Assert.assertTrue( |
| 1069 |
iterable3.makeString("/"), |
| 1070 |
iterable3.makeString("/").equals("<["32", "33"]:(toStringLiteral.(type))(); separator="/">") |
| 1071 |
|| iterable3.makeString("/").equals("<["33", "32"]:(toStringLiteral.(type))(); separator="/">")); |
| 1072 |
|
| 1073 |
<name>Iterable iterable4 = this.newWith(<["1", "2"]:(literal.(type))(); separator=", ">); |
| 1074 |
Assert.assertTrue("<["1", "2"]:(toStringLiteral.(type))(); separator=", ">".equals(iterable4.makeString()) |
| 1075 |
|| "<["2", "1"]:(toStringLiteral.(type))(); separator=", ">".equals(iterable4.makeString())); |
| 1076 |
Assert.assertTrue("<["1", "2"]:(toStringLiteral.(type))(); separator="/">".equals(iterable4.makeString("/")) |
| 1077 |
|| "<["2", "1"]:(toStringLiteral.(type))(); separator="/">".equals(iterable4.makeString("/"))); |
| 1078 |
Assert.assertTrue("[<["1", "2"]:(toStringLiteral.(type))(); separator="/">]".equals(iterable4.makeString("[", "/", "]")) |
| 1079 |
|| "[<["2", "1"]:(toStringLiteral.(type))(); separator="/">]".equals(iterable4.makeString("[", "/", "]"))); |
| 1080 |
|
| 1081 |
<name>Iterable iterable5 = this.newWith(<["0", "1"]:(literal.(type))(); separator=", ">); |
| 1082 |
Assert.assertTrue( |
| 1083 |
iterable5.makeString(), |
| 1084 |
iterable5.makeString().equals("<["0", "1"]:(toStringLiteral.(type))(); separator=", ">") |
| 1085 |
|| iterable5.makeString().equals("<["1", "0"]:(toStringLiteral.(type))(); separator=", ">")); |
| 1086 |
Assert.assertTrue( |
| 1087 |
iterable5.makeString("[", "/", "]"), |
| 1088 |
iterable5.makeString("[", "/", "]").equals("[<["0", "1"]:(toStringLiteral.(type))(); separator="/">]") |
| 1089 |
|| iterable5.makeString("[", "/", "]").equals("[<["1", "0"]:(toStringLiteral.(type))(); separator="/">]")); |
| 1090 |
Assert.assertTrue( |
| 1091 |
iterable5.makeString("/"), |
| 1092 |
iterable5.makeString("/").equals("<["0", "1"]:(toStringLiteral.(type))(); separator="/">") |
| 1093 |
|| iterable5.makeString("/").equals("<["1", "0"]:(toStringLiteral.(type))(); separator="/">")); |
| 1094 |
} |
| 1095 |
|
| 1096 |
@Test |
| 1097 |
public void appendString() |
| 1098 |
{ |
| 1099 |
StringBuilder appendable = new StringBuilder(); |
| 1100 |
this.newWith().appendString(appendable); |
| 1101 |
Assert.assertEquals("", appendable.toString()); |
| 1102 |
this.newWith().appendString(appendable, "/"); |
| 1103 |
Assert.assertEquals("", appendable.toString()); |
| 1104 |
this.newWith().appendString(appendable, "[", ", ", "]"); |
| 1105 |
Assert.assertEquals("[]", appendable.toString()); |
| 1106 |
StringBuilder appendable1 = new StringBuilder(); |
| 1107 |
this.newWith(<(literal.(type))("1")>).appendString(appendable1); |
| 1108 |
Assert.assertEquals("<(toStringLiteral.(type))("1")>", appendable1.toString()); |
| 1109 |
StringBuilder appendable2 = new StringBuilder(); |
| 1110 |
|
| 1111 |
<name>Iterable iterable = this.newWith(<["1", "2"]:(literal.(type))(); separator=", ">); |
| 1112 |
iterable.appendString(appendable2); |
| 1113 |
Assert.assertTrue("<["1", "2"]:(toStringLiteral.(type))(); separator=", ">".equals(appendable2.toString()) |
| 1114 |
|| "<["2", "1"]:(toStringLiteral.(type))(); separator=", ">".equals(appendable2.toString())); |
| 1115 |
StringBuilder appendable3 = new StringBuilder(); |
| 1116 |
iterable.appendString(appendable3, "/"); |
| 1117 |
Assert.assertTrue("<["1", "2"]:(toStringLiteral.(type))(); separator="/">".equals(appendable3.toString()) |
| 1118 |
|| "<["2", "1"]:(toStringLiteral.(type))(); separator="/">".equals(appendable3.toString())); |
| 1119 |
StringBuilder appendable4 = new StringBuilder(); |
| 1120 |
iterable.appendString(appendable4, "[", ", ", "]"); |
| 1121 |
Assert.assertEquals(iterable.toString(), appendable4.toString()); |
| 1122 |
|
| 1123 |
StringBuilder appendable5 = new StringBuilder(); |
| 1124 |
this.newWith(<(literal.(type))("31")>).appendString(appendable5); |
| 1125 |
Assert.assertEquals("<(toStringLiteral.(type))("31")>", appendable5.toString()); |
| 1126 |
|
| 1127 |
StringBuilder appendable6 = new StringBuilder(); |
| 1128 |
this.newWith(<(literal.(type))("32")>).appendString(appendable6); |
| 1129 |
Assert.assertEquals("<(toStringLiteral.(type))("32")>", appendable6.toString()); |
| 1130 |
|
| 1131 |
StringBuilder appendable7 = new StringBuilder(); |
| 1132 |
<name>Iterable iterable1 = this.newWith(<["0", "31"]:(literal.(type))(); separator=", ">); |
| 1133 |
iterable1.appendString(appendable7); |
| 1134 |
Assert.assertTrue(appendable7.toString(), "<["0", "31"]:(toStringLiteral.(type))(); separator=", ">".equals(appendable7.toString()) |
| 1135 |
|| "<["31", "0"]:(toStringLiteral.(type))(); separator=", ">".equals(appendable7.toString())); |
| 1136 |
|
| 1137 |
StringBuilder appendable8 = new StringBuilder(); |
| 1138 |
<name>Iterable iterable2 = this.newWith(<["31", "32"]:(literal.(type))(); separator=", ">); |
| 1139 |
iterable2.appendString(appendable8, "/"); |
| 1140 |
Assert.assertTrue(appendable8.toString(), "<["31", "32"]:(toStringLiteral.(type))(); separator="/">".equals(appendable8.toString()) |
| 1141 |
|| "<["32", "31"]:(toStringLiteral.(type))(); separator="/">".equals(appendable8.toString())); |
| 1142 |
|
| 1143 |
StringBuilder appendable9 = new StringBuilder(); |
| 1144 |
<name>Iterable iterable4 = this.newWith(<["32", "33"]:(literal.(type))(); separator=", ">); |
| 1145 |
iterable4.appendString(appendable9, "[", "/", "]"); |
| 1146 |
Assert.assertTrue(appendable9.toString(), "[<["32", "33"]:(toStringLiteral.(type))(); separator="/">]".equals(appendable9.toString()) |
| 1147 |
|| "[<["33", "32"]:(toStringLiteral.(type))(); separator="/">]".equals(appendable9.toString())); |
| 1148 |
|
| 1149 |
StringBuilder appendable10 = new StringBuilder(); |
| 1150 |
<name>Iterable iterable5 = this.newWith(<["0", "1"]:(literal.(type))(); separator=", ">); |
| 1151 |
iterable5.appendString(appendable10); |
| 1152 |
Assert.assertTrue(appendable10.toString(), "<["0", "1"]:(toStringLiteral.(type))(); separator=", ">".equals(appendable10.toString()) |
| 1153 |
|| "<["1", "0"]:(toStringLiteral.(type))(); separator=", ">".equals(appendable10.toString())); |
| 1154 |
StringBuilder appendable11 = new StringBuilder(); |
| 1155 |
iterable5.appendString(appendable11, "/"); |
| 1156 |
Assert.assertTrue(appendable11.toString(), "<["0", "1"]:(toStringLiteral.(type))(); separator="/">".equals(appendable11.toString()) |
| 1157 |
|| "<["1", "0"]:(toStringLiteral.(type))(); separator="/">".equals(appendable11.toString())); |
| 1158 |
StringBuilder appendable12 = new StringBuilder(); |
| 1159 |
iterable5.appendString(appendable12, "[", "/", "]"); |
| 1160 |
Assert.assertTrue(appendable12.toString(), "[<["0", "1"]:(toStringLiteral.(type))(); separator="/">]".equals(appendable12.toString()) |
| 1161 |
|| "[<["1", "0"]:(toStringLiteral.(type))(); separator="/">]".equals(appendable12.toString())); |
| 1162 |
} |
| 1163 |
|
| 1164 |
@Test |
| 1165 |
public void toList() |
| 1166 |
{ |
| 1167 |
<name>Iterable iterable = this.newWith(<["31", "32"]:(literal.(type))(); separator=", ">); |
| 1168 |
Assert.assertTrue(<name>ArrayList.newListWith(<["31", "32"]:(literal.(type))(); separator=", ">).equals(iterable.toList()) |
| 1169 |
|| <name>ArrayList.newListWith(<["32", "31"]:(literal.(type))(); separator=", ">).equals(iterable.toList())); |
| 1170 |
Assert.assertEquals(<name>ArrayList.newListWith(<(literal.(type))("0")>), this.newWith(<(literal.(type))("0")>).toList()); |
| 1171 |
Assert.assertEquals(<name>ArrayList.newListWith(<(literal.(type))("31")>), this.newWith(<(literal.(type))("31")>).toList()); |
| 1172 |
Assert.assertEquals(<name>ArrayList.newListWith(<(literal.(type))("32")>), this.newWith(<(literal.(type))("32")>).toList()); |
| 1173 |
Assert.assertEquals(new <name>ArrayList(), this.newWith().toList()); |
| 1174 |
} |
| 1175 |
|
| 1176 |
@Test |
| 1177 |
public void toSortedList() |
| 1178 |
{ |
| 1179 |
Assert.assertEquals(<name>ArrayList.newListWith(), this.newWith().toSortedList()); |
| 1180 |
Assert.assertEquals(<name>ArrayList.newListWith(<(literal.(type))("1")>), this.newWith(<(literal.(type))("1")>).toSortedList()); |
| 1181 |
Assert.assertEquals(<name>ArrayList.newListWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">), this.newWith(<["0", "31", "1"]:(literal.(type))(); separator=", ">).toSortedList()); |
| 1182 |
Assert.assertEquals(<name>ArrayList.newListWith(<["0", "1", "31", "32"]:(literal.(type))(); separator=", ">), this.newWith(<["0", "31", "32", "1"]:(literal.(type))(); separator=", ">).toSortedList()); |
| 1183 |
} |
| 1184 |
|
| 1185 |
@Test |
| 1186 |
public void toSortedListByComparator() |
| 1187 |
{ |
| 1188 |
<name>Iterable iterable = this.newWith(<["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]:(literal.(type))(); separator=", ">); |
| 1189 |
|
| 1190 |
Mutable<name>List result = iterable.toSortedList((a, b) -> (int) ((int) ((int) a & 1) - ((int) b & 1))); // odd/even comparator |
| 1191 |
|
| 1192 |
Assert.assertNotSame(iterable, result); |
| 1193 |
|
| 1194 |
result |
| 1195 |
.collectBoolean(e -> e % 2 == 0, BooleanLists.mutable.of()) |
| 1196 |
.forEachWithIndex((e, i) -> Assert.assertEquals("index " + i, i \< 5, e)); |
| 1197 |
} |
| 1198 |
|
| 1199 |
@Test |
| 1200 |
public void toSortedListByFunctionNaturalOrder() |
| 1201 |
{ |
| 1202 |
MutableList\<String> list = Lists.mutable.of("Foo", "Bar", "Baz", "Waldo", "Qux"); |
| 1203 |
<name>Iterable index = this.newMutableCollectionWith(<["0", "1", "2", "3", "4"]:(literal.(type))(); separator=", ">); |
| 1204 |
|
| 1205 |
Mutable<name>List result = index.toSortedListBy(i -> list.get((int) i)); |
| 1206 |
|
| 1207 |
Assert.assertNotSame(index, result); |
| 1208 |
Assert.assertEquals(<name>ArrayList.newListWith(<["1", "2", "0", "4", "3"]:(literal.(type))(); separator=", ">), result); |
| 1209 |
} |
| 1210 |
|
| 1211 |
@Test |
| 1212 |
public void toSortedListByFunctionWithComparator() |
| 1213 |
{ |
| 1214 |
MutableList\<String> list = Lists.mutable.of("Foo", "Bar", "Baz", "Waldo", "Qux"); |
| 1215 |
<name>Iterable index = this.newMutableCollectionWith(<["0", "1", "2", "3", "4"]:(literal.(type))(); separator=", ">); |
| 1216 |
|
| 1217 |
Mutable<name>List result = index.toSortedListBy(i -> list.get((int) i), Comparators.naturalOrder().reversed()); |
| 1218 |
|
| 1219 |
Assert.assertNotSame(index, result); |
| 1220 |
Assert.assertEquals(<name>ArrayList.newListWith(<["3", "4", "0", "2", "1"]:(literal.(type))(); separator=", ">), result); |
| 1221 |
} |
| 1222 |
|
| 1223 |
@Test |
| 1224 |
public void toSet() |
| 1225 |
{ |
| 1226 |
Assert.assertEquals(<name>HashSet.newSetWith(), this.newWith().toSet()); |
| 1227 |
Assert.assertEquals(<name>HashSet.newSetWith(<["1"]:(literal.(type))(); separator=", ">), this.newWith(<(literal.(type))("1")>).toSet()); |
| 1228 |
Assert.assertEquals(<name>HashSet.newSetWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">), this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">).toSet()); |
| 1229 |
Assert.assertEquals(<name>HashSet.newSetWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">), this.newWith(<["0", "1", "31"]:(literal.(type))(); separator=", ">).toSet()); |
| 1230 |
Assert.assertEquals(<name>HashSet.newSetWith(<["0", "1", "31", "32"]:(literal.(type))(); separator=", ">), this.newWith(<["0", "1", "31", "32"]:(literal.(type))(); separator=", ">).toSet()); |
| 1231 |
Assert.assertEquals(<name>HashSet.newSetWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">), this.newWith(<["1", "2", "2", "3", "3", "3"]:(literal.(type))(); separator=", ">).toSet()); |
| 1232 |
} |
| 1233 |
|
| 1234 |
@Test |
| 1235 |
public void toBag() |
| 1236 |
{ |
| 1237 |
Assert.assertEquals(new <name>HashBag(), this.newWith().toBag()); |
| 1238 |
Assert.assertEquals(<name>HashBag.newBagWith(<["1"]:(literal.(type))(); separator=", ">), this.newWith(<(literal.(type))("1")>).toBag()); |
| 1239 |
Assert.assertEquals(<name>HashBag.newBagWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">), this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">).toBag()); |
| 1240 |
Assert.assertEquals(<name>HashBag.newBagWith(<["1", "2", "2", "3", "3", "3"]:(literal.(type))(); separator=", ">), this.newWith(<["1", "2", "2", "3", "3", "3"]:(literal.(type))(); separator=", ">).toBag()); |
| 1241 |
Assert.assertEquals(<name>HashBag.newBagWith(<["0", "1", "31", "32"]:(literal.(type))(); separator=", ">), this.newWith(<["0", "1", "31", "32"]:(literal.(type))(); separator=", ">).toBag()); |
| 1242 |
} |
| 1243 |
|
| 1244 |
@Test |
| 1245 |
public void asLazy() |
| 1246 |
{ |
| 1247 |
<name>Iterable iterable = this.classUnderTest(); |
| 1248 |
Assert.assertEquals(iterable.toBag(), iterable.asLazy().toBag()); |
| 1249 |
Verify.assertInstanceOf(Lazy<name>Iterable.class, iterable.asLazy()); |
| 1250 |
|
| 1251 |
<name>Iterable iterable1 = this.newWith(<["1", "2", "2", "3", "3", "3"]:(literal.(type))(); separator=", ">); |
| 1252 |
Assert.assertEquals(iterable1.toBag(), iterable1.asLazy().toBag()); |
| 1253 |
Verify.assertInstanceOf(Lazy<name>Iterable.class, iterable1.asLazy()); |
| 1254 |
|
| 1255 |
<name>Iterable iterable2 = this.newWith(<["1", "2", "2", "3", "3", "3"]:(literal.(type))(); separator=", ">); |
| 1256 |
Assert.assertEquals(iterable2.toBag(), iterable2.asLazy().toBag()); |
| 1257 |
Verify.assertInstanceOf(Lazy<name>Iterable.class, iterable2.asLazy()); |
| 1258 |
|
| 1259 |
<name>Iterable iterable3 = this.newWith(); |
| 1260 |
Assert.assertEquals(iterable3.toBag(), iterable3.asLazy().toBag()); |
| 1261 |
Verify.assertInstanceOf(Lazy<name>Iterable.class, iterable3.asLazy()); |
| 1262 |
|
| 1263 |
<name>Iterable iterable4 = this.newWith(<["1"]:(literal.(type))(); separator=", ">); |
| 1264 |
Assert.assertEquals(iterable4.toBag(), iterable4.asLazy().toBag()); |
| 1265 |
Verify.assertInstanceOf(Lazy<name>Iterable.class, iterable4.asLazy()); |
| 1266 |
} |
| 1267 |
|
| 1268 |
@Test |
| 1269 |
public void injectInto() |
| 1270 |
{ |
| 1271 |
<name>Iterable iterable1 = this.newWith(<["0", "2", "31"]:(literal.(type))(); separator=", ">); |
| 1272 |
<wrapperName> sum1 = iterable1.injectInto(<wrapperName>.valueOf(<(literal.(type))("0")>), (<wrapperName> result, <type> value) -> <wrapperName>.valueOf((<type>) (result + value + 1))); |
| 1273 |
Assert.assertEquals(<wrapperName>.valueOf(<(literal.(type))("36")>), sum1); |
| 1274 |
|
| 1275 |
<name>Iterable iterable2 = this.newWith(<[ "1", "2", "31"]:(literal.(type))(); separator=", ">); |
| 1276 |
<wrapperName> sum2 = iterable2.injectInto(<wrapperName>.valueOf(<(literal.(type))("0")>), (<wrapperName> result, <type> value) -> <wrapperName>.valueOf((<type>) (result + value + 1))); |
| 1277 |
Assert.assertEquals(<wrapperName>.valueOf(<(literal.(type))("37")>), sum2); |
| 1278 |
|
| 1279 |
<name>Iterable iterable3 = this.newWith(<["0", "1", "2", "31"]:(literal.(type))(); separator=", ">); |
| 1280 |
<wrapperName> sum3 = iterable3.injectInto(<wrapperName>.valueOf(<(literal.(type))("0")>), (<wrapperName> result, <type> value) -> <wrapperName>.valueOf((<type>) (result + value + 1))); |
| 1281 |
Assert.assertEquals(<wrapperName>.valueOf(<(literal.(type))("38")>), sum3); |
| 1282 |
} |
| 1283 |
|
| 1284 |
@Test |
| 1285 |
public void injectIntoBoolean() |
| 1286 |
{ |
| 1287 |
<name>Iterable iterable1 = this.newWith(<["0", "2", "31"]:(literal.(type))(); separator=", ">); |
| 1288 |
boolean sum1 = iterable1.injectIntoBoolean(false, (boolean result, <type> value) -> (boolean) (result || value == <(literal.(type))("0")>)); |
| 1289 |
Assert.assertEquals(true, sum1); |
| 1290 |
|
| 1291 |
<name>Iterable iterable2 = this.newWith(<[ "1", "2", "31"]:(literal.(type))(); separator=", ">); |
| 1292 |
boolean sum2 = iterable2.injectIntoBoolean(false, (boolean result, <type> value) -> (boolean) (result || value == <(literal.(type))("0")>)); |
| 1293 |
Assert.assertEquals(false, sum2); |
| 1294 |
} |
| 1295 |
|
| 1296 |
<injectIntoPrimitiveTest("Byte", "byte", false)> |
| 1297 |
|
| 1298 |
<injectIntoPrimitiveTest("Char", "char", false)> |
| 1299 |
|
| 1300 |
<injectIntoPrimitiveTest("Short", "short", false)> |
| 1301 |
|
| 1302 |
<injectIntoPrimitiveTest("Int", "int", false)> |
| 1303 |
|
| 1304 |
<injectIntoPrimitiveTest("Float", "float", true)> |
| 1305 |
|
| 1306 |
<injectIntoPrimitiveTest("Long", "long", false)> |
| 1307 |
|
| 1308 |
<injectIntoPrimitiveTest("Double", "double", true)> |
| 1309 |
|
| 1310 |
@Test(expected = NoSuchElementException.class) |
| 1311 |
public void reduceOnEmptyThrows() |
| 1312 |
{ |
| 1313 |
this.newWith().reduce((<(wideType.(type))> result, <type> value) -> <(castWideType.(type))>result + <(castWideType.(type))>value + <(wideLiteral.(type))("1")>); |
| 1314 |
} |
| 1315 |
|
| 1316 |
@Test |
| 1317 |
public void reduce() |
| 1318 |
{ |
| 1319 |
<name>Iterable iterable1 = this.newWith(<["0", "2", "31"]:(literal.(type))(); separator=", ">); |
| 1320 |
<(wideType.(type))> sum1 = iterable1.reduce((<(wideType.(type))> result, <type> value) -> <(castWideType.(type))>result + <(castWideType.(type))>value + <(wideLiteral.(type))("1")>); |
| 1321 |
Assert.assertEquals(<(wideLiteral.(type))("35")>, sum1<if(primitive.floatingPoint)>, 0.001<endif>); |
| 1322 |
|
| 1323 |
<name>Iterable iterable2 = this.newWith(<[ "1", "2", "31"]:(literal.(type))(); separator=", ">); |
| 1324 |
<(wideType.(type))> sum2 = iterable2.reduce((<(wideType.(type))> result, <type> value) -> <(castWideType.(type))>result + <(castWideType.(type))>value + <(wideLiteral.(type))("1")>); |
| 1325 |
Assert.assertEquals(<(wideLiteral.(type))("36")>, sum2<if(primitive.floatingPoint)>, 0.001<endif>); |
| 1326 |
|
| 1327 |
<name>Iterable iterable3 = this.newWith(<["0", "1", "2", "31"]:(literal.(type))(); separator=", ">); |
| 1328 |
<(wideType.(type))> sum3 = iterable3.reduce((<(wideType.(type))> result, <type> value) -> <(castWideType.(type))>result + <(castWideType.(type))>value + <(wideLiteral.(type))("1")>); |
| 1329 |
Assert.assertEquals(<(wideLiteral.(type))("37")>, sum3<if(primitive.floatingPoint)>, 0.001<endif>); |
| 1330 |
} |
| 1331 |
|
| 1332 |
@Test |
| 1333 |
public void reduceIfEmpty() |
| 1334 |
{ |
| 1335 |
<(wideType.(type))> empty1 = this.newWith().reduceIfEmpty((<(wideType.(type))> result, <type> value) -> <(castWideType.(type))>result + <(castWideType.(type))>value + <(wideLiteral.(type))("1")>, <(wideLiteral.(type))("1")>); |
| 1336 |
Assert.assertEquals(<(wideLiteral.(type))("1")>, empty1<if(primitive.floatingPoint)>, 0.001<endif>); |
| 1337 |
<(wideType.(type))> empty2 = this.newWith().reduceIfEmpty((<(wideType.(type))> result, <type> value) -> <(castWideType.(type))>result + <(castWideType.(type))>value + <(wideLiteral.(type))("1")>, <(wideLiteral.(type))("0")>); |
| 1338 |
Assert.assertEquals(<(wideLiteral.(type))("0")>, empty2<if(primitive.floatingPoint)>, 0.001<endif>); |
| 1339 |
|
| 1340 |
<name>Iterable iterable1 = this.newWith(<["0", "2", "31"]:(literal.(type))(); separator=", ">); |
| 1341 |
<(wideType.(type))> sum1 = iterable1.reduceIfEmpty((<(wideType.(type))> result, <type> value) -> <(castWideType.(type))>result + <(castWideType.(type))>value + <(wideLiteral.(type))("1")>, <(wideLiteral.(type))("0")>); |
| 1342 |
Assert.assertEquals(<(wideLiteral.(type))("35")>, sum1<if(primitive.floatingPoint)>, 0.001<endif>); |
| 1343 |
|
| 1344 |
<name>Iterable iterable2 = this.newWith(<[ "1", "2", "31"]:(literal.(type))(); separator=", ">); |
| 1345 |
<(wideType.(type))> sum2 = iterable2.reduceIfEmpty((<(wideType.(type))> result, <type> value) -> <(castWideType.(type))>result + <(castWideType.(type))>value + <(wideLiteral.(type))("1")>, <(wideLiteral.(type))("0")>); |
| 1346 |
Assert.assertEquals(<(wideLiteral.(type))("36")>, sum2<if(primitive.floatingPoint)>, 0.001<endif>); |
| 1347 |
|
| 1348 |
<name>Iterable iterable3 = this.newWith(<["0", "1", "2", "31"]:(literal.(type))(); separator=", ">); |
| 1349 |
<(wideType.(type))> sum3 = iterable3.reduceIfEmpty((<(wideType.(type))> result, <type> value) -> <(castWideType.(type))>result + <(castWideType.(type))>value + <(wideLiteral.(type))("1")>, <(wideLiteral.(type))("0")>); |
| 1350 |
Assert.assertEquals(<(wideLiteral.(type))("37")>, sum3<if(primitive.floatingPoint)>, 0.001<endif>); |
| 1351 |
} |
| 1352 |
|
| 1353 |
@Test |
| 1354 |
public void chunk() |
| 1355 |
{ |
| 1356 |
<name>Iterable iterable = this.newWith(<["0", "1", "2", "3", "4", "5"]:(literal.(type))(); separator=", ">); |
| 1357 |
Assert.assertEquals( |
| 1358 |
Lists.mutable.with( |
| 1359 |
this.newMutableCollectionWith(<["0"]:(literal.(type))(); separator=", ">), |
| 1360 |
this.newMutableCollectionWith(<["1"]:(literal.(type))(); separator=", ">), |
| 1361 |
this.newMutableCollectionWith(<["2"]:(literal.(type))(); separator=", ">), |
| 1362 |
this.newMutableCollectionWith(<["3"]:(literal.(type))(); separator=", ">), |
| 1363 |
this.newMutableCollectionWith(<["4"]:(literal.(type))(); separator=", ">), |
| 1364 |
this.newMutableCollectionWith(<["5"]:(literal.(type))(); separator=", ">)).toSet(), |
| 1365 |
iterable.chunk(1).toSet()); |
| 1366 |
Assert.assertEquals( |
| 1367 |
Lists.mutable.with( |
| 1368 |
this.newMutableCollectionWith(<["0", "1"]:(literal.(type))(); separator=", ">), |
| 1369 |
this.newMutableCollectionWith(<["2", "3"]:(literal.(type))(); separator=", ">), |
| 1370 |
this.newMutableCollectionWith(<["4", "5"]:(literal.(type))(); separator=", ">)).toSet(), |
| 1371 |
iterable.chunk(2).toSet()); |
| 1372 |
Assert.assertEquals( |
| 1373 |
Lists.mutable.with( |
| 1374 |
this.newMutableCollectionWith(<["0", "1", "2"]:(literal.(type))(); separator=", ">), |
| 1375 |
this.newMutableCollectionWith(<["3", "4", "5"]:(literal.(type))(); separator=", ">)).toSet(), |
| 1376 |
iterable.chunk(3).toSet()); |
| 1377 |
Assert.assertEquals( |
| 1378 |
Lists.mutable.with( |
| 1379 |
this.newMutableCollectionWith(<["0", "1", "2", "3"]:(literal.(type))(); separator=", ">), |
| 1380 |
this.newMutableCollectionWith(<["4", "5"]:(literal.(type))(); separator=", ">)).toSet(), |
| 1381 |
iterable.chunk(4).toSet()); |
| 1382 |
Assert.assertEquals( |
| 1383 |
Lists.mutable.with(this.newMutableCollectionWith(<["0", "1", "2", "3", "4", "5"]:(literal.(type))(); separator=", ">)).toSet(), |
| 1384 |
iterable.chunk(6).toSet()); |
| 1385 |
Assert.assertEquals( |
| 1386 |
Lists.mutable.with(this.newMutableCollectionWith(<["0", "1", "2", "3", "4", "5"]:(literal.(type))(); separator=", ">)).toSet(), |
| 1387 |
iterable.chunk(7).toSet()); |
| 1388 |
Assert.assertEquals(Lists.mutable.with(), this.newWith().chunk(1)); |
| 1389 |
Assert.assertEquals(Lists.mutable.with(this.newMutableCollectionWith(<["0"]:(literal.(type))(); separator=", ">)), this.newWith(<["0"]:(literal.(type))(); separator=", ">).chunk(1)); |
| 1390 |
Assert.assertEquals(Lists.mutable.with(), this.newWith().chunk(1)); |
| 1391 |
|
| 1392 |
Assert.assertThrows(IllegalArgumentException.class, () -> iterable.chunk(0)); |
| 1393 |
Assert.assertThrows(IllegalArgumentException.class, () -> iterable.chunk(-1)); |
| 1394 |
Assert.assertThrows(IllegalArgumentException.class, () -> this.newMutableCollectionWith().chunk(-1)); |
| 1395 |
} |
| 1396 |
} |
| 1397 |
|
| 1398 |
>> |
| 1399 |
|
| 1400 |
kahanSumTests ::= [ |
| 1401 |
"float": "kahanFloatSumTest", |
| 1402 |
"double": "kahanDoubleSumTest", |
| 1403 |
"default": "noTest" |
| 1404 |
] |
| 1405 |
|
| 1406 |
kahanFloatSumTest() ::= << |
| 1407 |
>> |
| 1408 |
|
| 1409 |
kahanDoubleSumTest() ::= << |
| 1410 |
|
| 1411 |
>> |
| 1412 |
|
| 1413 |
noTest() ::= "" |
| 1414 |
|
| 1415 |
maxTests ::= [ |
| 1416 |
"byte": "intMaxTest", |
| 1417 |
"short": "intMaxTest", |
| 1418 |
"char": "charMaxTest", |
| 1419 |
"int": "intMaxTest", |
| 1420 |
"long": "intMaxTest", |
| 1421 |
"float": "floatMaxTest", |
| 1422 |
"double": "floatMaxTest" |
| 1423 |
] |
| 1424 |
|
| 1425 |
intMaxTest(type, name) ::= << |
| 1426 |
Assert.assertEquals(<(wideLiteral.(type))("9")>, this.newWith(<["-1", "-2", "9"]:(literal.(type))(); separator=", ">).max()<(wideDelta.(type))>); |
| 1427 |
Assert.assertEquals(<(wideLiteral.(type))("-1")>, this.newWith(<["-1", "-2", "-9"]:(literal.(type))(); separator=", ">).max()<(wideDelta.(type))>); |
| 1428 |
Assert.assertEquals(<(wideLiteral.(type))("32")>, this.newWith(<["1", "0", "9", "30", "31", "32"]:(literal.(type))(); separator=", ">).max()<(wideDelta.(type))>); |
| 1429 |
Assert.assertEquals(<(wideLiteral.(type))("32")>, this.newWith(<["-1", "0", "9", "30", "31", "32"]:(literal.(type))(); separator=", ">).max()<(wideDelta.(type))>); |
| 1430 |
Assert.assertEquals(<(wideLiteral.(type))("31")>, this.newWith(<["31", "0", "30"]:(literal.(type))(); separator=", ">).max()<(wideDelta.(type))>); |
| 1431 |
Assert.assertEquals(<(wideLiteral.(type))("39")>, this.newWith(<["32", "39", "35"]:(literal.(type))(); separator=", ">).max()<(wideDelta.(type))>); |
| 1432 |
Assert.assertEquals(this.classUnderTest().size(), this.classUnderTest().max()<(delta.(type))>); |
| 1433 |
>> |
| 1434 |
|
| 1435 |
charMaxTest(type, name) ::= << |
| 1436 |
Assert.assertEquals(<(literal.(type))("-1")>, this.newWith(<["-1", "-2", "9"]:(literal.(type))(); separator=", ">).max()<(wideDelta.(type))>); |
| 1437 |
Assert.assertEquals(<(literal.(type))("32")>, this.newWith(<["1", "0", "9", "30", "31", "32"]:(literal.(type))(); separator=", ">).max()<(wideDelta.(type))>); |
| 1438 |
Assert.assertEquals(<(literal.(type))("-1")>, this.newWith(<["-1", "0", "9", "30", "31", "32"]:(literal.(type))(); separator=", ">).max()<(wideDelta.(type))>); |
| 1439 |
Assert.assertEquals(<(literal.(type))("31")>, this.newWith(<["31", "0", "30"]:(literal.(type))(); separator=", ">).max()<(wideDelta.(type))>); |
| 1440 |
Assert.assertEquals(<(literal.(type))("39")>, this.newWith(<["32", "39", "35"]:(literal.(type))(); separator=", ">).max()<(wideDelta.(type))>); |
| 1441 |
Assert.assertEquals(this.classUnderTest().size(), this.classUnderTest().max()<(wideDelta.(type))>); |
| 1442 |
>> |
| 1443 |
|
| 1444 |
floatMaxTest(type, name) ::= << |
| 1445 |
<intMaxTest(type, name)> |
| 1446 |
Assert.assertEquals(32.5, this.newWith(<["-1.5", "31.8", "32.5"]:(decimalLiteral.(type))(); separator=", ">).max()<(wideDelta.(type))>); |
| 1447 |
Assert.assertEquals(-1.5, this.newWith(<["-1.5", "-31.8", "-32.5"]:(decimalLiteral.(type))(); separator=", ">).max()<(wideDelta.(type))>); |
| 1448 |
Assert.assertEquals(<name>.POSITIVE_INFINITY, this.newWith(<["-1.5", "31.8", "32.5"]:(decimalLiteral.(type))(); separator=", ">, <name>.POSITIVE_INFINITY).max()<(wideDelta.(type))>); |
| 1449 |
Assert.assertEquals(<name>.NaN, this.newWith(<["-1.5", "31.8", "32.5"]:(decimalLiteral.(type))(); separator=", ">, <name>.NaN, 31.5f).max()<(wideDelta.(type))>); |
| 1450 |
Assert.assertEquals(32.5, this.newWith(<["-1.5", "31.8", "32.5"]:(decimalLiteral.(type))(); separator=", ">, <name>.NEGATIVE_INFINITY, 31.5f).max()<(wideDelta.(type))>); |
| 1451 |
>> |
| 1452 |
|
| 1453 |
minTests ::= [ |
| 1454 |
"byte": "intMinTest", |
| 1455 |
"short": "intMinTest", |
| 1456 |
"char": "charMinTest", |
| 1457 |
"int": "intMinTest", |
| 1458 |
"long": "intMinTest", |
| 1459 |
"float": "floatMinTest", |
| 1460 |
"double": "floatMinTest" |
| 1461 |
] |
| 1462 |
|
| 1463 |
intMinTest(type, name) ::= << |
| 1464 |
Assert.assertEquals(<(wideLiteral.(type))("-2")>, this.newWith(<["-1", "-2", "9"]:(literal.(type))(); separator=", ">).min()<(wideDelta.(type))>); |
| 1465 |
Assert.assertEquals(<(wideLiteral.(type))("0")>, this.newWith(<["1", "0", "9", "30", "31", "32"]:(literal.(type))(); separator=", ">).min()<(wideDelta.(type))>); |
| 1466 |
Assert.assertEquals(<(wideLiteral.(type))("-1")>, this.newWith(<["-1", "0", "9", "30", "31", "32"]:(literal.(type))(); separator=", ">).min()<(wideDelta.(type))>); |
| 1467 |
Assert.assertEquals(<(wideLiteral.(type))("31")>, this.newWith(<["31", "32", "33"]:(literal.(type))(); separator=", ">).min()<(wideDelta.(type))>); |
| 1468 |
Assert.assertEquals(<(wideLiteral.(type))("32")>, this.newWith(<["32", "39", "35"]:(literal.(type))(); separator=", ">).min()<(wideDelta.(type))>); |
| 1469 |
Assert.assertEquals(<(wideLiteral.(type))("1")>, this.classUnderTest().min()<(wideDelta.(type))>); |
| 1470 |
>> |
| 1471 |
|
| 1472 |
charMinTest(type, name) ::= << |
| 1473 |
Assert.assertEquals(<(wideLiteral.(type))("9")>, this.newWith(<["-1", "-2", "9"]:(literal.(type))(); separator=", ">).min()<(wideDelta.(type))>); |
| 1474 |
Assert.assertEquals(<(wideLiteral.(type))("0")>, this.newWith(<["1", "0", "9", "30", "31", "32"]:(literal.(type))(); separator=", ">).min()<(wideDelta.(type))>); |
| 1475 |
Assert.assertEquals(<(wideLiteral.(type))("0")>, this.newWith(<["-1", "0", "9", "30", "31", "32"]:(literal.(type))(); separator=", ">).min()<(wideDelta.(type))>); |
| 1476 |
Assert.assertEquals(<(wideLiteral.(type))("31")>, this.newWith(<["31", "32", "33"]:(literal.(type))(); separator=", ">).min()<(wideDelta.(type))>); |
| 1477 |
Assert.assertEquals(<(wideLiteral.(type))("32")>, this.newWith(<["32", "39", "35"]:(literal.(type))(); separator=", ">).min()<(wideDelta.(type))>); |
| 1478 |
Assert.assertEquals(<(wideLiteral.(type))("1")>, this.classUnderTest().min()<(wideDelta.(type))>); |
| 1479 |
>> |
| 1480 |
|
| 1481 |
floatMinTest(type, name) ::= << |
| 1482 |
<intMinTest(type, name)> |
| 1483 |
Assert.assertEquals(-1.5, this.newWith(<["-1.5", "31.5", "32.5"]:(decimalLiteral.(type))(); separator=", ">).min()<(wideDelta.(type))>); |
| 1484 |
Assert.assertEquals(1.5, this.newWith(<["1.5", "31.0", "30.0"]:(decimalLiteral.(type))(); separator=", ">, <name>.POSITIVE_INFINITY).min()<(wideDelta.(type))>); |
| 1485 |
Assert.assertEquals(31.5, this.newWith(<["31.5", "32.5"]:(decimalLiteral.(type))(); separator=", ">, <name>.NaN).min()<(wideDelta.(type))>); |
| 1486 |
Assert.assertEquals(<name>.NEGATIVE_INFINITY, this.newWith(<["-1.5", "31.5", "32.5"]:(decimalLiteral.(type))(); separator=", ">, <name>.NEGATIVE_INFINITY, 31.5f).min()<(wideDelta.(type))>); |
| 1487 |
>> |
| 1488 |
|
| 1489 |
NaNTests(key) ::= << |
| 1490 |
@Test |
| 1491 |
public void contains_<key>() |
| 1492 |
{ |
| 1493 |
<name>Iterable primitiveIterable = this.newWith(<wrapperName>.<key>); |
| 1494 |
Set\<<wrapperName>\> hashSet = new HashSet\<>(); |
| 1495 |
Assert.assertTrue(hashSet.add(<wrapperName>.<key>)); |
| 1496 |
Assert.assertTrue(hashSet.contains(<wrapperName>.<key>)); |
| 1497 |
Assert.assertTrue(primitiveIterable.contains(<wrapperName>.<key>)); |
| 1498 |
} |
| 1499 |
|
| 1500 |
>> |
| 1501 |
|
| 1502 |
NaNEqualsTests() ::= << |
| 1503 |
@Test |
| 1504 |
public void testEquals_NaN() |
| 1505 |
{ |
| 1506 |
<name>Iterable iterable1 = this.newWith(<wrapperName>.NaN); |
| 1507 |
Set\<<wrapperName>\> hashSet1 = new HashSet\<>(); |
| 1508 |
hashSet1.add(<wrapperName>.NaN); |
| 1509 |
<name>Iterable iterable2 = this.newWith(<wrapperName>.NaN); |
| 1510 |
Set\<<wrapperName>\> hashSet2 = new HashSet\<>(); |
| 1511 |
hashSet2.add(<wrapperName>.NaN); |
| 1512 |
<name>Iterable iterable3 = this.newWith(<wrapperName>.POSITIVE_INFINITY); |
| 1513 |
Set\<<wrapperName>\> hashSet3 = new HashSet\<>(); |
| 1514 |
hashSet3.add(<wrapperName>.POSITIVE_INFINITY); |
| 1515 |
<name>Iterable iterable4 = this.newWith(<wrapperName>.POSITIVE_INFINITY); |
| 1516 |
Set\<<wrapperName>\> hashSet4 = new HashSet\<>(); |
| 1517 |
hashSet4.add(<wrapperName>.POSITIVE_INFINITY); |
| 1518 |
<name>Iterable iterable5 = this.newWith(<wrapperName>.NEGATIVE_INFINITY); |
| 1519 |
Set\<<wrapperName>\> hashSet5 = new HashSet\<>(); |
| 1520 |
hashSet5.add(<wrapperName>.NEGATIVE_INFINITY); |
| 1521 |
<name>Iterable iterable6 = this.newWith(<wrapperName>.NEGATIVE_INFINITY); |
| 1522 |
Set\<<wrapperName>\> hashSet6 = new HashSet\<>(); |
| 1523 |
hashSet6.add(<wrapperName>.NEGATIVE_INFINITY); |
| 1524 |
|
| 1525 |
Assert.assertEquals(hashSet1, hashSet2); |
| 1526 |
Assert.assertEquals(iterable1, iterable2); |
| 1527 |
Assert.assertEquals(hashSet3, hashSet4); |
| 1528 |
Assert.assertEquals(iterable3, iterable4); |
| 1529 |
Assert.assertEquals(hashSet5, hashSet6); |
| 1530 |
Assert.assertEquals(iterable5, iterable6); |
| 1531 |
|
| 1532 |
Assert.assertNotEquals(hashSet1, hashSet3); |
| 1533 |
Assert.assertNotEquals(iterable1, iterable3); |
| 1534 |
Assert.assertNotEquals(hashSet3, hashSet5); |
| 1535 |
Assert.assertNotEquals(iterable3, iterable5); |
| 1536 |
Assert.assertNotEquals(hashSet5, hashSet1); |
| 1537 |
Assert.assertNotEquals(iterable5, iterable1); |
| 1538 |
} |
| 1539 |
|
| 1540 |
>> |
| 1541 |
|
| 1542 |
differentNaNs() ::= << |
| 1543 |
@Test |
| 1544 |
public void contains_different_NaNs() |
| 1545 |
{ |
| 1546 |
<bitsType.(type)> nan1 = <NaNBits1.(type)>; |
| 1547 |
<name>Iterable primitiveIterable = this.newWith(<wrapperName>.<bitsType.(type)>BitsTo<name>(nan1)); |
| 1548 |
Set\<<wrapperName>\> hashSet = new HashSet\<>(); |
| 1549 |
hashSet.add(<wrapperName>.<bitsType.(type)>BitsTo<name>(nan1)); |
| 1550 |
<bitsType.(type)> nan2 = <NaNBits2.(type)>; |
| 1551 |
Assert.assertEquals(hashSet.contains(<wrapperName>.<bitsType.(type)>BitsTo<name>(nan2)), primitiveIterable.contains(<wrapperName>.<bitsType.(type)>BitsTo<name>(nan2))); |
| 1552 |
} |
| 1553 |
|
| 1554 |
>> |
| 1555 |
|
| 1556 |
ZeroTests() ::= << |
| 1557 |
@Test |
| 1558 |
public void contains_zero() |
| 1559 |
{ |
| 1560 |
<name>Iterable iterable = this.newWith(<(literal.(type))("0")>); |
| 1561 |
Set\<<wrapperName>\> hashSet = new HashSet\<>(); |
| 1562 |
hashSet.add(<(literal.(type))("0")>); |
| 1563 |
|
| 1564 |
Assert.assertTrue(hashSet.contains(<(literal.(type))("0")>)); |
| 1565 |
Assert.assertFalse(hashSet.contains(-<(literal.(type))("0")>)); |
| 1566 |
Assert.assertTrue(iterable.contains(<(literal.(type))("0")>)); |
| 1567 |
Assert.assertFalse(iterable.contains(-<(literal.(type))("0")>)); |
| 1568 |
} |
| 1569 |
|
| 1570 |
>> |
| 1571 |
|
| 1572 |
NaNBits1 ::= [ |
| 1573 |
"float": "0x7f800001", |
| 1574 |
"double": "0x7ff0000000000001L", |
| 1575 |
"default": "no matching bits" |
| 1576 |
] |
| 1577 |
|
| 1578 |
NaNBits2 ::= [ |
| 1579 |
"float": "0xff800001", |
| 1580 |
"double": "0xfff0000000000001L", |
| 1581 |
"default": "no matching bits" |
| 1582 |
] |
| 1583 |
|
| 1584 |
injectIntoPrimitiveTest(toName, toType, toFloatingPoint) ::= << |
| 1585 |
@Test |
| 1586 |
public void injectInto<toName>() |
| 1587 |
{ |
| 1588 |
<name>Iterable iterable1 = this.newWith(<["0", "2", "31"]:(literal.(type))(); separator=", ">); |
| 1589 |
<toType> sum1 = iterable1.injectInto<toName>(<(literal.(toType))("0")>, (<toType> result, <type> value) -> (<toType>) (result + value + 1)); |
| 1590 |
Assert.assertEquals(<(literal.(toType))("36")>, sum1<if(toFloatingPoint)>, 0.001<endif>); |
| 1591 |
|
| 1592 |
<name>Iterable iterable2 = this.newWith(<[ "1", "2", "31"]:(literal.(type))(); separator=", ">); |
| 1593 |
<toType> sum2 = iterable2.injectInto<toName>(<(literal.(toType))("0")>, (<toType> result, <type> value) -> (<toType>) (result + value + 1)); |
| 1594 |
Assert.assertEquals(<(literal.(toType))("37")>, sum2<if(toFloatingPoint)>, 0.001<endif>); |
| 1595 |
|
| 1596 |
<name>Iterable iterable3 = this.newWith(<["0", "1", "2", "31"]:(literal.(type))(); separator=", ">); |
| 1597 |
<toType> sum3 = iterable3.injectInto<toName>(<(literal.(toType))("0")>, (<toType> result, <type> value) -> (<toType>) (result + value + 1)); |
| 1598 |
Assert.assertEquals(<(literal.(toType))("38")>, sum3<if(toFloatingPoint)>, 0.001<endif>); |
| 1599 |
} |
| 1600 |
>> |