@Test public void shrinksOfNonEmptyList() { List<List<Integer>> shrinks = Lists.shrinksOfOneItem( random, newArrayList(1, 2, 3), (r, i) -> { assumeThat(r, sameInstance(random)); return newArrayList(4, 5); }); assertEquals( newArrayList( newArrayList(4, 2, 3), newArrayList(5, 2, 3), newArrayList(1, 4, 3), newArrayList(1, 5, 3), newArrayList(1, 2, 4), newArrayList(1, 2, 5) ), shrinks); }
public static <T> List<List<T>> shrinksOfOneItem( SourceOfRandomness random, List<T> target, Shrink<T> shrink) { if (target.isEmpty()) return new ArrayList<>(); T head = target.get(0); List<T> tail = target.subList(1, target.size()); List<List<T>> shrinks = new ArrayList<>(); shrinks.addAll( shrink.shrink(random, head) .stream() .map(i -> { List<T> items = new ArrayList<>(); items.add(i); items.addAll(tail); return items; }) .collect(toList())); shrinks.addAll( shrinksOfOneItem(random, tail, shrink) .stream() .map(s -> { List<T> items = new ArrayList<>(); items.add(head); items.addAll(s); return items; }) .collect(toList())); return shrinks; }
Lists { public static <T> List<List<T>> shrinksOfOneItem( SourceOfRandomness random, List<T> target, Shrink<T> shrink) { if (target.isEmpty()) return new ArrayList<>(); T head = target.get(0); List<T> tail = target.subList(1, target.size()); List<List<T>> shrinks = new ArrayList<>(); shrinks.addAll( shrink.shrink(random, head) .stream() .map(i -> { List<T> items = new ArrayList<>(); items.add(i); items.addAll(tail); return items; }) .collect(toList())); shrinks.addAll( shrinksOfOneItem(random, tail, shrink) .stream() .map(s -> { List<T> items = new ArrayList<>(); items.add(head); items.addAll(s); return items; }) .collect(toList())); return shrinks; } }
Lists { public static <T> List<List<T>> shrinksOfOneItem( SourceOfRandomness random, List<T> target, Shrink<T> shrink) { if (target.isEmpty()) return new ArrayList<>(); T head = target.get(0); List<T> tail = target.subList(1, target.size()); List<List<T>> shrinks = new ArrayList<>(); shrinks.addAll( shrink.shrink(random, head) .stream() .map(i -> { List<T> items = new ArrayList<>(); items.add(i); items.addAll(tail); return items; }) .collect(toList())); shrinks.addAll( shrinksOfOneItem(random, tail, shrink) .stream() .map(s -> { List<T> items = new ArrayList<>(); items.add(head); items.addAll(s); return items; }) .collect(toList())); return shrinks; } private  Lists(); }
Lists { public static <T> List<List<T>> shrinksOfOneItem( SourceOfRandomness random, List<T> target, Shrink<T> shrink) { if (target.isEmpty()) return new ArrayList<>(); T head = target.get(0); List<T> tail = target.subList(1, target.size()); List<List<T>> shrinks = new ArrayList<>(); shrinks.addAll( shrink.shrink(random, head) .stream() .map(i -> { List<T> items = new ArrayList<>(); items.add(i); items.addAll(tail); return items; }) .collect(toList())); shrinks.addAll( shrinksOfOneItem(random, tail, shrink) .stream() .map(s -> { List<T> items = new ArrayList<>(); items.add(head); items.addAll(s); return items; }) .collect(toList())); return shrinks; } private  Lists(); static List<List<T>> removeFrom(List<T> target, int howMany); static List<List<T>> shrinksOfOneItem(
        SourceOfRandomness random,
        List<T> target,
        Shrink<T> shrink); static boolean isDistinct(List<T> target); }
Lists { public static <T> List<List<T>> shrinksOfOneItem( SourceOfRandomness random, List<T> target, Shrink<T> shrink) { if (target.isEmpty()) return new ArrayList<>(); T head = target.get(0); List<T> tail = target.subList(1, target.size()); List<List<T>> shrinks = new ArrayList<>(); shrinks.addAll( shrink.shrink(random, head) .stream() .map(i -> { List<T> items = new ArrayList<>(); items.add(i); items.addAll(tail); return items; }) .collect(toList())); shrinks.addAll( shrinksOfOneItem(random, tail, shrink) .stream() .map(s -> { List<T> items = new ArrayList<>(); items.add(head); items.addAll(s); return items; }) .collect(toList())); return shrinks; } private  Lists(); static List<List<T>> removeFrom(List<T> target, int howMany); static List<List<T>> shrinksOfOneItem(
        SourceOfRandomness random,
        List<T> target,
        Shrink<T> shrink); static boolean isDistinct(List<T> target);  }