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"));
    }
}

@@ -1534,11 +1534,522 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void testDifference() %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        Sets.SetView%3CString%3E diff = Sets.difference(first, second);%0A        assertThat(diff).containsOnly(%22bully%22, %22vertex%22);%0A%0A        assertThat(first.stream()%0A                .filter(s -%3E !second.contains(s))%0A                .collect(Collectors.toSet()))%0A                .containsOnly(%22bully%22, %22vertex%22);%0A    %7D
 %0A%7D%0A

Add Sets#difference