@Test
 public void collectOnFromToInterval() {
   Interval interval = Interval.oneTo(5);
   LazyIterable<String> result = interval.collect(String::valueOf);
   Verify.assertIterableSize(5, result);
   Verify.assertContainsAll(result, "1", "5");
 }
 @Test
 public void removeUsingPredicate() {
   MutableList<Integer> objects = MultiReaderFastList.newListWith(1, 2, 3, null);
   Assert.assertTrue(objects.removeIf(Predicates.isNull()));
   Verify.assertSize(3, objects);
   Verify.assertContainsAll(objects, 1, 2, 3);
 }
 @Test
 public void addingAllToOtherList() {
   MutableList<String> newList = FastList.newList(this.list);
   newList.add("2");
   Verify.assertItemAtIndex("1", 0, newList);
   Verify.assertItemAtIndex("2", 1, newList);
 }
 @Override
 @Test
 public void isEmpty() {
   Verify.assertEmpty(MultiReaderFastList.newList());
   Verify.assertNotEmpty(MultiReaderFastList.newListWith(1, 2));
   Assert.assertTrue(MultiReaderFastList.newListWith(1, 2).notEmpty());
 }
 @Test
 public void selectWith() {
   Verify.assertContainsAll(
       SingletonListTest.newWith(1).selectWith(Predicates2.<Integer>lessThan(), 3), 1);
   Verify.assertEmpty(
       SingletonListTest.newWith(1).selectWith(Predicates2.<Integer>greaterThan(), 3));
 }
 @Override
 @Test
 public void reject() {
   Verify.assertContainsAll(this.newWith(1, 2, 3, 4).reject(Predicates.lessThan(3)), 3, 4);
   Verify.assertContainsAll(
       this.newWith(1, 2, 3, 4).reject(Predicates.lessThan(3), UnifiedSet.newSet()), 3, 4);
 }
  @Test
  public void drop() {
    Assert.assertEquals(FastList.newListWith(3, 4), Interval.fromTo(1, 4).drop(2));
    Verify.assertIterableEmpty(Interval.fromTo(1, 2).drop(3));

    Verify.assertThrows(IllegalArgumentException.class, () -> Interval.fromTo(1, 3).drop(-1));
  }
 @Test
 public void iterator() {
   Interval zero = Interval.zero();
   Iterator<Integer> zeroIterator = zero.iterator();
   Assert.assertTrue(zeroIterator.hasNext());
   Assert.assertEquals(Integer.valueOf(0), zeroIterator.next());
   Assert.assertFalse(zeroIterator.hasNext());
   Interval oneToFive = Interval.oneTo(5);
   Iterator<Integer> oneToFiveIterator = oneToFive.iterator();
   for (int i = 1; i < 6; i++) {
     Assert.assertTrue(oneToFiveIterator.hasNext());
     Assert.assertEquals(Integer.valueOf(i), oneToFiveIterator.next());
   }
   Verify.assertThrows(NoSuchElementException.class, (Runnable) oneToFiveIterator::next);
   Interval threeToNegativeThree = Interval.fromTo(3, -3);
   Iterator<Integer> threeToNegativeThreeIterator = threeToNegativeThree.iterator();
   for (int i = 3; i > -4; i--) {
     Assert.assertTrue(threeToNegativeThreeIterator.hasNext());
     Assert.assertEquals(Integer.valueOf(i), threeToNegativeThreeIterator.next());
   }
   Verify.assertThrows(
       NoSuchElementException.class, (Runnable) threeToNegativeThreeIterator::next);
   Verify.assertThrows(
       UnsupportedOperationException.class, () -> Interval.zeroTo(10).iterator().remove());
 }
 @Test
 public void toSet() {
   Interval interval = Interval.evensFromTo(0, 10);
   MutableSet<Integer> set = interval.toSet();
   Verify.assertContainsAll(set, 0, 2, 4, 6, 8, 10);
   Verify.assertSize(6, set);
 }
 @Test
 public void toFastList() {
   Interval interval = Interval.evensFromTo(0, 10);
   FastList<Integer> toList = (FastList<Integer>) interval.toList();
   Verify.assertStartsWith(toList, 0, 2, 4, 6, 8, 10);
   Verify.assertSize(6, toList);
 }
 @Test
 public void selectAndRejectWith() {
   MutableList<Integer> objects = SingletonListTest.newWith(1);
   Twin<MutableList<Integer>> result = objects.selectAndRejectWith(Object::equals, 1);
   Verify.assertSize(1, result.getOne());
   Verify.assertEmpty(result.getTwo());
 }
 @Test
 public void toArray() {
   MutableList<Integer> objects = SingletonListTest.newWith(1);
   Object[] array = objects.toArray();
   Verify.assertSize(1, array);
   Integer[] array2 = objects.toArray(new Integer[1]);
   Verify.assertSize(1, array2);
 }
 @Test
 public void rejectWith() {
   Verify.assertEmpty(SingletonListTest.newWith(1).rejectWith(Predicates2.<Integer>lessThan(), 3));
   Verify.assertContainsAll(
       SingletonListTest.newWith(1)
           .rejectWith(Predicates2.<Integer>greaterThan(), 3, UnifiedSet.<Integer>newSet()),
       1);
 }
 @Test
 public void toMap() {
   MutableList<Integer> integers = SingletonListTest.newWith(1);
   MutableMap<Integer, Integer> map =
       integers.toMap(Functions.getIntegerPassThru(), Functions.getIntegerPassThru());
   Verify.assertContainsAll(map.keySet(), 1);
   Verify.assertContainsAll(map.values(), 1);
 }
 @Override
 @Test
 public void clear() {
   MutableList<Integer> integers = this.newWith(1, 2, 3, 4);
   Verify.assertNotEmpty(integers);
   integers.clear();
   Verify.assertEmpty(integers);
 }
 @Test
 public void without() {
   MutableList<Integer> list = new SingletonList<>(2);
   Assert.assertSame(list, list.without(9));
   list = list.without(2);
   Verify.assertListsEqual(Lists.mutable.of(), list);
   Verify.assertInstanceOf(EmptyList.class, list);
 }
 @Override
 @Test
 public void removeIfWith() {
   MutableList<Integer> objects = MultiReaderFastList.newListWith(1, 2, 3, null);
   Assert.assertTrue(objects.removeIfWith((each, ignored) -> each == null, null));
   Verify.assertSize(3, objects);
   Verify.assertContainsAll(objects, 1, 2, 3);
 }
 @Test
 public void serializationOfSublist() {
   MutableList<Integer> collection = this.newWith(1, 2, 3, 4, 5);
   MutableList<Integer> deserializedCollection =
       SerializeTestHelper.serializeDeserialize(collection.subList(0, 2));
   Verify.assertSize(2, deserializedCollection);
   Verify.assertStartsWith(deserializedCollection, 1, 2);
   Assert.assertEquals(collection.subList(0, 2), deserializedCollection);
 }
 @Test
 public void fromAndToAndBy() {
   Interval interval = Interval.from(1);
   Interval interval2 = interval.to(10);
   Interval interval3 = interval2.by(2);
   Verify.assertEqualsAndHashCode(interval, Interval.fromTo(1, 1));
   Verify.assertEqualsAndHashCode(interval2, Interval.fromTo(1, 10));
   Verify.assertEqualsAndHashCode(interval3, Interval.fromToBy(1, 10, 2));
 }
 @Test
 public void collectIf() {
   Verify.assertContainsAll(
       SingletonListTest.newWith(1).collectIf(Integer.class::isInstance, String::valueOf), "1");
   Verify.assertContainsAll(
       SingletonListTest.newWith(1)
           .collectIf(Integer.class::isInstance, String::valueOf, FastList.<String>newList()),
       "1");
 }
 @Override
 @Test
 public void selectAndRejectWith() {
   MutableList<Integer> list = this.getIntegerList();
   Twin<MutableList<Integer>> result =
       list.selectAndRejectWith(Predicates2.in(), Lists.fixedSize.of(1));
   Verify.assertSize(1, result.getOne());
   Verify.assertSize(4, result.getTwo());
 }
 @Override
 @Test
 public void addAllAtIndex() {
   MutableList<Integer> integers = this.newWith(5);
   integers.addAll(0, Lists.fixedSize.of(1, 2, 3, 4));
   Verify.assertStartsWith(integers, 1, 2, 3, 4, 5);
   integers.addAll(0, this.newWith(-3, -2, -1, 0));
   Verify.assertStartsWith(integers, -3, -2, -1, 0, 1, 2, 3, 4, 5);
 }
 @Override
 @Test
 public void serialization() {
   MutableList<Integer> collection = this.newWith(1, 2, 3, 4, 5);
   MutableList<Integer> deserializedCollection =
       SerializeTestHelper.serializeDeserialize(collection);
   Verify.assertSize(5, deserializedCollection);
   Verify.assertStartsWith(deserializedCollection, 1, 2, 3, 4, 5);
   Assert.assertEquals(collection, deserializedCollection);
 }
 @Test
 public void flatCollect() {
   Function<Integer, MutableSet<String>> function =
       object -> UnifiedSet.newSetWith(object.toString());
   Verify.assertListsEqual(
       FastList.newListWith("1"), SingletonListTest.newWith(1).flatCollect(function));
   Verify.assertSetsEqual(
       UnifiedSet.newSetWith("1"),
       SingletonListTest.newWith(1).flatCollect(function, UnifiedSet.<String>newSet()));
 }
 @Test
 public void toSortedList() {
   MutableList<Integer> integers = SingletonListTest.newWith(1);
   MutableList<Integer> list = integers.toSortedList(Collections.<Integer>reverseOrder());
   Verify.assertStartsWith(list, 1);
   Assert.assertNotSame(integers, list);
   MutableList<Integer> list2 = integers.toSortedList();
   Verify.assertStartsWith(list2, 1);
   Assert.assertNotSame(integers, list2);
 }
