import java.util.Random;
/****************************************************
 * YahtzeeTester will exercise the YUtil class to 
 * insure that the scoring is working correctly.
 * It uses a "check expect" to compare values and 
 * prints an error message if that test failed.
 *
 * @author Nancy Harris
 * @version V1 01/2012
 ****************************************************/
 public class YahtzeeTester
 {
   /**************************************************
    * main method carries out the checks and produces
    * the display
    *
    * @param args Command line arguments unused in this
    *             application
    *************************************************/
    public static void main (String args[])
    {
   		// Set up Dice - Random will not be used
			Dice dice = new Dice(new Random(), 5);
			 		
			// test Aces
			dice.setDie(0, 1);
			dice.setDie(1, 1);
			dice.setDie(2, 1);
			dice.setDie(3, 1);
			dice.setDie(4, 1);
			
			// check that the dice don't change
			System.out.println("Initial 1s: " + dice);
			
			// we can also test Yahtzee and 0 case for the other
			// top methods
			checkExpect("Checking Aces ", 5, YUtil.acesScore(dice));
			checkExpect("Checking Twos ", 0, YUtil.twosScore(dice));
			checkExpect("Checking Threes ", 0, YUtil.threeScore(dice));
			checkExpect("Checking Fours ", 0, YUtil.fourScore(dice));
			checkExpect("Checking Fives ", 0, YUtil.fiveScore(dice));
			checkExpect("Checking Sixes ", 0, YUtil.sixScore(dice));
			checkExpect("Checking Yahtzee ", 50, YUtil.yahtzeeScore(dice));
			checkExpect("Checking Chance ", 5, YUtil.chanceScore(dice));
			checkExpect("Checking Small ", 35, YUtil.smallScore(dice));
			checkExpect("Checking Large ", 40, YUtil.largeScore(dice));
			checkExpect("Checking Full House ", 25, YUtil.fullScore(dice));
			checkExpect("Checking Three of a Kind ", 5, YUtil.kind3Score(dice));
			checkExpect("Checking Four of a Kind ", 5, YUtil.kind4Score(dice));
			
		
			// test unqualified hands
			dice.setDie(0, 5);
			dice.setDie(1, 4);
			dice.setDie(2, 1);
			dice.setDie(3, 2);
			dice.setDie(4, 1);
			
			System.out.println();  // leave a space
			
			// check that the dice don't change
			System.out.println("Initial: " + dice);

			// we can also test Yahtzee and 0 case for the other
			// top methods
			checkExpect("Checking Aces ", 2, YUtil.acesScore(dice));
			checkExpect("Checking Twos ", 2, YUtil.twosScore(dice));
			checkExpect("Checking Threes ", 0, YUtil.threeScore(dice));
			checkExpect("Checking Fours ", 4, YUtil.fourScore(dice));
			checkExpect("Checking Fives ", 5, YUtil.fiveScore(dice));
			checkExpect("Checking Sixes ", 0, YUtil.sixScore(dice));
			checkExpect("Checking Yahtzee ", 0, YUtil.yahtzeeScore(dice));
			checkExpect("Checking Chance ", 13, YUtil.chanceScore(dice));
			checkExpect("Checking Small ", 0, YUtil.smallScore(dice));
			checkExpect("Checking Large ", 0, YUtil.largeScore(dice));
			checkExpect("Checking Full House ", 0, YUtil.fullScore(dice));
			checkExpect("Checking Three of a Kind ", 0, YUtil.kind3Score(dice));
			checkExpect("Checking Four of a Kind ", 0, YUtil.kind4Score(dice));

			// test that the dice don't change
			System.out.println("After checking: " + dice);
			
			// check each method for valid hands
			dice.setDie(0, 5);
			dice.setDie(1, 4);
			dice.setDie(2, 5);
			dice.setDie(3, 2);
			dice.setDie(4, 5);
			
			System.out.println(); // leave space
			
			System.out.println("Dice state: " + dice);

			checkExpect("Checking Fives ", 15, YUtil.fiveScore(dice));
			checkExpect("Checking 3 of a Kind ", 21, YUtil.kind3Score(dice));
			checkExpect("Checking Chance ", 21, YUtil.chanceScore(dice));
			checkExpect("Checking Full House ", 0, YUtil.fullScore(dice));
			checkExpect("Checking Small ", 0, YUtil.smallScore(dice)); 
			
			// check each method for valid hands
			dice.setDie(0, 6);
			dice.setDie(1, 2);
			dice.setDie(2, 4);
			dice.setDie(3, 1);
			dice.setDie(4, 3);
			
			System.out.println(); // leave space
			
			System.out.println("Dice state: " + dice);
			checkExpect("Checking Sixes ", 6, YUtil.sixScore(dice));
			checkExpect("Checking 3 of a Kind ", 0, YUtil.kind3Score(dice));
			checkExpect("Checking Chance ", 16, YUtil.chanceScore(dice));
			checkExpect("Checking Small ", 35, YUtil.smallScore(dice)); 
			checkExpect("Checking Large ", 0, YUtil.largeScore(dice));

			// check each method for valid hands
			dice.setDie(0, 2);
			dice.setDie(1, 1);
			dice.setDie(2, 5);
			dice.setDie(3, 3);
			dice.setDie(4, 4);
			
			System.out.println(); // leave space
			
			System.out.println("Dice state: " + dice);		
			checkExpect("Checking Threes ", 3, YUtil.threeScore(dice));
			checkExpect("Checking Chance ", 15, YUtil.chanceScore(dice));
			checkExpect("Checking Small ", 35, YUtil.smallScore(dice)); 
			checkExpect("Checking Large ", 40, YUtil.largeScore(dice));

			// check each method for valid hands
			dice.setDie(0, 3);
			dice.setDie(1, 3);
			dice.setDie(2, 2);
			dice.setDie(3, 3);
			dice.setDie(4, 3);
			
			System.out.println(); // leave space

			System.out.println("Dice state: " + dice);			
			checkExpect("Checking 3 of a Kind ", 14, YUtil.kind3Score(dice));
			checkExpect("Checking 4 of a Kind ", 14, YUtil.kind4Score(dice));
			checkExpect("Checking Yahtzee ", 0, YUtil.yahtzeeScore(dice)); 

			// check each method for valid hands
			dice.setDie(0, 2);
			dice.setDie(1, 3);
			dice.setDie(2, 2);
			dice.setDie(3, 3);
			dice.setDie(4, 3);
			
			System.out.println(); // leave space

			System.out.println("Dice state: " + dice);			
			checkExpect("Checking Full House ", 25, YUtil.fullScore(dice));
			checkExpect("Checking 3 of a Kind ", 13, YUtil.kind3Score(dice));
			checkExpect("Checking Yahtzee ", 0, YUtil.yahtzeeScore(dice)); 

    }
    
    /*************************************************
     * checkExpect compares two values to see if they
     * are the same. It prints the location message and 
     * either a correct message or the two mismatched 
     * values
     *
     * @param location Which test is running
     * @param expected The expected value - set
     * @param actual   The actual value - calculated
     *************************************************/
     public static void checkExpect(String location, int expected, int
      actual)
     {
         System.out.print(location);
			if (expected == actual)
				System.out.println(" -- Correct!");
			else
				System.out.println(" -- Expected " + expected + " Got " + actual);
     }
  }