Esempio n. 1
0
  public static void testPickNext() {
    List<Integer> list = new ArrayList<>(10);
    for (int i = 0; i < 10; i++) list.add(i);
    Integer num = Util.pickNext(list, 5);
    System.out.println("number next to 5: " + num);
    assert num != null;
    assert num.equals(6);

    num = Util.pickNext(list, 9);
    System.out.println("number next to 9: " + num);
    assert num != null;
    assert num.equals(0);

    num = Util.pickNext(list, 11);
    assert num == null;
  }
Esempio n. 2
0
  public static void testPickNextN() {
    List<Integer> list = Arrays.asList(1, 2, 3, 4);
    List<Integer> result = Util.pickNext(list, 0, 1);
    assert result.isEmpty();

    result = Util.pickNext(list, 1, 1);
    System.out.println("result = " + result);
    assert result.size() == 1;
    assert result.contains(2);

    result = Util.pickNext(list, 3, 2);
    System.out.println("result = " + result);
    assert result.size() == 2;
    assert result.contains(4) && result.contains(1);

    result = Util.pickNext(list, 4, 5);
    System.out.println("result = " + result);
    assert result.size() == 3;
    assert result.contains(1) && result.contains(2) && result.contains(3);
  }