所以基本上我试图测试看看我的5张牌是否有一对(两张牌有相同的值(1-9))并且我得到一个未知的错误,这是我的代码
错误:
java.lang.AssertionError at org.junit.Assert.fail(Assert.java:86)...
代码:
public static boolean hasPair(Card[] cards) {
Deck theDeck = new Deck();
cards = theDeck.deal(5);
int k=0;
for (int atPos = 0; atPos<5; atPos++){
for (int atPos2 = atPos+1; atPos2<5; atPos2++){
if(cards[atPos].getValue() == cards[atPos2].getValue()){
k++;
}
}
}
if (k==2){
return true;
}
else {
return false;
}
失败的JUnit
@Test
public void testExampleTest_SinglePairTest() {
Card[] testHand = new Card[5];
testHand[0] = new Card(1,1);
testHand[1] = new Card(2,1);
testHand[2] = new Card(2,1);
testHand[3] = new Card(4,1);
testHand[4] = new Card(5,1);
assertTrue(HandEvaluatorBBXP.hasPair(testHand));
答案 0 :(得分:0)
似乎没有必要将Card[] cards
作为hasPair
方法的参数传递,因为您立即将变量设置为deck.deal()返回的任何值。因此,传入的值永远不会被使用。
这可能是您的测试失败的原因,因为您的测试数据是hasPair方法实际用于评估测试的内容。