예제 #26
0
 @Test
 public void copySet() {
   Verify.assertInstanceOf(ImmutableSet.class, Sets.immutable.ofAll(Sets.fixedSize.of()));
   MutableSet<Integer> set = Sets.fixedSize.of(1);
   ImmutableSet<Integer> immutableSet = set.toImmutable();
   Verify.assertInstanceOf(ImmutableSet.class, Sets.immutable.ofAll(set));
   Verify.assertInstanceOf(
       ImmutableSet.class, Sets.immutable.ofAll(UnifiedSet.newSetWith(1, 2, 3, 4, 5)));
   Assert.assertSame(Sets.immutable.ofAll(immutableSet.castToSet()), immutableSet);
 }
 @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);
 }
 @Test
 public void sortThisOnListWithMoreThan9Elements() {
   MutableList<Integer> integers = this.newWith(2, 3, 4, 1, 5, 7, 6, 8, 10, 9);
   Verify.assertStartsWith(integers.sortThis(), 1, 2, 3, 4);
   MutableList<Integer> integers2 = this.newWith(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
   Verify.assertStartsWith(
       integers2.sortThis(Collections.reverseOrder()), 10, 9, 8, 7, 6, 5, 4, 3, 2, 1);
   MutableList<Integer> integers3 = this.newWith(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
   Verify.assertStartsWith(integers3.sortThis(), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
 }
 @Test
 public void sortThisOnListWithLessThan10Elements() {
   MutableList<Integer> integers = this.newWith(2, 3, 4, 1, 7, 9, 6, 8, 5);
   Verify.assertStartsWith(integers.sortThis(), 1, 2, 3, 4, 5, 6, 7, 8, 9);
   MutableList<Integer> integers2 = this.newWith(1, 2, 3, 4, 5, 6, 7, 8, 9);
   Verify.assertStartsWith(
       integers2.sortThis(Collections.reverseOrder()), 9, 8, 7, 6, 5, 4, 3, 2, 1);
   MutableList<Integer> integers3 = this.newWith(1, 2, 3, 4, 5, 6, 7, 8, 9);
   Verify.assertStartsWith(integers3.sortThis(), 1, 2, 3, 4, 5, 6, 7, 8, 9);
   Verify.assertInstanceOf(MultiReaderFastList.class, integers3.sortThis());
 }
 @Test
 public void addAllEmpty() {
   MutableList<Integer> integers = MultiReaderFastList.newList();
   integers.addAll(Lists.fixedSize.of());
   Verify.assertEmpty(integers);
   integers.addAll(Sets.fixedSize.of());
   Verify.assertEmpty(integers);
   integers.addAll(FastList.newList());
   Verify.assertEmpty(integers);
   integers.addAll(ArrayAdapter.newArray());
   Verify.assertEmpty(integers);
 }