我想测试下面的两种方法,但因为它基于随机输出,所以我的首选方法assertEquals()
不起作用。
我只想测试以确保这些方法产生某种输出。有任何想法吗?
新手程序员,感谢帮助。
public void compRandomChoice() {
double choice = (Math.random() * 100 / 100);
if (choice > 0 && choice <= 0.34) {
computer.setChoice(HandThrow.ROCK);
} else if (choice > 0.34 && choice <= 0.67) {
computer.setChoice(HandThrow.PAPER);
} else {
computer.setChoice(HandThrow.SCISSORS);
}
}
public String gameWinner() {
String gameResult;
if (human.getChoice() == computer.getChoice()) {
gameResult = "ITS A TIE!";
} else if (human.getChoice() == HandThrow.ROCK
&& computer.getChoice() == HandThrow.SCISSORS
|| human.getChoice() == HandThrow.PAPER
&& computer.getChoice() == HandThrow.ROCK
|| human.getChoice() == HandThrow.SCISSORS
&& computer.getChoice() == HandThrow.PAPER) {
gameResult = "CONGRATS, YOU WIN!";
} else {
gameResult = "COMPUTER WINS!";
}
return gameResult;
}