-4
我有這個類的測試用例,我必須填寫所有的方法。我收到了一些最後只返回已經創建的東西。但我不知道如何去做其他的方法。有小費嗎?我們正在製作一個Yahtzee遊戲。不知道如何用測試用例編程這個類
這裏是一流的,我必須在方法
import java.util.Vector;
import model.Player;
public class YahtzeeEngine {
public static final int MAX_ROLLS = 0;
private Vector<Player> myPlayers;
private Roller myRoller;
private Player myPlayerUp;
private int myNumberRollsUsed;
public Vector myPlayer;
public YahtzeeEngine(int numPlayers) {
}
public void startGame() {
}
public void selectPlayerUp(Player player) {
}
public void switchPlayerUp() {
}
public boolean incrementRollsUsed() {
return false;
}
public void resetNumberRollsUsed() {
myNumberRollsUsed = 0;
}
public Roller getRoller() {
return myRoller;
}
public Player getPlayerUp() {
return myPlayerUp;
}
public Vector<Player> getPlayers() {
return myPlayers;
}
public int getNumberRollsUsed() {
return myNumberRollsUsed;
}
public String toString() {
return null;
}
}
這裏填寫爲它
package yahtzee.testing;
import static org.junit.Assert.*;
import yahtzee.model.Player;
import yahtzee.model.Roller;
import yahtzee.model.YahtzeeEngine;
import org.junit.Assert;
import org.junit.Test;
/**
* This class is built to test the methods within the YahtzeeEngine class.
* Each test case should pass if the code is properly implemented.
*/
public class TestYahtzeeEngine {
/**
* Tests that the Category keeps track of the proper
* amount of rolls that have been used.
*/
@Test
public void testIncrement() {
YahtzeeEngine ye = new YahtzeeEngine(2);
for (int i = 0; i < 3; i++) {
ye.incrementRollsUsed();
}
assertTrue(ye.getNumberRollsUsed() == 3);
}
/**
* Tests if the number of rolls is reset to zero when resetRolls() has been called.
*/
@Test
public void testResetRolls() {
YahtzeeEngine ye = new YahtzeeEngine(1);
for (int i = 0; i < 3; i++) {
ye.incrementRollsUsed();
}
ye.resetNumberRollsUsed();
assertTrue(ye.getNumberRollsUsed() == 0);
}
/**
* Tests if the current player up will rotate properly
* when the switchPlayerUp() method is invoked.
*/
@Test
public void testPlayerUp() {
YahtzeeEngine ye = new YahtzeeEngine(2);
Player player1 = ye.getPlayers().get(0);
ye.selectPlayerUp(player1);
ye.switchPlayerUp();
assertFalse(ye.getPlayerUp().equals(player1));
}
/**
* Tests if the player vector is the correct length for min number of players.
*/
@Test
public void testMinPlayerVector() {
YahtzeeEngine ye = new YahtzeeEngine(1);
assertTrue(ye.getPlayers().size() == 1);
}
/**
* Tests if the player vector is the correct length for max number of players.
*/
@Test
public void testMaxPlayerVector() {
YahtzeeEngine ye = new YahtzeeEngine(6);
assertTrue(ye.getPlayers().size() == 6);
}
/**
* Test that bad number of players passed in defaults to 2 players.
*/
@Test
public void testTooFewPlayerVector1() {
YahtzeeEngine ye = new YahtzeeEngine(0);
assertTrue(ye.getPlayers().size() == 2);
}
@Test
public void testTooFewPlayerVector2() {
YahtzeeEngine ye = new YahtzeeEngine(7);
assertTrue(ye.getPlayers().size() == 2);
}
/**
* Tests that the game is properly instantiated after startGame() has been called.
*/
@Test
public void testStartOfGame() {
YahtzeeEngine ye = new YahtzeeEngine(2);
ye.startGame();
assertTrue(ye.getNumberRollsUsed() == 0);
assertTrue(ye.getPlayerUp() != null);
assertTrue(ye.getPlayers().get(0) != null);
assertTrue(ye.getPlayers().get(1) != null);
assertTrue(ye.getRoller() != null);
}
/**
* Testing values from YahtzeeEngine on default construction.
*/
@Test
public void testYahtzeeEngineConstructor() {
YahtzeeEngine ye = new YahtzeeEngine(1);
assertTrue(ye.getNumberRollsUsed() == 0);
assertTrue(ye.getPlayerUp() == null);
assertTrue(ye.getRoller() == null);
assertTrue(ye.getPlayers().size() == 1);
}
}
你有試過什麼嗎?你有什麼具體的問題:) –
你基本上要求我們提供所有要實現的功能的提示。在你的問題中更具體一些,你會增加獲得有意義答案的機會! – Calpis
那麼我已經完成了toString()之上的5,他們只是返回一些東西。但是我不確定如何對這些方法進行編程,根據測試用例的具體情況不確定如何實現。例如,在公共布爾方法中,我怎麼知道該怎麼做? – user2909132