package net.wolfgangwerner.kata.set;

import org.junit.Test;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertTrue;


public class SetRecognitionTest {

    /* Test Deck Blueprint
        Map<CardKey, Card> testCards = new HashMap<>();
        Card c0 = Card.of(Shape.PEANUT, Pattern.FULL, Color.GREEN,Count.TWO);
        Card c1 = Card.of(Shape.PEANUT, Pattern.STRIPED, Color.RED,Count.ONE);
        Card c2 = Card.of(Shape.ELLIPSE, Pattern.FULL, Color.RED,Count.ONE);
        Card c3 = Card.of(Shape.TRIANGLE, Pattern.FULL, Color.RED,Count.TWO);
        Card c4 = Card.of(Shape.PEANUT, Pattern.FULL, Color.GREEN,Count.THREE);
        Card c5 = Card.of(Shape.TRIANGLE, Pattern.FULL, Color.VOILET,Count.THREE);
        Card c6 = Card.of(Shape.PEANUT, Pattern.FULL, Color.GREEN,Count.ONE);
        Card c7 = Card.of(Shape.PEANUT, Pattern.EMPTY, Color.VOILET,Count.ONE);
        Card c8 = Card.of(Shape.TRIANGLE, Pattern.EMPTY, Color.VOILET,Count.ONE);

        testCards.put(CardKey.of(c0), c0);
        testCards.put(CardKey.of(c1), c1);
        testCards.put(CardKey.of(c2), c2);
        testCards.put(CardKey.of(c3), c3);
        testCards.put(CardKey.of(c4), c4);
        testCards.put(CardKey.of(c5), c5);
        testCards.put(CardKey.of(c6), c6);
        testCards.put(CardKey.of(c7), c7);
        testCards.put(CardKey.of(c8), c8);
     */

    @Test
    public void singleSetMatchingShapePatternAndColorIsFound() {
        Map<CardKey, Card> testCards = new HashMap<>();
        Card c0 = Card.of(Shape.PEANUT, Pattern.FULL, Color.GREEN,Count.TWO);
        Card c1 = Card.of(Shape.PEANUT, Pattern.STRIPED, Color.RED,Count.ONE);
        Card c2 = Card.of(Shape.ELLIPSE, Pattern.FULL, Color.RED,Count.ONE);
        Card c3 = Card.of(Shape.TRIANGLE, Pattern.FULL, Color.RED,Count.TWO);
        Card c4 = Card.of(Shape.PEANUT, Pattern.FULL, Color.GREEN,Count.THREE);
        Card c5 = Card.of(Shape.TRIANGLE, Pattern.FULL, Color.VOILET,Count.THREE);
        Card c6 = Card.of(Shape.PEANUT, Pattern.FULL, Color.GREEN,Count.ONE);
        Card c7 = Card.of(Shape.PEANUT, Pattern.EMPTY, Color.VOILET,Count.ONE);
        Card c8 = Card.of(Shape.TRIANGLE, Pattern.EMPTY, Color.VOILET,Count.ONE);
        Card c9 = Card.of(Shape.TRIANGLE, Pattern.STRIPED, Color.VOILET,Count.THREE);
        Card c10 = Card.of(Shape.ELLIPSE, Pattern.STRIPED, Color.GREEN,Count.ONE);
        Card c11 = Card.of(Shape.PEANUT, Pattern.STRIPED, Color.VOILET,Count.ONE);
        Card c12 = Card.of(Shape.TRIANGLE, Pattern.STRIPED, Color.VOILET,Count.ONE);

        testCards.put(CardKey.of(c0), c0);
        testCards.put(CardKey.of(c1), c1);
        testCards.put(CardKey.of(c2), c2);
        testCards.put(CardKey.of(c3), c3);
        testCards.put(CardKey.of(c4), c4);
        testCards.put(CardKey.of(c5), c5);
        testCards.put(CardKey.of(c6), c6);
        testCards.put(CardKey.of(c7), c7);
        testCards.put(CardKey.of(c8), c8);
        testCards.put(CardKey.of(c9), c9);
        testCards.put(CardKey.of(c10), c10);
        testCards.put(CardKey.of(c11), c11);
        testCards.put(CardKey.of(c12), c12);

        MockDeck deck = new MockDeck(testCards);
        Hand hand = new Hand(deck);

        Set<CardSet> recognizedSets = hand.findSets();
        System.out.println(recognizedSets);

        assertThat(recognizedSets.size(), is(4));

        Set<CardSet> expectedSets = new HashSet<>();
        expectedSets.add(new CardSet(c0,c4,c6));
        expectedSets.add(new CardSet(c6,c1,c7));
        expectedSets.add(new CardSet(c0,c5,c2));
        expectedSets.add(new CardSet(c11,c10,c1));

        assertTrue(recognizedSets.containsAll(expectedSets));

    }
}

@@ -1569,16 +1569,167 @@
  @Test%0D%0A
+    //THIS TEST IS FLAKEY, the reason is that the set recognition algorithm is wrong%0D%0A    //it finds only valid sets, but not neccesarily all of them%0D%0A
     publ

comment on failing test