aboutsummaryrefslogtreecommitdiff
path: root/tests/model.lisp
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2025-02-24 23:38:59 +0000
committerAryadev Chavali <aryadev@aryadevchavali.com>2025-02-24 23:38:59 +0000
commit7d7987cdc218bf1e2bff269c46e503fad0da45d8 (patch)
treef5a6a3235f13effd5f9d3cafc591618e6694559e /tests/model.lisp
parentf4d98ad07d117282300d3d1befdfa4c5ef39a357 (diff)
downloadcantedraw-7d7987cdc218bf1e2bff269c46e503fad0da45d8.tar.gz
cantedraw-7d7987cdc218bf1e2bff269c46e503fad0da45d8.tar.bz2
cantedraw-7d7987cdc218bf1e2bff269c46e503fad0da45d8.zip
Implement test for int->card
Diffstat (limited to 'tests/model.lisp')
-rw-r--r--tests/model.lisp20
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/model.lisp b/tests/model.lisp
index 4294b26..6ffdff9 100644
--- a/tests/model.lisp
+++ b/tests/model.lisp
@@ -112,3 +112,23 @@
(is equal int-range
(mapcar ($>> int->suit suit->int) int-range))))
+(define-test (model-test int->card)
+ :depends-on ((cantedraw/tests/functions range))
+ :compile-at :execute
+ (fail (int->card nil))
+ (fail (int->card "Not a number"))
+ ;; Proving int->card maps 0-51 to exactly 52 unique cards
+ (let ((mapping (mapcar #'int->card (range 0 52))))
+ (is eq 52 (length (remove-duplicates mapping :test #'equal))
+ "52 unique elements.")
+ (true (every #'card-p mapping)
+ "Every element is a card."))
+ ;; Prove that cards outside of [0, 51] are mapped to jokers (not exhaustive)
+ (loop :for positive :from 100 :to 200
+ :for negative :from -200 :to -100
+ :for inp := (mapcar #'int->card (list positive negative))
+ :do (true (every #'card-p inp)
+ "Is a card.")
+ :do (true (every (lambda (c) (eq :joker (card-suit c))) inp)
+ "Are jokers.")))
+