package com.janosgyerik.utils.misc;

import org.junit.Test;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

import static com.janosgyerik.utils.misc.IterTools.toList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;

public class IterToolsTest {

    private <T> Set<List<T>> permutations(List<T> nums) {
        return IterTools.toSet(IterTools.permutations(nums));
    }

    @Test
    public void test_permutate_empty() {
        assertEquals(Collections.singleton(Collections.emptyList()), permutations(Collections.emptyList()));
    }

    @Test
    public void test_permutate_1() {
        assertEquals(Collections.singleton(Collections.singletonList(1)), permutations(Collections.singletonList(1)));
    }

    private Set<List<Integer>> makeSet(List<List<Integer>> lists) {
        Set<List<Integer>> result = new HashSet<>();
        result.addAll(lists);
        return result;
    }

    @Test
    public void test_permutate_1_2() {
        assertEquals(
            makeSet(Arrays.asList(Arrays.asList(1, 2), Arrays.asList(2, 1))),
            permutations(Arrays.asList(1, 2)));
        assertEquals(
            makeSet(Arrays.asList(Arrays.asList(2, 1), Arrays.asList(1, 2))),
            permutations(Arrays.asList(1, 2)));
    }

    @Test
    public void test_permutate_1_2_3() {
        assertEquals(
            makeSet(Arrays.asList(Arrays.asList(1, 2, 3), Arrays.asList(1, 3, 2), Arrays.asList(2, 1, 3),
                Arrays.asList(2, 3, 1), Arrays.asList(3, 1, 2), Arrays.asList(3, 2, 1))),
            permutations(Arrays.asList(1, 2, 3)));
    }

    @Test
    public void should_get_equal_list_from_iterator() {
        List<Integer> list = Arrays.asList(3, 1, 4, 5, 2);
        assertEquals(list, toList(list.iterator()));
    }

    @Test
    public void should_get_empty_list_from_empty_iterator() {
        List<Integer> list = Collections.emptyList();
        assertEquals(list, toList(list.iterator()));
    }

    @Test
    public void should_get_1_empty_permutation_for_empty_list() {
        Iterable<List<Integer>> permutations = IterTools.permutations(0);
        assertThat(permutations).containsOnlyElementsOf(Collections.singleton(Collections.emptyList()));
    }

    @Test
    public void should_get_1_permutation_for_singleton_list() {
        Set<List<Integer>> permutations = permutations(Collections.singletonList(7));
        assertThat(permutations).containsOnlyElementsOf(Collections.singleton(Collections.singletonList(7)));
    }

    @Test
    public void should_get_2_permutations_for_x_y() {
        Set<List<Character>> permutations = permutations(Arrays.asList('x', 'y'));
        assertThat(permutations).containsOnlyElementsOf(Arrays.asList(
            Arrays.asList('x', 'y'),
            Arrays.asList('y', 'x')
        ));
    }

    @Test
    public void should_get_6_permutations_for_1_2_3() {
        Set<List<Integer>> permutations = permutations(Arrays.asList(1, 2, 3));
        assertThat(permutations).containsOnlyElementsOf(Arrays.asList(
            Arrays.asList(1, 2, 3),
            Arrays.asList(1, 3, 2),
            Arrays.asList(2, 1, 3),
            Arrays.asList(2, 3, 1),
            Arrays.asList(3, 1, 2),
            Arrays.asList(3, 2, 1)
        ));
    }

    @Test
    public void should_get_equal_permutations_from_recursion_and_iterator() {
        List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6);
        Iterable<List<Integer>> permutations = IterTools.permutations(6);
        Set<List<Integer>> set = StreamSupport.stream(permutations.spliterator(), false).collect(Collectors.toSet());
        assertEquals(set, permutations(list));
    }
}

@@ -75,9 +75,14 @@
 til.
-*
+Arrays
 ;%0Aim
@@ -100,24 +100,18 @@
 til.
-stream.
 Collect
-or
+ion
 s;%0Ai
