package hangman.core.state;

import hangman.core.guess.Guess;
import hangman.core.secret.Secret;
import hangman.core.secret.Secret.Category;
import org.junit.Before;
import org.junit.Test;

import java.util.HashSet;

public class GameStateTest {

    private final Guess ga = Guess.of('a');
    private final Guess gb = Guess.of('b');

    private GameState gsWithGuess;

    @Before
    public void setUp() {
        GameState gsNew = GameState.newGameState(10, Secret.of("dog", Category.ANIMALS), new HashSet<>());
        gsWithGuess = GameState.newGameStateWithGuess(gsNew, ga);
    }

    @Test(expected = UnsupportedOperationException.class)
    public void isImmutableAdd() {
        gsWithGuess.getGuesses().add(gb);
    }

    @Test(expected = UnsupportedOperationException.class)
    public void isImmutableRemove() {
        gsWithGuess.getGuesses().remove(ga);
    }

    @Test(expected = UnsupportedOperationException.class)
    public void isImmutableClear() {
        gsWithGuess.getGuesses().clear();
    }
}

@@ -22,16 +22,55 @@
 state;%0A%0A
+import com.google.common.collect.Sets;%0A
 import h
@@ -239,23 +239,186 @@
 va.util.
-HashSet
+Collections;%0Aimport java.util.HashSet;%0A%0Aimport static org.junit.Assert.assertEquals;%0Aimport static org.junit.Assert.assertFalse;%0Aimport static org.junit.Assert.assertTrue
 ;%0A%0Apubli
@@ -446,32 +446,39 @@
  %7B%0A%0A    private 
+static 
 final Guess ga =
@@ -473,18 +473,23 @@
 l Guess 
-ga
+GUESS_A
  = Guess
@@ -510,16 +510,23 @@
 private 
+static 
 final Gu
@@ -529,18 +529,23 @@
 l Guess 
-gb
+GUESS_B
  = Guess
@@ -554,16 +554,184 @@
 f('b');%0A
+    private static final Secret SECRET_ANIMAL = Secret.of(%22dog%22, Category.ANIMALS);%0A    private static final Secret SECRET_FRUIT= Secret.of(%22apple%22, Category.FRUITS);%0A%0A
 %0A    pri
@@ -965,18 +965,23 @@
 (gsNew, 
-ga
+GUESS_A
 );%0A    %7D
@@ -1116,10 +1116,15 @@
 add(
-gb
+GUESS_B
 );%0A 
@@ -1269,10 +1269,15 @@
 ove(
-ga
+GUESS_A
 );%0A 
@@ -1424,11 +1424,1308 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void equalsAndHashCode() %7B%0A        GameState gsOne = GameState.newGameState(10, SECRET_ANIMAL, Collections.emptySet());%0A        GameState gsTwo = GameState.newGameState(10, SECRET_ANIMAL, Collections.emptySet());%0A        GameState gsThree = GameState.newGameState(10, SECRET_ANIMAL, Collections.emptySet());%0A%0A        // equals%0A        assertFalse(%22equals: null%22, gsOne.equals(null));%0A        assertTrue(%22equals: is reflexive%22, gsOne.equals(gsOne));%0A        assertTrue(%22equals: is symmetric%22, gsOne.equals(gsTwo) && gsTwo.equals(gsOne));%0A        assertTrue(%22equals: is transitive%22, gsOne.equals(gsTwo) && gsTwo.equals(gsThree) && gsOne.equals(gsThree));%0A        assertTrue(%22equals: is consistent%22, gsOne.equals(gsTwo) && gsOne.equals(gsTwo));%0A%0A        GameState gsElevenMaxIncorrect = GameState.newGameState(11, SECRET_ANIMAL, Collections.emptySet());%0A        GameState gsFruit = GameState.newGameState(10, SECRET_FRUIT, Collections.emptySet());%0A        GameState gsAGuess = GameState.newGameState(10, SECRET_ANIMAL, Sets.newHashSet(GUESS_A));%0A%0A        assertFalse(gsOne.equals(gsElevenMaxIncorrect));%0A        assertFalse(gsOne.equals(gsFruit));%0A        assertFalse(gsOne.equals(gsAGuess));%0A%0A        // hashCode%0A        assertEquals(gsOne.hashCode(), gsTwo.hashCode());%0A    %7D
 %0A%7D%0A

test for hashCode & equals methods