/**  * Die test class.  *  * @author Kurt Mammen, Ben Woskow  * @version Lab 3  * @version CPE102-X (replace the X with your section number)  * @version Winter 2008  */ import static org.junit.Assert.*; import org.junit.Test; public class DieTest { /** * Test method for {@link Die()}. * Here we are testing to ensure that newly-created * Die instances (empty constructor) have the default number of sides. */ @Test public void testDieEmptyConstructor() { // Construct an Die object Die die = new Die(); // Check to see if the die has the default number of sides assertEquals(die.sides(), Die.DEFAULT_NUMBER_OF_SIDES); } /** * Test method for {@link Die(int)}. * Here we are testing to ensure that newly-created * Die instances (constructor with the sides parameter) * have the expected number of sides. */ @Test public void testDieSidesConstructor() { int sides = 10; // Construct an Die object Die die = new Die(sides); // Check to see if the die has the expected number of sides assertEquals(die.sides(), sides); } /** * Test method for {@link Die(int, long)}. * Here we are testing to ensure that newly-created * Die instances (constructor with the sides and seed parameters) * have the expected number of sides and expected roll values. */ @Test public void testDieSidesSeedConstructor() { int sides = 10; long seed = 1000L; // Construct an Die object Die die = new Die(sides, seed); // Check to see if the die has the expected number of sides assertEquals(die.sides(), sides); // Check to see if the die has the expected roll values // Given a seed, Random objects will produce repeated 'random' values. assertEquals(die.roll(), 8); assertEquals(die.roll(), 6); assertEquals(die.roll(), 7); } /** * Test method for {@link Die(long)}. * Here we are testing to ensure that newly-created * Die instances (constructor with the seed parameter) * have the default number of sides and expected roll values. */ @Test public void testDieSeedConstructor() { long seed = 1000L; // Construct an Die object Die die = new Die(seed); // Check to see if the die has the default number of sides assertEquals(die.sides(), Die.DEFAULT_NUMBER_OF_SIDES); // Check to see if the die has the expected roll values // Given a seed, Random objects will produce repeated 'random' values. assertEquals(die.roll(), 2); assertEquals(die.roll(), 2); assertEquals(die.roll(), 1); } /** * Test method for {@link Die#sides()}. * Here we are testing to ensure that the sides() method works. */ @Test public void testSides() { // Construct Die object #1 Die die1 = new Die(); // Construct Die object #2 int sides = 10; Die die2 = new Die(sides); // Check to see if the dice have the expected number of sides assertEquals(die1.sides(), Die.DEFAULT_NUMBER_OF_SIDES); assertEquals(die2.sides(), sides); } /** * Test method for {@link Die#roll()} and {@link Die#value()}. * Here we are testing to ensure that the value() method returns * the most recently roll() (rolled) value. */ @Test public void testRollValue() { // Construct an Die object Die die = new Die(); // Check to see if the method returns expected values for a few executions. assertEquals(die.roll(), die.value()); assertEquals(die.roll(), die.value()); assertEquals(die.roll(), die.value()); } }