@Test
 public void forEachOnFromToByInterval2() {
   List<Integer> result = new ArrayList<>();
   Interval interval = Interval.fromToBy(5, 1, -2);
   interval.forEach(CollectionAddProcedure.on(result));
   Verify.assertSize(3, result);
   Verify.assertContains(1, result);
   Verify.assertNotContains(2, result);
   Verify.assertContains(5, result);
 }
  @Override
  @Test
  public void removeAllIterable() {
    super.removeAllIterable();

    MutableList<Integer> objects = MultiReaderFastList.newListWith(1, 2, 3);
    objects.removeAllIterable(Lists.fixedSize.of(1, 2));
    Verify.assertSize(1, objects);
    Verify.assertContains(3, objects);
    MutableList<Integer> objects2 = MultiReaderFastList.newListWith(1, 2, 3);
    objects2.removeAllIterable(Lists.fixedSize.of(1));
    Verify.assertSize(2, objects2);
    Verify.assertContainsAll(objects2, 2, 3);
    MutableList<Integer> objects3 = MultiReaderFastList.newListWith(1, 2, 3);
    objects3.removeAllIterable(Lists.fixedSize.of(3));
    Verify.assertSize(2, objects3);
    Verify.assertContainsAll(objects3, 1, 2);
    MutableList<Integer> objects4 = MultiReaderFastList.newListWith(1, 2, 3);
    objects4.removeAllIterable(Lists.fixedSize.of());
    Verify.assertSize(3, objects4);
    Verify.assertContainsAll(objects4, 1, 2, 3);
    MutableList<Integer> objects5 = MultiReaderFastList.newListWith(1, 2, 3);
    objects5.removeAllIterable(Lists.fixedSize.of(1, 2, 3));
    Verify.assertEmpty(objects5);
    MutableList<Integer> objects6 = MultiReaderFastList.newListWith(1, 2, 3);
    objects6.removeAllIterable(Lists.fixedSize.of(2));
    Verify.assertSize(2, objects6);
    Verify.assertContainsAll(objects6, 1, 3);
  }
 @Test
 public void forLoop() {
   MutableList<String> list = SingletonListTest.newWith("one");
   MutableList<String> upperList = SingletonListTest.newWith("ONE");
   for (String each : list) {
     Verify.assertContains(each.toUpperCase(), upperList);
   }
 }
  @Test
  public void reverseForEachOnFromToInterval() {
    List<Integer> result = new ArrayList<>();
    Interval interval = Interval.oneTo(5);
    interval.reverseForEach(result::add);
    Verify.assertSize(5, result);
    Verify.assertContains(1, result);
    Verify.assertContains(5, result);
    Assert.assertEquals(Integer.valueOf(5), Iterate.getFirst(result));
    Assert.assertEquals(Integer.valueOf(1), Iterate.getLast(result));

    result.clear();
    interval.reverseThis().reverseForEach(result::add);
    Verify.assertSize(5, result);
    Verify.assertContains(1, result);
    Verify.assertContains(5, result);
    Assert.assertEquals(Integer.valueOf(1), Iterate.getFirst(result));
    Assert.assertEquals(Integer.valueOf(5), Iterate.getLast(result));
  }
 @Test
 public void subList() {
   MutableList<String> list = SingletonListTest.newWith("one");
   MutableList<String> subList = list.subList(0, 1);
   MutableList<String> upperList = SingletonListTest.newWith("ONE");
   for (String each : subList) {
     Verify.assertContains(each.toUpperCase(), upperList);
   }
   Assert.assertEquals("one", subList.getFirst());
   Assert.assertEquals("one", subList.getLast());
 }
Exemplo n.º 6
0
  @Test
  public void setKeyPreservation() {
    Key key = new Key("key");

    Key duplicateKey1 = new Key("key");
    ImmutableSet<Key> set1 = Sets.immutable.of(key, duplicateKey1);
    Verify.assertSize(1, set1);
    Verify.assertContains(key, set1);
    Assert.assertSame(key, set1.getFirst());

    Key duplicateKey2 = new Key("key");
    ImmutableSet<Key> set2 = Sets.immutable.of(key, duplicateKey1, duplicateKey2);
    Verify.assertSize(1, set2);
    Verify.assertContains(key, set2);
    Assert.assertSame(key, set2.getFirst());

    Key duplicateKey3 = new Key("key");
    ImmutableSet<Key> set3 = Sets.immutable.of(key, new Key("not a dupe"), duplicateKey3);
    Verify.assertSize(2, set3);
    Verify.assertContainsAll("immutable set", set3, key, new Key("not a dupe"));
    Assert.assertSame(key, set3.detect(key::equals));

    Key duplicateKey4 = new Key("key");
    ImmutableSet<Key> set4 =
        Sets.immutable.of(key, new Key("not a dupe"), duplicateKey3, duplicateKey4);
    Verify.assertSize(2, set4);
    Verify.assertContainsAll("immutable set", set4, key, new Key("not a dupe"));
    Assert.assertSame(key, set4.detect(key::equals));

    ImmutableSet<Key> set5 =
        Sets.immutable.of(key, new Key("not a dupe"), new Key("me neither"), duplicateKey4);
    Verify.assertSize(3, set5);
    Verify.assertContainsAll(
        "immutable set", set5, key, new Key("not a dupe"), new Key("me neither"));
    Assert.assertSame(key, set5.detect(key::equals));

    ImmutableSet<Key> set6 = Sets.immutable.of(key, duplicateKey2, duplicateKey3, duplicateKey4);
    Verify.assertSize(1, set6);
    Verify.assertContains(key, set6);
    Assert.assertSame(key, set6.detect(key::equals));
  }