Write Junit Test for the following class below:
public class Turn
{
private int turnScore;
private Dice dice;
private boolean isSkunk;
private boolean isDoubleSkunk;
public Turn()
{
dice = new Dice();
}
public Turn(Dice dice) {
this.dice = dice;
}
public void turnRoll()
{
dice.roll();
if (dice.getDie1Value() == 1 ||
dice.getDie2Value() == 1 && dice.getLastRoll() != 2)
{
turnScore =
0;
isSkunk =
true;
}
else if (dice.getLastRoll() ==
2)
{
turnScore =
0;
isDoubleSkunk =
true;
}
else
{
turnScore +=
getDiceValue();
isSkunk =
false;
}
}
public void programmedTurnRoll()
{
dice.roll();
if (dice.getDie1Value() == 1 ||
dice.getDie2Value() == 1 && dice.getLastRoll() != 2)
{
turnScore =
0;
isSkunk =
true;
}
else if (dice.getLastRoll() ==
2)
{
turnScore =
0;
isSkunk =
true;
}
else
{
turnScore +=
dice.getLastRoll();
isSkunk =
false;
}
}
public int getTurnScore()
{
return this.turnScore;
}
public boolean isSkunk()
{
return isSkunk;
}
public boolean isDoubleSkunk() {
return isDoubleSkunk;
}
public int getDie1Value()
{
return dice.getDie1Value();
}
public int getDie2Value()
{
return dice.getDie2Value();
}
public int getDiceValue()
{
return getDie1Value() +
getDie2Value();
}
}
Please let me know if you have any doubts or you want me to modify
the answer. And if you find this answer useful then don't forget to
rate my answer as thumps up. Thank you! :)
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
public class TurnTest
{
private Dice dice, dice2;
private Die die1, die2, die3, die4;
private int[] rollDie1, rollDie2, rollDie3,
rollDie4;
private int turnScore;
@Before
public void setUp() throws Exception
{
this.rollDie1 = new
int[] { 1, 2, 3 };
this.die1 = new
Die(rollDie1);
this.rollDie2 = new
int[] { 1, 2, 3 };
this.die2 = new
Die(rollDie2);
this.dice = new
Dice(die1, die2);
this.rollDie3 = new
int[] { 3, 4, 5 };
this.die3 = new
Die(rollDie3);
this.rollDie4 = new
int[] { 4, 5, 6 };
this.die4 = new
Die(rollDie4);
this.dice2 = new
Dice(die3, die4);
}
@Test
public void testIsSkunk() {
Turn turn = new
Turn(dice);
turn.turnRoll();
boolean testBol =
turn.isSkunk();
//assertTrue(testBol);
}
@Test
public void testTurnScore() {
Turn turn2 = new
Turn(dice2);
turn2.turnRoll();
int expectedTurnScore =
7;
int actualTurnScore =
turn2.getTurnScore();
//assertEquals(expectedTurnScore,actualTurnScore);
}
private void extracted(int expectedTurnScore,
int actualTurnScore) {
assertEquals(expectedTurnScore,actualTurnScore);
}
@Test
public void testTurnScoreAfterSkunk() {
Turn turn = new
Turn(dice);
turn.turnRoll();
int expectedTurnScore =
0;
int actualTurnScore =
turn.getTurnScore();
extracted(expectedTurnScore, actualTurnScore);
}
public int getTurnScore() {
return turnScore;
}
public void setTurnScore(int turnScore)
{
this.turnScore =
turnScore;
}
}
----------------------------------------------------------------------------------------------------------------------------------------------
public class Turn
{
private int turnScore;
private Dice dice;
private boolean isSkunk;
private boolean isDoubleSkunk;
public Turn()
{
dice = new Dice();
}
public Turn(Dice dice) {
this.dice = dice;
}
public void turnRoll()
{
dice.roll();
if (dice.getDie1() ==
1 || dice.getDie2() == 1 && dice.getLastRoll() != 2)
{
turnScore = 0;
isSkunk = true;
}
else if
(dice.getLastRoll() == 2)
{
turnScore = 0;
isDoubleSkunk = true;
// totalScore = 0;
}
else
{
turnScore += getDiceValue();
isSkunk = false;
}
}
public void programmedTurnRoll()
{
dice.roll();
if (dice.getDie1() ==
1 || dice.getDie2() == 1 && dice.getLastRoll() != 2)
{
turnScore = 0;
isSkunk = true;
}
else if
(dice.getLastRoll() == 2)
{
turnScore = 0;
isSkunk = true;
// totalScore = 0;
}
else
{
turnScore += dice.getLastRoll();
isSkunk = false;
}
}
public int getTurnScore()
{
return
this.turnScore;
}
public boolean isSkunk()
{
return isSkunk;
}
public boolean isDoubleSkunk() {
return
isDoubleSkunk;
}
public int getDie1Value()
{
return
dice.getDie1();
}
public int getDie2Value()
{
return
dice.getDie2();
}
public int getDiceValue()
{
return getDie1Value() +
getDie2Value();
}
}
Write Junit Test for the following class below: public class Turn { private int turnScore; private Dice dice; private boolean isSkunk; private boolean isDoubleSkunk; public Turn() {...
Write Junit test for the following class below: public class Player { public int turnScore; public int roundScore; public int lastTurnScore; public String name; public int chipPile; public Player (String name) { this.name = name; this.turnScore = 0; this.chipPile = 50; } public int getChip() { return chipPile; } public void addChip(int chips) { chipPile...
Write Junit test for the following class below: public class Player { public int turnScore; public int roundScore; public int lastTurnScore; public String name; public int chipPile; public Player (String name) { this.name = name; this.turnScore = 0; this.chipPile = 50; } public int getChip() { return chipPile; } public void addChip(int chips) { chipPile += chips; } public int getRoundScore() { return roundScore; } public void setRoundScore(int points) { roundScore += points; } public int getTurnScore() { return turnScore; ...
Create Junit tests for the following classes public class Dice { private Die die1; private Die die2; public Dice() { this.die1 = new Die(); this.die2 = new Die(); } public Dice(int[] programmedRolls) { int[] programmableroll = programmedRolls; this.die1 = new Die(programmableroll); this.die1 = new Die(programmableroll); } public Dice(Die die1, Die die2) { this.die1 = die1; this.die2 = die2; } public void roll() { die1.roll(); die2.roll(); } public int getDie1Value() { return die1.getLastRoll(); } public int getDie2Value() { return die2.getLastRoll(); } ...
Consider the Automobile class: public class Automobile { private String model; private int rating; // a number 1, 2, 3, 4, 5 private boolean isTruck; public Automobile(String model, boolean isTruck) { this.model = model; this.rating = 0; // unrated this.isTruck = isTruck; } public Automobile(String model, int rating, boolean isTruck) { this.model = model; this.rating = rating; this.isTruck = isTruck; } public String getModel()...
Write JunitTest for the class below: public class Dice { private Die die1; private Die die2; public Dice(int[] programmedRolls) { int[] programmableroll = programmedRolls; this.die1 = new Die(programmableroll); this.die1 = new Die(programmableroll); } }
Assignment (to be done in Java): Person Class: public class Person extends Passenger{ private int numOffspring; public Person() { this.numOffspring = 0; } public Person (int numOffspring) { this.numOffspring = numOffspring; } public Person(String name, int birthYear, double weight, double height, char gender, int numCarryOn, int numOffspring) { super(name, birthYear, weight, height, gender, numCarryOn); if(numOffspring < 0) { this.numOffspring = 0; } this.numOffspring = numOffspring; } public int getNumOffspring() { ...
This is my code for a TicTacToe game. However, I don't know how to write JUnit tests. Please help me with my JUnit Tests. I will post below what I have so far. package cs145TicTacToe; import java.util.Scanner; /** * A multiplayer Tic Tac Toe game */ public class TicTacToe { private char currentPlayer; private char[][] board; private char winner; /** * Default constructor * Initializes the board to be 3 by 3 and...
public class Date { private int month; private int day; private int year; /** default constructor * sets month to 1, day to 1 and year to 2000 */ public Date( ) { setDate( 1, 1, 2000 ); } /** overloaded constructor * @param mm initial value for month * @param dd initial value for day * @param yyyy initial value for year * * passes parameters to setDate method */ public Date( int mm, int dd, int yyyy )...
Write one JUnit test in Java for the following: Essay class: import java.util.Scanner; public class Essay implements IAnswer{ private String question; public Essay(String q){ this.question = q; } //This function returns question text public String getQuestionText() { return question; } //This function takes answer from user public void answer(String userAnswer) { // Take care of answer } @Override public String getAnswer() { System.out.println(question); Scanner scan = new Scanner(System.in); System.out.print("Answer: "); String ans =scan.nextLine(); scan.close(); if(ans.length() <=140){ return ans; }else{ return...
public class Buildbst { private int data; private Buildbst left; private Buildbst right; //Set the binary search tree public Buildbst(int data) { this.data = data; this.left = null; this.right =null; } public int getData() { return data; } public void setData(int data) { this.data = data; } public Buildbst getLeft() { return left; } public void setLeft(Buildbst left) { this.left = left; } public Buildbst getRight() { return right; } public void setRight(Buildbst right) { this.right = right; } }...