Question

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 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();
   }

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1


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();
    }

}
|삐 DiceTest [~/ldeaProjects/DiceTest] -../src/TurnTest.java [DiceTest] Project import static org.junit.Assert.assertEquals im

Add a comment
Know the answer?
Add Answer to:
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()    {...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT