package com.janosgyerik.utils.misc;

import org.junit.Test;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static com.janosgyerik.utils.misc.IterTools.permutations;
import static org.assertj.core.api.Assertions.assertThat;

public class IterToolsTest {

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

    @Test
    public void should_get_1_permutation_for_singleton_list() {
        Iterable<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() {
        Iterable<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() {
        Iterable<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)
        ));
    }
}

@@ -75,67 +75,9 @@
 til.
-Arrays;%0Aimport java.util.Collections;%0Aimport java.util.List
+*
 ;%0A%0Ai
@@ -1532,11 +1532,319 @@
 );%0A    %7D
+%0A%0A    @Test(expected = NoSuchElementException.class)%0A    public void should_throw_exception_when_iterating_beyond_permutations() %7B%0A        Iterator%3CList%3CInteger%3E%3E iterator = permutations(3).iterator();%0A        while (iterator.hasNext()) %7B%0A            iterator.next();%0A        %7D%0A        iterator.next();%0A    %7D
 %0A%7D%0A

Add test for iterating over permutations