@@ -130,27 +130,11 @@
 til.
-stream.StreamSuppor
+Lis
 t;%0A%0A
@@ -188,1846 +188,109 @@
 ols.
-toList;%0Aimport static org.assertj.core.api.Assertions.assertThat;%0Aimport static org.junit.Assert.assertEquals;%0A%0Apublic class IterToolsTest %7B%0A%0A    private %3CT%3E Set%3CList%3CT%3E%3E permutations(List%3CT%3E nums) %7B%0A        return IterTools.toSet(IterTools.permutations(nums));%0A    %7D%0A%0A    @Test%0A    public void test_permutate_empty() %7B%0A        assertEquals(Collections.singleton(Collections.emptyList()), permutations(Collections.emptyList()));%0A    %7D%0A%0A    @Test%0A    public void test_permutate_1() %7B%0A        assertEquals(Collections.singleton(Collections.singletonList(1)), permutations(Collections.singletonList(1)));%0A    %7D%0A%0A    private Set%3CList%3CInteger%3E%3E makeSet(List%3CList%3CInteger%3E%3E lists) %7B%0A        Set%3CList%3CInteger%3E%3E result = new HashSet%3C%3E();%0A        result.addAll(lists);%0A        return result;%0A    %7D%0A%0A    @Test%0A    public void test_permutate_1_2() %7B%0A        assertEquals(%0A            makeSet(Arrays.asList(Arrays.asList(1, 2), Arrays.asList(2, 1))),%0A            permutations(Arrays.asList(1, 2)));%0A        assertEquals(%0A            makeSet(Arrays.asList(Arrays.asList(2, 1), Arrays.asList(1, 2))),%0A            permutations(Arrays.asList(1, 2)));%0A    %7D%0A%0A    @Test%0A    public void test_permutate_1_2_3() %7B%0A        assertEquals(%0A            makeSet(Arrays.asList(Arrays.asList(1, 2, 3), Arrays.asList(1, 3, 2), Arrays.asList(2, 1, 3),%0A                Arrays.asList(2, 3, 1), Arrays.asList(3, 1, 2), Arrays.asList(3, 2, 1))),%0A            permutations(Arrays.asList(1, 2, 3)));%0A    %7D%0A%0A    @Test%0A    public void should_get_equal_list_from_iterator() %7B%0A        List%3CInteger%3E list = Arrays.asList(3, 1, 4, 5, 2);%0A        assertEquals(list, toList(list.iterator()));%0A    %7D%0A%0A    @Test%0A    public void should_get_empty_list_from_empty_iterator() %7B%0A        List%3CInteger%3E list = Collections.emptyList();%0A        assertEquals(list, toList(list.iterator()));%0A    %7D
+permutations;%0Aimport static org.assertj.core.api.Assertions.assertThat;%0A%0Apublic class IterToolsTest %7B
 %0A%0A  
@@ -406,34 +406,24 @@
 mutations = 
-IterTools.
 permutations
@@ -613,35 +613,40 @@
 ist() %7B%0A        
-Set
+Iterable
 %3CList%3CInteger%3E%3E 
@@ -889,27 +889,32 @@
 ) %7B%0A        
-Set
+Iterable
 %3CList%3CCharac
@@ -1202,35 +1202,40 @@
 2_3() %7B%0A        
-Set
+Iterable
 %3CList%3CInteger%3E%3E 
@@ -1594,403 +1594,7 @@
    %7D
-%0A%0A    @Test%0A    public void should_get_equal_permutations_from_recursion_and_iterator() %7B%0A        List%3CInteger%3E list = Arrays.asList(1, 2, 3, 4, 5, 6);%0A        Iterable%3CList%3CInteger%3E%3E permutations = IterTools.permutations(6);%0A        Set%3CList%3CInteger%3E%3E set = StreamSupport.stream(permutations.spliterator(), false).collect(Collectors.toSet());%0A        assertEquals(set, permutations(list));%0A    %7D
 %0A%7D%0A

Remove redundant tests