Skip to content

Instantly share code, notes, and snippets.

@JHarry444
Created September 13, 2019 13:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JHarry444/1849ccf9f74e2b799b60d9913feea256 to your computer and use it in GitHub Desktop.
Save JHarry444/1849ccf9f74e2b799b60d9913feea256 to your computer and use it in GitHub Desktop.
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);
}
}
}
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