Skip to content

Instantly share code, notes, and snippets.

@JHarry444
Last active May 16, 2019 08:51
Show Gist options
  • Save JHarry444/5be160124bbd6fd1f1979a36b398bd03 to your computer and use it in GitHub Desktop.
Save JHarry444/5be160124bbd6fd1f1979a36b398bd03 to your computer and use it in GitHub Desktop.
TDD example
package main;
public class Blackjack {
public static int play(int hand1, int hand2) {
if (hand1 > 21 && hand2 > 21) {
return 0;
} else if (hand1 > 21) {
return hand2;
} else if (hand2 > 21) {
return hand1;
}
return Math.max(hand1, hand2);
}
}
public class BlackJackTest {
private BlackJack blackJack;
@Before
public void init() {
this.blackJack = new BlackJack();
}
@Test
public void testHighestWins() {
assertEquals("Highest number has not won.", 20, this.blackJack.findWinningHand(20, 0));
}
@Test
public void testOneBust() {
assertEquals("Player one has gone bust and still won", 15, this.blackJack.findWinningHand(25, 15));
}
@Test
public void testTwoBust() {
assertEquals("Player two has gone bust and still won", 15, this.blackJack.findWinningHand(15, 25));
}
@Test
public void testBothBust() {
assertEquals("Both players have gonw bust but one of them still won", 0, this.blackJack.findWinningHand(25, 25));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment