コード例 #1
0
  @Test
  public void sortOnListWithLessThan10Elements() {
    ArrayList<Integer> integers = this.newArrayList(2, 3, 4, 1, 5, 7, 6, 9, 8);
    Verify.assertStartsWith(ArrayListIterate.sortThis(integers), 1, 2, 3, 4, 5, 6, 7, 8, 9);

    ArrayList<Integer> integers2 = this.newArrayList(1, 2, 3, 4, 5, 6, 7, 8, 9);
    Verify.assertStartsWith(
        ArrayListIterate.sortThis(integers2, Collections.<Integer>reverseOrder()),
        9,
        8,
        7,
        6,
        5,
        4,
        3,
        2,
        1);

    ArrayList<Integer> integers3 = this.newArrayList(1, 2, 3, 4, 5, 6, 7, 8, 9);
    Verify.assertStartsWith(ArrayListIterate.sortThis(integers3), 1, 2, 3, 4, 5, 6, 7, 8, 9);

    ArrayList<Integer> integers4 = this.newArrayList(9, 8, 7, 6, 5, 4, 3, 2, 1);
    Verify.assertStartsWith(ArrayListIterate.sortThis(integers4), 1, 2, 3, 4, 5, 6, 7, 8, 9);

    ThisIsNotAnArrayList<Integer> arrayListThatIsnt =
        new ThisIsNotAnArrayList<Integer>(FastList.newListWith(9, 8, 7, 6, 5, 4, 3, 2, 1));
    Verify.assertStartsWith(
        ArrayListIterate.sortThis(arrayListThatIsnt), 1, 2, 3, 4, 5, 6, 7, 8, 9);
  }
コード例 #2
0
 @Test
 public void sortingWitoutAccessToInternalArray() {
   ThisIsNotAnArrayList<Integer> arrayListThatIsnt =
       new ThisIsNotAnArrayList<Integer>(FastList.newListWith(5, 3, 4, 1, 2));
   Verify.assertStartsWith(
       ArrayListIterate.sortThis(arrayListThatIsnt, Comparators.naturalOrder()), 1, 2, 3, 4, 5);
 }
コード例 #3
0
  @Test
  public void sortOnListWithMoreThan10Elements() {
    ArrayList<Integer> integers = this.newArrayList(2, 3, 4, 1, 5, 7, 6, 8, 10, 9);
    Verify.assertStartsWith(ArrayListIterate.sortThis(integers), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

    ArrayList<Integer> integers2 = this.newArrayList(1, 2, 3, 4, 5, 6, 7, 8);
    Verify.assertStartsWith(
        ArrayListIterate.sortThis(integers2, Collections.<Integer>reverseOrder()),
        8,
        7,
        6,
        5,
        4,
        3,
        2,
        1);

    ArrayList<Integer> integers3 = this.newArrayList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
    Verify.assertStartsWith(ArrayListIterate.sortThis(integers3), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
  }