public class DiceChecker
{
  public static void main(String[] args)
  {
    int errorCount = 0;
    
    System.out.println("Starting DiceChecker...");
    System.out.println("...");
    System.out.println("");
    
    System.out.println("Creating a bag of 12 6-sided dice, BAG1");
    System.out.println("...");
    System.out.println("");
    BagOfDice bog1 = new BagOfDice(12);
    Dice[] d1 = bog1.getDice();
    
    System.out.println("Checking BAG1 has all 6-sided dice");
    System.out.println("...");
    int size = d1.length;
    if(size != 12)
    {
      System.out.println("ERROR: BAG1 doesn't contain 12 dice.  Contains " + size + " dice instead");
      errorCount++;
    }
    for(int k=0; k<d1.length; k++)
    {
      int sides = d1[k].getSides();
      if(sides != 6)
      {
        errorCount++;
        System.out.println("ERROR: BAG1 Dice " + k + " doesn't have 6 sides, has " + sides + " isntead.");
      }
    }
    System.out.println("");
    
    int[] rolled = new int[d1.length];
    for(int k=0; k<d1.length; k++)
    {
      rolled[k] = d1[k].getNumRolled();
    }
  
    System.out.println("Rolling BAG1 (calling rollAllDice function)");
    System.out.println("...");
    int sum = bog1.rollAllDice();
    int testsum = 0;
    
    for(int k=0; k<d1.length; k++)
    {
      if(d1[k].getNumRolled() == rolled[k])
      {
        errorCount++;
        System.out.println("ERROR: Dice " + k + " was not rolled when rolling BAG1");
      }
      testsum += d1[k].getTop();
    }
    if(testsum != sum)
    {
      errorCount++;
      System.out.println("ERROR: BAG1 returned incorrect sum when calling rollAllDice.  Returned " + sum + " when sum of Dice Tops is " + testsum);
    }
    
    System.out.println("");
    
    System.out.println("");
    
    int[] diceSides = new int[7];
    for(int k=1; k<=7; k++)
    {
      diceSides[k-1] = k;
    }
    System.out.println("Creating Bag of Dice, BAG2, with dice of 1,2,3,4,5,6,7 sides");
    System.out.println("...");
    System.out.println("");
    BagOfDice bog2 = new BagOfDice(diceSides);
    Dice[] d2 = bog2.getDice();
    size = d2.length;
    
    
    System.out.println("Checking BAG2 has correct sided dice");
    System.out.println("...");
    size = d2.length;
    if(size != 7)
    {
      System.out.println("ERROR: BAG1 doesn't contain 7 dice.  Contains " + size + " dice instead");
      errorCount++;
    }
    for(int k=0; k<d2.length; k++)
    {
      int sides = d2[k].getSides();
      if(sides != k+1)
      {
        errorCount++;
        System.out.println("ERROR: BAG1 Dice " + k + " doesn't have " + (k+1) + " sides, has " + sides + " isntead.");
      }
    }
    System.out.println("");
    
    int[] rolled2 = new int[d2.length];
    for(int k=0; k<d2.length; k++)
    {
      rolled2[k] = d2[k].getNumRolled();
    }
    
    System.out.println("Rolling BAG2 (calling rollAllDice function)");
    System.out.println("...");
    sum = bog2.rollAllDice();
    testsum = 0;
    
    for(int k=0; k<d2.length; k++)
    {
      if(d2[k].getNumRolled() == rolled2[k])
      {
        errorCount++;
        System.out.println("ERROR: Dice " + k + " was not rolled when rolling BAG2");
      }
      testsum += d2[k].getTop();
    }
    if(testsum != sum)
    {
      errorCount++;
      System.out.println("ERROR: BAG2 returned incorrect sum when calling rollAllDice.  Returned " + sum + " when sum of Dice Tops is " + testsum);
    }
    
    System.out.println("");
    
    System.out.println(errorCount + " errors reported");
  }
}