package com.github.arteam.jgcompare;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import org.assertj.core.api.Assertions;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import static org.assertj.core.api.Assertions.assertThat;

/**
 * Date: 4/14/15
 * Time: 9:04 PM
 *
 * @author Artem Prigoda
 */
public class SetsTest {

    @Test
    @SuppressWarnings("unchecked")
    public void testCartesianProduct() {
        Set<String> first = ImmutableSet.of("1", "2");
        Set<String> second = ImmutableSet.of("floor", "arch", "gamble");
        assertThat(Sets.cartesianProduct(first, second)).containsOnly(
                ImmutableList.of("1", "floor"),
                ImmutableList.of("1", "arch"),
                ImmutableList.of("1", "gamble"),
                ImmutableList.of("2", "floor"),
                ImmutableList.of("2", "arch"),
                ImmutableList.of("2", "gamble"));

        assertThat(first.stream()
                .flatMap(s1 -> second.stream().map(s2 -> Arrays.asList(s1, s2)))
                .collect(Collectors.toSet())).containsOnly(
                ImmutableList.of("1", "floor"),
                ImmutableList.of("1", "arch"),
                ImmutableList.of("1", "gamble"),
                ImmutableList.of("2", "floor"),
                ImmutableList.of("2", "arch"),
                ImmutableList.of("2", "gamble"));
    }

    @Test
    public void testDifference() {
        Set<String> first = ImmutableSet.of("tweak", "perf", "bully", "vertex");
        Set<String> second = ImmutableSet.of("perf", "moan", "tweak");
        Sets.SetView<String> diff = Sets.difference(first, second);
        assertThat(diff).containsOnly("bully", "vertex");

        assertThat(first.stream()
                .filter(s -> !second.contains(s))
                .collect(Collectors.toSet()))
                .containsOnly("bully", "vertex");
    }
}

@@ -334,16 +334,48 @@
 lectors;
+%0Aimport java.util.stream.Stream;
 %0A%0Aimport
@@ -1777,36 +1777,19 @@
     
-Sets.SetView%3CString%3E diff = 
+assertThat(
 Sets
@@ -1818,33 +1818,8 @@
 ond)
-;%0A        assertThat(diff
 ).co
@@ -1976,24 +1976,24 @@
 s.toSet()))%0A
-
             
@@ -2035,11 +2035,578 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void testSymmetricDifference() %7B%0A        Set%3CString%3E first = ImmutableSet.of(%22tweak%22, %22perf%22, %22bully%22, %22vertex%22);%0A        Set%3CString%3E second = ImmutableSet.of(%22perf%22, %22moan%22, %22tweak%22);%0A        assertThat(Sets.symmetricDifference(first, second)).containsOnly(%22bully%22, %22vertex%22, %22moan%22);%0A%0A        assertThat(Stream.concat(first.stream().filter(s -%3E !second.contains(s)),%0A                second.stream().filter(s -%3E !first.contains(s)))%0A                .collect(Collectors.toSet()))%0A                .containsOnly(%22bully%22, %22vertex%22, %22moan%22);%0A%0A    %7D
 %0A%7D%0A

Add Sets#symmetricDifference