import junit.framework.TestCase;
public class GuessDivisorsTester extends TestCase {
  
  public void testPlayFirstGuess() {
    GuessDivisors gd= new GuessDivisors(23);
    JOptionPane.setBufferedReaderToString("23");
    JOptionPane.resetStringBuffer();
    gd.play();
    String yourOutput= JOptionPane.getStringBufferContents();
    String oneGuess="\\s*Guess a positive integer.\\s*\\n+" +
      "\\s*You got it!\\s*\\n+.*";
    assertTrue("Your output:\n" + yourOutput,
               yourOutput.matches(oneGuess));
  }
  
  public void testPlayHiGuess() {
    GuessDivisors gd= new GuessDivisors(23);
    JOptionPane.setBufferedReaderToString("47\n23");
    JOptionPane.resetStringBuffer();
    gd.play();
    String yourOutput= JOptionPane.getStringBufferContents();
    String hiGuess= "\\s*Guess a positive integer.\\s*\\n+" +
      "\\s*My number divides your guess, leaving a remainder of\\s+1." +
      "\\s+Try again.\\s*\\n+" +
      "\\s*You got it!\\s*\\n+";
    assertTrue("Your output:\n" + yourOutput,
               yourOutput.matches(hiGuess));
  }
  
  public void testPlayHiLowGuess() {
    GuessDivisors gd= new GuessDivisors(23);
    JOptionPane.setBufferedReaderToString("47\n8\n23");
    JOptionPane.resetStringBuffer();
    gd.play();
    String yourOutput= JOptionPane.getStringBufferContents();
    String hiLowGuess= "\\s*Guess a positive integer.\\s*\\n+" +
      "\\s*My number divides your guess, leaving a remainder of\\s+1.\\s+" +
      "Try again.\\s*\\n+" +
      "\\s*Your guess divides my number, leaving a remainder of\\s+7.\\s+" +
      "Try again.\\s*\\n+" +
      "\\s*You got it!\\s*\\n+";
    assertTrue("Your output:\n" + yourOutput,
               yourOutput.matches(hiLowGuess));
  }
  
  public void testPlayHiLowHiGuess() {
    GuessDivisors gd= new GuessDivisors(23);
    JOptionPane.setBufferedReaderToString("47\n8\n43\n23");
    JOptionPane.resetStringBuffer();
    gd.play();
    String yourOutput= JOptionPane.getStringBufferContents();
    String hiLowHiGuess=
      "\\s*Guess a positive integer.\\s*\\n+" +
      "\\s*My number divides your guess,\\s+" +
      "leaving a remainder of\\s+1.\\s+Try again.\\s*\\n+" +
      "\\s*Your guess divides my number,\\s+" +
      "leaving a remainder of\\s+7.\\s+Try again.\\s*\\n+" +
      "\\s*My number divides your guess,\\s+" +
      "leaving a remainder of\\s+20.\\s+Try again.\\s*\\n" +
      "\\s*You got it!\\s*\\n+";
    assertTrue("Your output:\n" + yourOutput,
               yourOutput.matches(hiLowHiGuess));
  }
}


