test/java/util/Collection/testlibrary/CollectionSupplier.java

Print this page
rev 7994 : 8024291: Rename Collection.removeIf(Predicate) back to removeAll(Predicate)
Reviewed-by: duke


 225             emptyWithSlack.add(42);
 226             assertTrue(emptyWithSlack.remove(42));
 227             collections.add(new TestCase("emptyWithSlack",
 228                     className,
 229                     copyConstructor.newInstance(emptyWithSlack),
 230                     emptyWithSlack));
 231 
 232             final Collection<Integer> singleWithSlack = defaultConstructor.newInstance();
 233             singleWithSlack.add(42);
 234             singleWithSlack.add(43);
 235             assertTrue(singleWithSlack.remove(43));
 236             collections.add(new TestCase("singleWithSlack",
 237                     className,
 238                     copyConstructor.newInstance(singleWithSlack),
 239                     singleWithSlack));
 240 
 241             final Collection<Integer> regularWithSlack = defaultConstructor.newInstance();
 242             for (int i=0; i < (2 * size); i++) {
 243                 regularWithSlack.add(i);
 244             }
 245             assertTrue(regularWithSlack.removeIf((x) -> {return x >= size;}));
 246             collections.add(new TestCase("regularWithSlack",
 247                     className,
 248                     copyConstructor.newInstance(regularWithSlack),
 249                     regularWithSlack));
 250 
 251             final Collection<Integer> reverseWithSlack = defaultConstructor.newInstance();
 252             for (int i=2 * size; i >= 0; i--) {
 253                 reverseWithSlack.add(i);
 254             }
 255             assertTrue(reverseWithSlack.removeIf((x) -> {return x < size;}));
 256             collections.add(new TestCase("reverseWithSlack",
 257                     className,
 258                     copyConstructor.newInstance(reverseWithSlack),
 259                     reverseWithSlack));
 260 
 261             final Collection<Integer> oddsWithSlack = defaultConstructor.newInstance();
 262             for (int i = 0; i < 2 * size; i++) {
 263                 oddsWithSlack.add((i * 2) + 1);
 264             }
 265             assertTrue(oddsWithSlack.removeIf((x) -> {return x >= size;}));
 266             collections.add(new TestCase("oddsWithSlack",
 267                     className,
 268                     copyConstructor.newInstance(oddsWithSlack),
 269                     oddsWithSlack));
 270 
 271             final Collection<Integer> evensWithSlack = defaultConstructor.newInstance();
 272             for (int i = 0; i < 2 * size; i++) {
 273                 evensWithSlack.add(i * 2);
 274             }
 275             assertTrue(evensWithSlack.removeIf((x) -> {return x >= size;}));
 276             collections.add(new TestCase("evensWithSlack",
 277                     className,
 278                     copyConstructor.newInstance(evensWithSlack),
 279                     evensWithSlack));
 280 
 281             final Collection<Integer> fibonacciWithSlack = defaultConstructor.newInstance();
 282             prev2 = 0;
 283             prev1 = 1;
 284             for (int i=0; i < size; i++) {
 285                 final int n = prev1 + prev2;
 286                 if (n < 0) { // stop on overflow
 287                     break;
 288                 }
 289                 fibonacciWithSlack.add(n);
 290                 prev2 = prev1;
 291                 prev1 = n;
 292             }
 293             assertTrue(fibonacciWithSlack.removeIf((x) -> {return x < 20;}));
 294             collections.add(new TestCase("fibonacciWithSlack",
 295                     className,
 296                     copyConstructor.newInstance(fibonacciWithSlack),
 297                     fibonacciWithSlack));
 298 
 299         }
 300 
 301         return collections;
 302     }
 303 
 304 }


 225             emptyWithSlack.add(42);
 226             assertTrue(emptyWithSlack.remove(42));
 227             collections.add(new TestCase("emptyWithSlack",
 228                     className,
 229                     copyConstructor.newInstance(emptyWithSlack),
 230                     emptyWithSlack));
 231 
 232             final Collection<Integer> singleWithSlack = defaultConstructor.newInstance();
 233             singleWithSlack.add(42);
 234             singleWithSlack.add(43);
 235             assertTrue(singleWithSlack.remove(43));
 236             collections.add(new TestCase("singleWithSlack",
 237                     className,
 238                     copyConstructor.newInstance(singleWithSlack),
 239                     singleWithSlack));
 240 
 241             final Collection<Integer> regularWithSlack = defaultConstructor.newInstance();
 242             for (int i=0; i < (2 * size); i++) {
 243                 regularWithSlack.add(i);
 244             }
 245             assertTrue(regularWithSlack.removeAll(x -> x >= size));
 246             collections.add(new TestCase("regularWithSlack",
 247                     className,
 248                     copyConstructor.newInstance(regularWithSlack),
 249                     regularWithSlack));
 250 
 251             final Collection<Integer> reverseWithSlack = defaultConstructor.newInstance();
 252             for (int i=2 * size; i >= 0; i--) {
 253                 reverseWithSlack.add(i);
 254             }
 255             assertTrue(reverseWithSlack.removeAll(x -> x < size));
 256             collections.add(new TestCase("reverseWithSlack",
 257                     className,
 258                     copyConstructor.newInstance(reverseWithSlack),
 259                     reverseWithSlack));
 260 
 261             final Collection<Integer> oddsWithSlack = defaultConstructor.newInstance();
 262             for (int i = 0; i < 2 * size; i++) {
 263                 oddsWithSlack.add((i * 2) + 1);
 264             }
 265             assertTrue(oddsWithSlack.removeAll(x -> x >= size));
 266             collections.add(new TestCase("oddsWithSlack",
 267                     className,
 268                     copyConstructor.newInstance(oddsWithSlack),
 269                     oddsWithSlack));
 270 
 271             final Collection<Integer> evensWithSlack = defaultConstructor.newInstance();
 272             for (int i = 0; i < 2 * size; i++) {
 273                 evensWithSlack.add(i * 2);
 274             }
 275             assertTrue(evensWithSlack.removeAll(x -> x >= size));
 276             collections.add(new TestCase("evensWithSlack",
 277                     className,
 278                     copyConstructor.newInstance(evensWithSlack),
 279                     evensWithSlack));
 280 
 281             final Collection<Integer> fibonacciWithSlack = defaultConstructor.newInstance();
 282             prev2 = 0;
 283             prev1 = 1;
 284             for (int i=0; i < size; i++) {
 285                 final int n = prev1 + prev2;
 286                 if (n < 0) { // stop on overflow
 287                     break;
 288                 }
 289                 fibonacciWithSlack.add(n);
 290                 prev2 = prev1;
 291                 prev1 = n;
 292             }
 293             assertTrue(fibonacciWithSlack.removeAll(x -> x < 20));
 294             collections.add(new TestCase("fibonacciWithSlack",
 295                     className,
 296                     copyConstructor.newInstance(fibonacciWithSlack),
 297                     fibonacciWithSlack));
 298 
 299         }
 300 
 301         return collections;
 302     }
 303 
 304 }