Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.46 KB | None | 0 0
  1. (ns user (:use clojure.test))
  2.  
  3. (def high-seven ["2H" "3S" "4C" "5C" "7D"])
  4. (def pair-hand ["2H" "2S" "4C" "5C" "7D"])
  5. (def two-pairs-hand ["2H" "2S" "4C" "4D" "7D"])
  6. (def three-of-a-kind-hand ["2H" "2S" "2C" "4D" "7D"])
  7. (def four-of-a-kind-hand ["2H" "2S" "2C" "2D" "7D"])
  8. (def straight-hand ["2H" "3S" "6C" "5D" "4D"])
  9. (def low-ace-straight-hand ["2H" "3S" "4C" "5D" "AD"])
  10. (def high-ace-straight-hand ["TH" "AS" "QC" "KD" "JD"])
  11. (def flush-hand ["2H" "4H" "5H" "9H" "7H"])
  12. (def full-house-hand ["2H" "5D" "2D" "2C" "5S"])
  13. (def straight-flush-hand ["2H" "3H" "6H" "5H" "4H"])
  14. (def low-ace-straight-flush-hand ["2D" "3D" "4D" "5D" "AD"])
  15. (def high-ace-straight-flush-hand ["TS" "AS" "QS" "KS" "JS"])
  16.  
  17. (deftest test-suit
  18. (is (= "H" (suit "JH")))
  19. (is (= "C" (suit "4C")))
  20. (is (= "D" (suit "KD")))
  21. (is (= "S" (suit "AS")))
  22. (is (= nil (suit "5N"))))
  23.  
  24. (deftest test-ranks
  25. (is (= 2 (rank "2C")))
  26. (is (= 3 (rank "3S")))
  27. (is (= 4 (rank "4H")))
  28. (is (= 5 (rank "5D")))
  29. (is (= 6 (rank "6S")))
  30. (is (= 7 (rank "7C")))
  31. (is (= 8 (rank "8H")))
  32. (is (= 9 (rank "9S")))
  33. (is (= 10 (rank "TH")))
  34. (is (= 11 (rank "JC")))
  35. (is (= 12 (rank "QD")))
  36. (is (= 13 (rank "KH")))
  37. (is (= 14 (rank "AH")))
  38. (is (= nil (rank nil))))
  39.  
  40. (deftest test-pair?
  41. (is (= true (pair? pair-hand)))
  42. (is (= false (pair? two-pairs-hand)))
  43. (is (= false (pair? three-of-a-kind-hand))))
  44.  
  45. (deftest test three-of-a-kind?
  46. (is (= true (three-of-a-kind? three-of-a-kind-hand)))
  47. (is (= false (three-of-a-kind? four-of-a-kind-hand)))
  48. (is (= false (three-of-a-kind? full-house-hand))))
  49.  
  50. (deftest test-four-of-a-kind?
  51. (is (= true (four-of-a-kind? four-of-a-kind-hand)))
  52. (is (= false (four-of-a-kind? full-house-hand))))
  53.  
  54. (deftest test-flush?
  55. (is (= true (flush? flush-hand)))
  56. (is (= true (flush? straight-flush-hand)))
  57. (is (= false (flush? high-seven))))
  58.  
  59. (deftest test-full-house?
  60. (is (= true (full-house? full-house-hand)))
  61. (is (= false (full-house? three-of-a-kind-hand))))
  62.  
  63. (deftest test-two-pairs?
  64. (is (= true (two-pairs? two-pairs-hand)))
  65. (is (= false (two-pairs? full-house-hand))))
  66.  
  67. (deftest test-straight?
  68. (is (= true (straight? straight-hand)))
  69. (is (= false (straight? high-seven)))
  70. (is (= true (straight? straight-flush-hand)))
  71. (is (= true (straight? high-ace-straight-flush-hand)))
  72. (is (= true (straight? low-ace-straight-flush-hand)))
  73. (is (= true (straight? high-ace-straight-hand)))
  74. (is (= true (straight? low-ace-straight-hand))))
  75.  
  76. (deftest test-straight-flush?
  77. (is (= true (straight-flush? straight-flush-hand)))
  78. (is (= true (straight-flush? high-ace-straight-flush-hand)))
  79. (is (= true (straight-flush? low-ace-straight-flush-hand)))
  80. (is (= false (straight-flush? flush-hand)))
  81. (is (= false (straight-flush? straight-hand))))
  82.  
  83. (deftest test-value
  84. (is (= 0 (value high-seven)))
  85. (is (= 1 (value pair-hand)))
  86. (is (= 2 (value two-pairs-hand)))
  87. (is (= 3 (value three-of-a-kind-hand)))
  88. (is (= 4 (value straight-hand)))
  89. (is (= 5 (value flush-hand)))
  90. (is (= 6 (value full-house-hand)))
  91. (is (= 7 (value four-of-a-kind-hand)))
  92. (is (= 8 (value straight-flush-hand))))
  93.  
  94. (deftest test-kickers
  95. (is (= '(7 5 4 3 2) (kickers high-seven)))
  96. (is (= '(14 13 12 11 10) (kickers high-ace-straight-flush-hand)))
  97. (is (= '(6 5 4 3 2) (kickers straight-hand)))
  98. (is (= '(2 7 5 4) (kickers pair-hand)))
  99. (is (= '(4 2 7) (kickers two-pairs-hand)))
  100. (is (= '(2 7 4) (kickers three-of-a-kind-hand)))
  101. (is (= '(9 7 5 4 2) (kickers flush-hand)))
  102. (is (= '(2 5) (kickers full-house-hand)))
  103. (is (= '(2 7) (kickers four-of-a-kind-hand)))
  104. (is (= '(5 4 3 2 1) (kickers low-ace-straight-flush-hand))))
  105.  
  106. (deftest test-higher-kicker?
  107. (is (= true (higher-kicker? (kickers high-ace-straight-hand) (kickers low-ace-straight-hand))))
  108. (is (= false (higher-kicker? '(7 6 4 3 2)'(7 6 4 3 2))))
  109. (is (= false (higher-kicker? (kickers straight-hand) (kickers flush-hand)))))
  110.  
  111. (deftest test-beats?
  112. (is (= nil (beats? flush-hand flush-hand)))
  113. (is (= true (beats? four-of-a-kind-hand three-of-a-kind-hand)))
  114. (is (= true (beats? high-ace-straight-hand low-ace-straight-hand)))
  115. (is (= nil (beats? high-seven straight-hand)))
  116. (is (= true (beats? straight-flush-hand full-house-hand))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement