Skip to content

Commit

Permalink
Add more specs
Browse files Browse the repository at this point in the history
  • Loading branch information
gdonald committed Aug 20, 2023
1 parent 4d7bfcb commit 0398f9d
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 12 deletions.
16 changes: 4 additions & 12 deletions blackjack.el
Original file line number Diff line number Diff line change
Expand Up @@ -1045,18 +1045,10 @@ Can be a single-character currency symbol such as \"$\", \"€\" or \"£\", or a
"Ask hand action for GAME."
(let ((answer (blackjack--hand-actions-menu game)))
(pcase answer
("stand" (if (blackjack--hand-can-stand-p game)
(blackjack--stand game)
(blackjack--ask-hand-action game)))
("hit" (if (blackjack--hand-can-hit-p game)
(blackjack--hit game)
(blackjack--ask-hand-action game)))
("split" (if (blackjack--hand-can-split-p game)
(blackjack--split game)
(blackjack--ask-hand-action game)))
("double" (if (blackjack--hand-can-double-p game)
(blackjack--double game)
(blackjack--ask-hand-action game))))))
("stand" (blackjack--stand game))
("hit" (blackjack--hit game))
("split" (blackjack--split game))
("double" (blackjack--double game)))))

(defun blackjack--hand-actions-menu (game)
"Hand actions menu for GAME."
Expand Down
56 changes: 56 additions & 0 deletions tests/test-blackjack.el
Original file line number Diff line number Diff line change
Expand Up @@ -1477,6 +1477,62 @@
(blackjack--new-number-decks-prompt)
(expect 'read-string :to-have-been-called)))

(describe "blackjack--hand-menu"
:var ((game (blackjack-game)))

(it "returns no options for player hand menu as a string"
(expect (blackjack--hand-menu game) :to-equal ""))

(it "returns double option for player hand menu as a string"
(spy-on 'blackjack--hand-can-double-p :and-return-value t)
(expect (blackjack--hand-menu game) :to-equal "(d) double"))

(it "returns split option for player hand menu as a string"
(spy-on 'blackjack--hand-can-split-p :and-return-value t)
(expect (blackjack--hand-menu game) :to-equal "(p) split"))

(it "returns stand option for player hand menu as a string"
(spy-on 'blackjack--hand-can-stand-p :and-return-value t)
(expect (blackjack--hand-menu game) :to-equal "(s) stand"))

(it "returns hit option for player hand menu as a string"
(spy-on 'blackjack--hand-can-hit-p :and-return-value t)
(expect (blackjack--hand-menu game) :to-equal "(h) hit"))

(it "returns all options for player hand menu as a string"
(spy-on 'blackjack--hand-can-double-p :and-return-value t)
(spy-on 'blackjack--hand-can-split-p :and-return-value t)
(spy-on 'blackjack--hand-can-stand-p :and-return-value t)
(spy-on 'blackjack--hand-can-hit-p :and-return-value t)
(expect (blackjack--hand-menu game) :to-equal "(h) hit (s) stand (p) split (d) double")))

(describe "blackjack--ask-hand-action"
:var ((game (blackjack-game)))

(it "stands the hand"
(spy-on 'blackjack--hand-actions-menu :and-return-value "stand")
(spy-on 'blackjack--stand)
(blackjack--ask-hand-action game)
(expect 'blackjack--stand :to-have-been-called))

(it "hits the hand"
(spy-on 'blackjack--hand-actions-menu :and-return-value "hit")
(spy-on 'blackjack--hit)
(blackjack--ask-hand-action game)
(expect 'blackjack--hit :to-have-been-called))

(it "splits the hand"
(spy-on 'blackjack--hand-actions-menu :and-return-value "split")
(spy-on 'blackjack--split)
(blackjack--ask-hand-action game)
(expect 'blackjack--split :to-have-been-called))

(it "doubles the hand"
(spy-on 'blackjack--hand-actions-menu :and-return-value "double")
(spy-on 'blackjack--double)
(blackjack--ask-hand-action game)
(expect 'blackjack--double :to-have-been-called)))

(provide 'test-blackjack)

;;; test-blackjack.el ends here
Expand Down

0 comments on commit 0398f9d

Please sign in to comment.