/**
 * Performs some basic testing of a RockPaperScissors implementation.
 *
 * @author Zach Tomaszewski
 */
public class RockPaperScissorsTester {

  public static void main(String[] args) {
    //should have a default constructor
    System.out.println("Building a new RockPaperScissors (RPS) object.");
    RockPaperScissors rps = new RockPaperScissors();

    //test an new RPS
    System.out.println("For a new unused RPS: ");
    test("getComputerMove()", RockPaperScissors.NO_MOVE, rps.getComputerMove());
    test("getOutcome()", RockPaperScissors.NO_MOVE, rps.getOutcome());

    //play a game
    System.out.println();
    rps.play(RockPaperScissors.ROCK);
    System.out.println("Now after play(ROCK)...");

    //repeat calls should always be equal
    test("getComputerMove()", rps.getComputerMove(), rps.getComputerMove());
    test("getComputerMove()", rps.getComputerMove(), rps.getComputerMove());

    //determine if outcome is correct
    int outcome;
    if (rps.getComputerMove() == RockPaperScissors.ROCK) {
      outcome = RockPaperScissors.DRAW;
    }else if (rps.getComputerMove() == RockPaperScissors.PAPER) {
      outcome = RockPaperScissors.LOSE;
    }else {
      outcome = RockPaperScissors.WIN;
    }
    test("getOutcome() is correct [this test assumes getComputerMove() is correct]",
        outcome, rps.getOutcome());
    //outcome should be consistent until play is called again
    test("getOutcome() is stable", rps.getOutcome(), rps.getOutcome());

    //Things not tested here:
    // * That the computer chooses evenly from all possible random moves
    //   (that is, if this test were run multiple times, sometimes the
    //    computer would win, sometimes lose, and sometimes draw)
    // * That play(int) returns the correct boolean value and does nothing
    //   (besides return false) if passed an invalid argument.

  }


  /**
   * Prints a single line describing a test, including whether it PASSed
   * or FAILed.  A test passes if its expected value equaled the actual value.
   * Returns whether the test passed or failed.
   */
  public static boolean test(String desc, int expected, int actual) {
    //determine and print results first (so all results are in same column)
    boolean passed = (expected == actual);
    if (passed) {
      System.out.print("PASS: ");
    }else {
      System.out.print("FAIL: ");
    }

    //describe test performed, with expected and actual values
    System.out.println(desc + " [" + expected + "]: " + actual);
    return passed;
  }

}
