lots of exercises in java... from https://github.com/exercism/java

PokerTest.java 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. import static org.junit.Assert.assertEquals;
  2. import java.util.Arrays;
  3. import org.junit.Test;
  4. import org.junit.Ignore;
  5. public class PokerTest {
  6. @Test
  7. public void oneHand() {
  8. final String hand = "4S 5S 7H 8D JC";
  9. assertEquals(Arrays.asList(hand),new Poker(Arrays.asList(hand)).getBestHands());
  10. }
  11. @Ignore("Remove to run test")
  12. @Test
  13. public void nothingVsOnePair() {
  14. final String nothing = "4S 5H 6S 8D JH";
  15. final String pairOf4 = "2S 4H 6S 4D JH";
  16. assertEquals(Arrays.asList(pairOf4),new Poker(Arrays.asList(nothing, pairOf4)).getBestHands());
  17. }
  18. @Ignore("Remove to run test")
  19. @Test
  20. public void twoPairs() {
  21. final String pairOf2 = "4S 2H 6S 2D JH";
  22. final String pairOf4 = "2S 4H 6S 4D JH";
  23. assertEquals(Arrays.asList(pairOf4), new Poker(Arrays.asList(pairOf2,pairOf4)).getBestHands());
  24. }
  25. @Ignore("Remove to run test")
  26. @Test
  27. public void onePairVsDoublePair() {
  28. final String pairOf8 = "2S 8H 6S 8D JH";
  29. final String doublePair = "4S 5H 4S 8D 5H";
  30. assertEquals(Arrays.asList(doublePair), new Poker(Arrays.asList(pairOf8, doublePair)).getBestHands());
  31. }
  32. @Ignore("Remove to run test")
  33. @Test
  34. public void twoDoublePairs() {
  35. final String doublePair2And8 = "2S 8H 2S 8D JH";
  36. final String doublePair4And5 = "4S 5H 4S 8D 5H";
  37. assertEquals(Arrays.asList(doublePair2And8), new Poker(Arrays.asList(doublePair2And8, doublePair4And5)).getBestHands());
  38. }
  39. @Ignore("Remove to run test")
  40. @Test
  41. public void doublePairVsThree() {
  42. final String doublePair2And8 = "2S 8H 2S 8D JH";
  43. final String threeOf4 = "4S 5H 4S 8D 4H";
  44. assertEquals(Arrays.asList(threeOf4 ), new Poker(Arrays.asList(doublePair2And8, threeOf4)).getBestHands());
  45. }
  46. @Ignore("Remove to run test")
  47. @Test
  48. public void twoThrees() {
  49. final String threeOf2 = "2S 2H 2S 8D JH";
  50. final String threeOf1 = "4S AH AS 8D AH";
  51. assertEquals(Arrays.asList(threeOf1), new Poker(Arrays.asList(threeOf2, threeOf1)).getBestHands());
  52. }
  53. @Ignore("Remove to run test")
  54. @Test
  55. public void threeVsStraight() {
  56. final String threeOf4 = "4S 5H 4S 8D 4H";
  57. final String straight = "3S 4H 2S 6D 5H";
  58. assertEquals(Arrays.asList(straight), new Poker(Arrays.asList(threeOf4, straight)).getBestHands());
  59. }
  60. @Ignore("Remove to run test")
  61. @Test
  62. public void twoStraights() {
  63. final String straightTo8 = "4S 6H 7S 8D 5H";
  64. final String straightTo9 = "5S 7H 8S 9D 6H";
  65. assertEquals(Arrays.asList(straightTo9 ), new Poker(Arrays.asList(straightTo8, straightTo9)).getBestHands());
  66. final String straightTo1 = "AS QH KS TD JH";
  67. final String straightTo5 = "4S AH 3S 2D 5H";
  68. assertEquals(Arrays.asList(straightTo1), new Poker(Arrays.asList(straightTo1, straightTo5)).getBestHands());
  69. }
  70. @Ignore("Remove to run test")
  71. @Test
  72. public void straightVsFlush() {
  73. final String straightTo8 = "4S 6H 7S 8D 5H";
  74. final String flushTo7 = "2S 4S 5S 6S 7S";
  75. assertEquals(Arrays.asList(flushTo7 ), new Poker(Arrays.asList(straightTo8, flushTo7)).getBestHands());
  76. }
  77. @Ignore("Remove to run test")
  78. @Test
  79. public void twoFlushes() {
  80. final String flushTo8 = "3H 6H 7H 8H 5H";
  81. final String flushTo7 = "2S 4S 5S 6S 7S";
  82. assertEquals(Arrays.asList(flushTo8), new Poker(Arrays.asList(flushTo8, flushTo7)).getBestHands());
  83. }
  84. @Ignore("Remove to run test")
  85. @Test
  86. public void flushVsFull() {
  87. final String flushTo8 = "3H 6H 7H 8H 5H";
  88. final String full = "4S 5H 4S 5D 4H";
  89. assertEquals(Arrays.asList(full ), new Poker(Arrays.asList(full, flushTo8)).getBestHands());
  90. }
  91. @Ignore("Remove to run test")
  92. @Test
  93. public void twoFulls() {
  94. final String fullOf4By9 = "4H 4S 4D 9S 9D";
  95. final String fullOf5By8 = "5H 5S 5D 8S 8D";
  96. assertEquals(Arrays.asList(fullOf5By8 ), new Poker(Arrays.asList(fullOf4By9, fullOf5By8)).getBestHands());
  97. }
  98. @Ignore("Remove to run test")
  99. @Test
  100. public void fullVsSquare() {
  101. final String full = "4S 5H 4S 5D 4H";
  102. final String squareOf3 = "3S 3H 2S 3D 3H";
  103. assertEquals(Arrays.asList(squareOf3 ), new Poker(Arrays.asList(full, squareOf3)).getBestHands());
  104. }
  105. @Ignore("Remove to run test")
  106. @Test
  107. public void twoSquares() {
  108. final String squareOf2 = "2S 2H 2S 8D 2H";
  109. final String squareOf5 = "4S 5H 5S 5D 5H";
  110. assertEquals(Arrays.asList(squareOf5), new Poker(Arrays.asList(squareOf2, squareOf5)).getBestHands());
  111. }
  112. @Ignore("Remove to run test")
  113. @Test
  114. public void squareVsStraightFlush() {
  115. final String squareOf5 = "4S 5H 5S 5D 5H";
  116. final String straightFlushTo9 = "5S 7S 8S 9S 6S";
  117. assertEquals(Arrays.asList(straightFlushTo9 ), new Poker(Arrays.asList(squareOf5, straightFlushTo9)).getBestHands());
  118. }
  119. @Ignore("Remove to run test")
  120. @Test
  121. public void twoStraightFlushes() {
  122. final String straightFlushTo8 = "4H 6H 7H 8H 5H";
  123. final String straightFlushTo9 = "5S 7S 8S 9S 6S";
  124. assertEquals(Arrays.asList(straightFlushTo9 ), new Poker(Arrays.asList(straightFlushTo8, straightFlushTo9)).getBestHands());
  125. }
  126. @Ignore("Remove to run test")
  127. @Test
  128. public void threeHandWithTie() {
  129. final String spadeStraightTo9 = "9S 8S 7S 6S 5S";
  130. final String diamondStraightTo9 = "9D 8D 7D 6D 5D";
  131. final String threeOf4 = "4D 4S 4H QS KS";
  132. assertEquals(Arrays.asList(spadeStraightTo9, diamondStraightTo9), new Poker(Arrays.asList(spadeStraightTo9, diamondStraightTo9, threeOf4)).getBestHands());
  133. }
  134. @Ignore("Remove to run test")
  135. @Test
  136. public void straightTo5AgainstAPairOfJacks() {
  137. final String straightTo5 = "2S 4D 5C 3S AS";
  138. final String twoJacks = "JD 8D 7D JC 5D";
  139. assertEquals(Arrays.asList(straightTo5), new Poker(Arrays.asList(straightTo5, twoJacks)).getBestHands());
  140. }
  141. }