2021-02-18 09:36:12 -05:00
|
|
|
import static org.junit.Assert.*;
|
|
|
|
import org.junit.*;
|
|
|
|
|
|
|
|
/*******************************************
|
|
|
|
* The test class for Chuck
|
|
|
|
*
|
|
|
|
* @author Resendiz
|
|
|
|
* @version February 2021
|
|
|
|
******************************************/
|
|
|
|
|
|
|
|
public class MyDiceGameTest {
|
|
|
|
|
|
|
|
/******************************************************
|
|
|
|
* Test initial values of the constructor
|
|
|
|
*****************************************************/
|
|
|
|
@Test
|
|
|
|
public void testConstructor() {
|
|
|
|
GameManager game = new GameManager(6);
|
|
|
|
int credits = game.getDice().getCredits();
|
|
|
|
|
|
|
|
// confirm there is only one copy of Title 1
|
|
|
|
Assert.assertEquals("Game should start with 10 credits",
|
|
|
|
credits, 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************
|
|
|
|
* Test Large
|
|
|
|
*****************************************************/
|
|
|
|
@Test
|
|
|
|
public void testLarge() {
|
|
|
|
// confirm large is rolled
|
|
|
|
GameManager game = new GameManager(6);
|
|
|
|
int credits = game.getDice().getCredits();
|
2021-02-18 20:42:54 -05:00
|
|
|
game.getDice().testRoll(new int[]{6, 4, 5});
|
2021-02-18 09:36:12 -05:00
|
|
|
game.getDice().checkLarge();
|
2021-02-18 20:42:54 -05:00
|
|
|
Assert.assertEquals("Dice => (6,4,5): credits should stay the same",
|
2021-02-18 09:36:12 -05:00
|
|
|
game.getDice().getCredits(), credits);
|
|
|
|
|
|
|
|
// confirm large is not rolled
|
|
|
|
GameManager game2 = new GameManager(6);
|
|
|
|
credits = game2.getDice().getCredits();
|
|
|
|
game2.getDice().testRoll(new int[]{1, 2, 3});
|
|
|
|
game2.getDice().checkLarge();
|
|
|
|
Assert.assertEquals("Dice => (1,2,3): credits should decrease by one",
|
|
|
|
game2.getDice().getCredits(), credits - 1);
|
|
|
|
|
2021-02-18 20:42:54 -05:00
|
|
|
|
2021-02-18 09:36:12 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************
|
2021-02-18 20:42:54 -05:00
|
|
|
* Test Doubles
|
2021-02-18 09:36:12 -05:00
|
|
|
*****************************************************/
|
|
|
|
@Test
|
2021-02-18 20:42:54 -05:00
|
|
|
public void testDoubles() {
|
|
|
|
// confirm doubles is rolled. 1st Combo
|
2021-02-18 09:36:12 -05:00
|
|
|
GameManager game = new GameManager(6);
|
|
|
|
int credits = game.getDice().getCredits();
|
2021-02-18 20:42:54 -05:00
|
|
|
game.getDice().testRoll(new int[]{1, 1, 2});
|
|
|
|
game.getDice().checkDoubles();
|
|
|
|
Assert.assertEquals("Dice => (1,1,2): credits should stay the same",
|
2021-02-18 09:36:12 -05:00
|
|
|
game.getDice().getCredits(), credits);
|
|
|
|
|
2021-02-18 20:42:54 -05:00
|
|
|
// confirm doubles is rolled. 2nd Combo
|
|
|
|
GameManager game2 = new GameManager(6);
|
|
|
|
int credits2 = game2.getDice().getCredits();
|
|
|
|
game2.getDice().testRoll(new int[]{2, 1, 1});
|
|
|
|
game2.getDice().checkDoubles();
|
|
|
|
Assert.assertEquals("Dice => (1,1,1): credits should stay the same",
|
|
|
|
game2.getDice().getCredits(), credits2);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************
|
|
|
|
* Test Combination of Points Awarded
|
|
|
|
*****************************************************/
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testCombinations(){
|
|
|
|
// confirm large and double are called
|
|
|
|
GameManager game = new GameManager(6);
|
|
|
|
int credits = game.getDice().getCredits();
|
|
|
|
game.getDice().testRoll(new int[]{6, 6, 3});
|
|
|
|
game.getDice().checkDoubles();
|
|
|
|
game.getDice().checkLarge();
|
|
|
|
Assert.assertEquals("Dice => (6,6,3): credits should increase by one",
|
|
|
|
game.getDice().getCredits(), credits + 1);
|
|
|
|
|
|
|
|
// confirm large, triplets and doubles are given points
|
|
|
|
GameManager game3 = new GameManager(6);
|
|
|
|
credits = game3.getDice().getCredits();
|
|
|
|
game3.getDice().testRoll(new int[]{4, 4, 4});
|
|
|
|
game3.getDice().checkLarge();
|
|
|
|
game3.getDice().checkTriplets();
|
|
|
|
game3.getDice().checkDoubles();
|
|
|
|
Assert.assertEquals("Dice => (4,4,4): credits should increased by two",
|
|
|
|
game3.getDice().getCredits(), credits + 2);
|
|
|
|
|
|
|
|
// confirm triplets and doubles are called but not large
|
|
|
|
GameManager game4 = new GameManager(6);
|
|
|
|
credits = game4.getDice().getCredits();
|
|
|
|
game4.getDice().testRoll(new int[]{3, 3, 3});
|
|
|
|
game4.getDice().checkLarge();
|
|
|
|
game4.getDice().checkTriplets();
|
|
|
|
game4.getDice().checkDoubles();
|
|
|
|
Assert.assertEquals("Dice => (3,3,3): credits should increase by one",
|
|
|
|
game4.getDice().getCredits(), credits+1);
|
|
|
|
|
|
|
|
|
2021-02-18 09:36:12 -05:00
|
|
|
}
|
|
|
|
}
|