Created
September 13, 2019 13:21
-
-
Save JHarry444/1849ccf9f74e2b799b60d9913feea256 to your computer and use it in GitHub Desktop.
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 int play(int a, int b) { | |
if (a > 21 && b > 21) { | |
return -1; | |
} else if (a > 21) { | |
return b; | |
} else if (b > 21) { | |
return a; | |
} else { | |
return Math.max(a, b); | |
} | |
} | |
} |
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 testing; | |
import static org.junit.Assert.assertEquals; | |
import org.junit.Test; | |
import main.BlackJack; | |
public class BlacklJackTest { | |
BlackJack blckJck = new BlackJack(); | |
@Test | |
public void testP1Wins() { | |
assertEquals(20, this.blckJck.play(20, 16)); | |
} | |
@Test | |
public void testP2Wins() { | |
assertEquals(20, this.blckJck.play(16, 20)); | |
} | |
@Test | |
public void testOneBust() { | |
assertEquals(2, this.blckJck.play(2, 24)); | |
} | |
@Test | |
public void testBothBust() { | |
assertEquals(-1, this.blckJck.play(25, 36)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment