Last active
May 16, 2019 08:51
-
-
Save JHarry444/5be160124bbd6fd1f1979a36b398bd03 to your computer and use it in GitHub Desktop.
TDD example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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