From aa2fa546745518c8c9119d7f0c10353f8d70abc1 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Mon, 24 Feb 2025 23:37:24 +0000 Subject: Implement test for int->rank --- tests/model.lisp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tests') diff --git a/tests/model.lisp b/tests/model.lisp index 32933ba..76924ca 100644 --- a/tests/model.lisp +++ b/tests/model.lisp @@ -23,6 +23,27 @@ (define-test model-test) +(define-test (model-test int->rank) + :depends-on ((cantedraw/tests/macros ->>) + (cantedraw/tests/functions rev-map)) + :compile-at :execute + (fail (int->rank nil)) + (fail (int->rank "Not a number")) + ;; Proving int->rank maps 0-51 to produces 13 ranks, all equally distributed. + (let ((mapping (rev-map #'int->rank (range 0 52)))) + ;; Prove there are 13 ranks + (is eq 13 (length mapping)) + ;; Prove every rank is equivalent in length. + (is eq 1 (->> mapping + (mapcar ($>> cdr length)) + remove-duplicates + length)) + ;; Prove Ace, 2, ..., 10, Jack, Queen, King are the 13 ranks. + (true (every #'identity + (->> (list :ace :king :queen :jack) + (append (range 2 11)) + (mapcar (lambda (rank) (assoc rank mapping)))))))) + (define-test (model-test int->suit) :depends-on ((cantedraw/tests/macros ->>) (cantedraw/tests/functions rev-map)) -- cgit v1.2.3-13-gbd6f