package ttsu.game.ai.heuristic.tictactoe;

import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Mockito.when;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import ttsu.game.ai.heuristic.tictactoe.TicTacToeEvaluator;
import ttsu.game.tictactoe.TicTacToeGameState;
import ttsu.game.tictactoe.TicTacToeGameState.Player;


@RunWith(MockitoJUnitRunner.class)
public class TicTacToeEvaluatorTest {

    private TicTacToeEvaluator evaluator;
    @Mock
    private TicTacToeGameState game;

    @Rule
    public ExpectedException thrown = ExpectedException.none();

    @Before
    public void setup() {
        evaluator = new TicTacToeEvaluator(Player.X);
    }

    // -- constructor

    @Test
    public void constructorNullPlayer() {
        thrown.expect(IllegalArgumentException.class);
        thrown.expectMessage("player cannot be null");
        new TicTacToeEvaluator(null);
    }
    
    // -- evaluate
    
    @Test
    public void evaluateWin() {
        when(game.hasWin(Player.X)).thenReturn(true);
        assertThat(evaluator.evaluate(game)).isEqualTo(100);
    }
    
    @Test
    public void evaluateLoss() {
        when(game.hasWin(Player.O)).thenReturn(true);
        assertThat(evaluator.evaluate(game)).isEqualTo(-1);
    }
    
    @Test
    public void evaluateDraw() {
        assertThat(evaluator.evaluate(game)).isEqualTo(0);
    }

    @Test
    public void evaluateNull() {
        thrown.expect(IllegalArgumentException.class);
        thrown.expectMessage("cannot evaluate null game");
        evaluator.evaluate(null);
    }
}

@@ -135,24 +135,50 @@
 to.when;%0D%0A%0D%0A
+import java.util.List;%0D%0A%0D%0A
 import org.j
@@ -187,24 +187,24 @@
 it.Before;%0D%0A
-
 import org.j
@@ -413,49 +413,25 @@
 ame.
-ai.heuristic.tictactoe.TicTacToeEvaluator
+DiscreteGameState
 ;%0D%0Ai
@@ -534,18 +534,16 @@
 yer;%0D%0A%0D%0A
-%0D%0A
 @RunWith
@@ -702,16 +702,81 @@
 e game;%0D
+%0A    @Mock%0D%0A    private List%3CDiscreteGameState%3E availableStates;%0D
 %0A%0D%0A    @
@@ -1185,30 +1185,26 @@
 l);%0D%0A    %7D%0D%0A
-    
 %0D%0A
+
     // -- ev
@@ -1211,22 +1211,18 @@
 aluate%0D%0A
-    
 %0D%0A
+
     @Tes
@@ -1372,10 +1372,319 @@
 To(1
-00
+);%0D%0A    %7D%0D%0A%0D%0A    @Test%0D%0A    public void evaluateWinConsidersAvailableMoves() %7B%0D%0A        when(game.hasWin(Player.X)).thenReturn(true);%0D%0A        when(game.availableStates()).thenReturn(availableStates);%0D%0A        when(availableStates.size()).thenReturn(5);%0D%0A        assertThat(evaluator.evaluate(game)).isEqualTo(6
 );%0D%0A
@@ -1682,38 +1682,34 @@
 lTo(6);%0D%0A    %7D%0D%0A
-    
 %0D%0A
+
     @Test%0D%0A    p
@@ -1860,20 +1860,16 @@
 %0A    %7D%0D%0A
-    
 %0D%0A    @T

fix and improve evaluator test