Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (ns user (:use clojure.test))
- (def high-seven ["2H" "3S" "4C" "5C" "7D"])
- (def pair-hand ["2H" "2S" "4C" "5C" "7D"])
- (def two-pairs-hand ["2H" "2S" "4C" "4D" "7D"])
- (def three-of-a-kind-hand ["2H" "2S" "2C" "4D" "7D"])
- (def four-of-a-kind-hand ["2H" "2S" "2C" "2D" "7D"])
- (def straight-hand ["2H" "3S" "6C" "5D" "4D"])
- (def low-ace-straight-hand ["2H" "3S" "4C" "5D" "AD"])
- (def high-ace-straight-hand ["TH" "AS" "QC" "KD" "JD"])
- (def flush-hand ["2H" "4H" "5H" "9H" "7H"])
- (def full-house-hand ["2H" "5D" "2D" "2C" "5S"])
- (def straight-flush-hand ["2H" "3H" "6H" "5H" "4H"])
- (def low-ace-straight-flush-hand ["2D" "3D" "4D" "5D" "AD"])
- (def high-ace-straight-flush-hand ["TS" "AS" "QS" "KS" "JS"])
- (deftest test-suit
- (is (= "H" (suit "JH")))
- (is (= "C" (suit "4C")))
- (is (= "D" (suit "KD")))
- (is (= "S" (suit "AS")))
- (is (= nil (suit "5N"))))
- (deftest test-ranks
- (is (= 2 (rank "2C")))
- (is (= 3 (rank "3S")))
- (is (= 4 (rank "4H")))
- (is (= 5 (rank "5D")))
- (is (= 6 (rank "6S")))
- (is (= 7 (rank "7C")))
- (is (= 8 (rank "8H")))
- (is (= 9 (rank "9S")))
- (is (= 10 (rank "TH")))
- (is (= 11 (rank "JC")))
- (is (= 12 (rank "QD")))
- (is (= 13 (rank "KH")))
- (is (= 14 (rank "AH")))
- (is (= nil (rank nil))))
- (deftest test-pair?
- (is (= true (pair? pair-hand)))
- (is (= false (pair? two-pairs-hand)))
- (is (= false (pair? three-of-a-kind-hand))))
- (deftest test three-of-a-kind?
- (is (= true (three-of-a-kind? three-of-a-kind-hand)))
- (is (= false (three-of-a-kind? four-of-a-kind-hand)))
- (is (= false (three-of-a-kind? full-house-hand))))
- (deftest test-four-of-a-kind?
- (is (= true (four-of-a-kind? four-of-a-kind-hand)))
- (is (= false (four-of-a-kind? full-house-hand))))
- (deftest test-flush?
- (is (= true (flush? flush-hand)))
- (is (= true (flush? straight-flush-hand)))
- (is (= false (flush? high-seven))))
- (deftest test-full-house?
- (is (= true (full-house? full-house-hand)))
- (is (= false (full-house? three-of-a-kind-hand))))
- (deftest test-two-pairs?
- (is (= true (two-pairs? two-pairs-hand)))
- (is (= false (two-pairs? full-house-hand))))
- (deftest test-straight?
- (is (= true (straight? straight-hand)))
- (is (= false (straight? high-seven)))
- (is (= true (straight? straight-flush-hand)))
- (is (= true (straight? high-ace-straight-flush-hand)))
- (is (= true (straight? low-ace-straight-flush-hand)))
- (is (= true (straight? high-ace-straight-hand)))
- (is (= true (straight? low-ace-straight-hand))))
- (deftest test-straight-flush?
- (is (= true (straight-flush? straight-flush-hand)))
- (is (= true (straight-flush? high-ace-straight-flush-hand)))
- (is (= true (straight-flush? low-ace-straight-flush-hand)))
- (is (= false (straight-flush? flush-hand)))
- (is (= false (straight-flush? straight-hand))))
- (deftest test-value
- (is (= 0 (value high-seven)))
- (is (= 1 (value pair-hand)))
- (is (= 2 (value two-pairs-hand)))
- (is (= 3 (value three-of-a-kind-hand)))
- (is (= 4 (value straight-hand)))
- (is (= 5 (value flush-hand)))
- (is (= 6 (value full-house-hand)))
- (is (= 7 (value four-of-a-kind-hand)))
- (is (= 8 (value straight-flush-hand))))
- (deftest test-kickers
- (is (= '(7 5 4 3 2) (kickers high-seven)))
- (is (= '(14 13 12 11 10) (kickers high-ace-straight-flush-hand)))
- (is (= '(6 5 4 3 2) (kickers straight-hand)))
- (is (= '(2 7 5 4) (kickers pair-hand)))
- (is (= '(4 2 7) (kickers two-pairs-hand)))
- (is (= '(2 7 4) (kickers three-of-a-kind-hand)))
- (is (= '(9 7 5 4 2) (kickers flush-hand)))
- (is (= '(2 5) (kickers full-house-hand)))
- (is (= '(2 7) (kickers four-of-a-kind-hand)))
- (is (= '(5 4 3 2 1) (kickers low-ace-straight-flush-hand))))
- (deftest test-higher-kicker?
- (is (= true (higher-kicker? (kickers high-ace-straight-hand) (kickers low-ace-straight-hand))))
- (is (= false (higher-kicker? '(7 6 4 3 2)'(7 6 4 3 2))))
- (is (= false (higher-kicker? (kickers straight-hand) (kickers flush-hand)))))
- (deftest test-beats?
- (is (= nil (beats? flush-hand flush-hand)))
- (is (= true (beats? four-of-a-kind-hand three-of-a-kind-hand)))
- (is (= true (beats? high-ace-straight-hand low-ace-straight-hand)))
- (is (= nil (beats? high-seven straight-hand)))
- (is (= true (beats? straight-flush-hand full-house-hand))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement