Skip to content

Commit

Permalink
Obviously another fix was necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
phoe committed May 9, 2020
1 parent 0083fdb commit 7e3d67c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
19 changes: 9 additions & 10 deletions koans-solved/dice-project.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
;; (defmethod dice-values ((object dice-set))
;; ____)

(defmethod roll ((count integer) (object dice-set))
(defmethod roll (count (object dice-set))
(check-type count (integer 1))
(setf (dice-values object)
(loop repeat count collect (random 6))))
(loop repeat count collect (1+ (random 6)))))

(define-test make-dice-set
(let ((dice (make-instance 'dice-set)))
Expand Down Expand Up @@ -78,19 +78,18 @@
(define-test junk-as-dice-count
(let ((dice (make-instance 'dice-set)))
(labels ((dice-failure (count)
(handler-case (progn (roll-dice count dice)
(handler-case (progn (roll count dice)
(error "Test failure"))
(error (condition) condition)))
(test-dice-failure (value)
(let* ((condition (dice-failure value))
(expected-type (type-error-expected-type condition)))
(assert-true (typep condition 'type-error))
(assert-equal value (type-error-datum condition))
(assert-true (subtypep expected-type '(integer 1 6)))
(assert-true (subtypep '(integer 1 6) expected-type)))))
(dice-failure 0)
(dice-failure "0")
(dice-failure :zero)
(dice-failure 18.0)
(dice-failure -7)
(dice-failure '(6 6 6)))))
(test-dice-failure 0)
(test-dice-failure "0")
(test-dice-failure :zero)
(test-dice-failure 18.0)
(test-dice-failure -7)
(test-dice-failure '(6 6 6)))))
17 changes: 8 additions & 9 deletions koans/dice-project.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
(defmethod dice-values ((object dice-set))
____)

(defmethod roll ((count integer) (object dice-set))
(defmethod roll (count (object dice-set))
____)

(define-test make-dice-set
Expand Down Expand Up @@ -76,19 +76,18 @@
(define-test junk-as-dice-count
(let ((dice (make-instance 'dice-set)))
(labels ((dice-failure (count)
(handler-case (progn (roll-dice count dice)
(handler-case (progn (roll count dice)
(error "Test failure"))
(error (condition) condition)))
(test-dice-failure (value)
(let* ((condition (dice-failure value))
(expected-type (type-error-expected-type condition)))
(assert-true (typep condition 'type-error))
(assert-equal value (type-error-datum condition))
(assert-true (subtypep expected-type '(integer 1 6)))
(assert-true (subtypep '(integer 1 6) expected-type)))))
(dice-failure 0)
(dice-failure "0")
(dice-failure :zero)
(dice-failure 18.0)
(dice-failure -7)
(dice-failure '(6 6 6)))))
(test-dice-failure 0)
(test-dice-failure "0")
(test-dice-failure :zero)
(test-dice-failure 18.0)
(test-dice-failure -7)
(test-dice-failure '(6 6 6)))))

0 comments on commit 7e3d67c

Please sign in to comment.