package com.github.donkirkby.vograbulary.ultraghost;

import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.number.OrderingComparison.*;
import static org.junit.Assert.*;

import java.io.StringReader;

import org.junit.Before;
import org.junit.Test;

public class ComputerStudentTest {
    private boolean isSolutionSet = false;
    private String solution;
    private ComputerStudent student;
    private WordList wordList;
    
    @Before
    public void setUp() {
        wordList = new WordList();
        wordList.read(new StringReader("PRICE\nPIECE\nPIPE"));
        student = new ComputerStudent();
        student.setWordList(wordList);
        student.setListener(new Student.StudentListener() {
            
            @Override
            public void submitSolution(String solution) {
                isSolutionSet = true;
                ComputerStudentTest.this.solution = solution;
            }
            
            @Override
            public void submitChallenge(String challenge, WordResult challengeResult) {
            }
            
            @Override
            public void showThinking() {
            }
            
            @Override
            public void askForSolution() {
            }
            
            @Override
            public void askForChallenge() {
            }
        });
    }
    
    @Test
    public void noSolutionFound() {
        int batchSize = 100;
        assertThat("word count", wordList.size(), lessThan(batchSize));
        student.setSearchBatchSize(batchSize);
        boolean isActiveStudent = true;
        student.startSolving("AXR", isActiveStudent);
        
        student.runSearchBatch();
        
        assertThat("is solution submitted", isSolutionSet, is(true));
        assertThat("solution", solution, nullValue());
    }
    
    @Test
    public void createSearchTaskCancelsAfterLastWord() {
        assertThat("word count", wordList.size(), is(3));
        boolean isActiveStudent = true;
        student.startSolving("PIE", isActiveStudent);
        String expectedSolution = "PIPE";

        student.runSearchBatch();
        boolean isCompleteAfterSecondLast = student.runSearchBatch();
        boolean isCompleteAfterLast = student.runSearchBatch();
        
        assertThat(
                "is complete before last word", 
                isCompleteAfterSecondLast, 
                is(false));
        assertThat(
                "is complete after last word",
                isCompleteAfterLast,
                is(true));
        assertThat("solution", solution, is(expectedSolution));
    }
}

@@ -435,21 +435,107 @@
 rdList;%0A
+    private FocusField focus;%0A    %0A    private enum FocusField %7BSolution, Challenge%7D;%0A
     %0A
-
     @Bef
@@ -1218,24 +1218,54 @@
 hinking() %7B%0A
+                focus = null;%0A
             
@@ -1340,24 +1340,69 @@
 olution() %7B%0A
+                focus = FocusField.Solution;%0A
             
@@ -1478,24 +1478,70 @@
 allenge() %7B%0A
+                focus = FocusField.Challenge;%0A
             
@@ -2043,32 +2043,705 @@
 %0A    %0A    @Test%0A
+    public void maxBatchCount() %7B%0A        student.setMaxSearchBatchCount(1);%0A        %0A        boolean isActiveStudent = true;%0A        student.startSolving(%22AXR%22, isActiveStudent);%0A        %0A        boolean isFinished = student.runSearchBatch();%0A        %0A        assertThat(%22finished%22, isFinished, is(true));%0A    %7D%0A    %0A    @Test%0A    public void maxBatchCountInactiveStudent() %7B%0A        student.setMaxSearchBatchCount(1);%0A        %0A        boolean isActiveStudent = false;%0A        student.startSolving(%22AXR%22, isActiveStudent);%0A        %0A        boolean isFinished = student.runSearchBatch();%0A        %0A        assertThat(%22finished%22, isFinished, is(false));%0A    %7D%0A    %0A    @Test%0A
     public void 
@@ -3417,32 +3417,32 @@
      is(true));%0A
-
         assertTh
@@ -3495,10 +3495,533 @@
 ;%0A    %7D%0A
+    %0A    @Test%0A    public void startThinkingWhenActive() %7B%0A        focus = FocusField.Solution;%0A        boolean isActiveStudent = true;%0A        student.startSolving(%22PIE%22, isActiveStudent);%0A        %0A        assertThat(%22focus%22, focus, nullValue());%0A    %7D%0A    %0A    @Test%0A    public void startThinkingWhenInactive() %7B%0A        focus = FocusField.Solution;%0A        boolean isActiveStudent = false;%0A        student.startSolving(%22PIE%22, isActiveStudent);%0A        %0A        assertThat(%22focus%22, focus, is(FocusField.Solution));%0A    %7D%0A
 %7D%0A

Add some tests for ComputerStudent.