koans, looks like exception handling with signals
This commit is contained in:
parent
6f09e0019c
commit
f4759c5685
|
@ -37,25 +37,26 @@
|
|||
(define-test type-hierarchy
|
||||
;; Inheritance for condition types works the same way as for classes.
|
||||
(let ((condition (make-condition 'my-condition)))
|
||||
(true-or-false? ____ (typep condition 'my-condition))
|
||||
(true-or-false? ____ (typep condition 'condition))
|
||||
(true-or-false? ____ (typep condition 'warning))
|
||||
(true-or-false? ____ (typep condition 'error)))
|
||||
(true-or-false? t (typep condition 'my-condition))
|
||||
(true-or-false? t (typep condition 'condition))
|
||||
(true-or-false? nil (typep condition 'warning)) ; nope
|
||||
(true-or-false? nil (typep condition 'error))) ; nope
|
||||
(let ((condition (make-condition 'my-warning)))
|
||||
(true-or-false? ____ (typep condition 'my-warning))
|
||||
(true-or-false? ____ (typep condition 'warning))
|
||||
(true-or-false? ____ (typep condition 'error)))
|
||||
(true-or-false? t (typep condition 'my-warning))
|
||||
(true-or-false? t (typep condition 'warning))
|
||||
(true-or-false? nil (typep condition 'error)))
|
||||
(let ((condition (make-condition 'my-serious-condition)))
|
||||
(true-or-false? ____ (typep condition 'my-serious-condition))
|
||||
(true-or-false? ____ (typep condition 'serious-condition))
|
||||
(true-or-false? ____ (typep condition 'warning))
|
||||
(true-or-false? ____ (typep condition 'error)))
|
||||
(true-or-false? t (typep condition 'my-serious-condition))
|
||||
(true-or-false? t (typep condition 'serious-condition))
|
||||
(true-or-false? nil (typep condition 'warning))
|
||||
(true-or-false? nil (typep condition 'error)))
|
||||
(let ((condition (make-condition 'my-error)))
|
||||
(true-or-false? ____ (typep condition 'my-error))
|
||||
(true-or-false? ____ (typep condition 'my-serious-condition))
|
||||
(true-or-false? ____ (typep condition 'serious-condition))
|
||||
(true-or-false? ____ (typep condition 'warning))
|
||||
(true-or-false? ____ (typep condition 'error))))
|
||||
(true-or-false? t (typep condition 'my-error))
|
||||
(true-or-false? nil (typep condition 'my-serious-condition))
|
||||
(true-or-false? t (typep condition 'serious-condition)) ; not on first try
|
||||
(true-or-false? nil (typep condition 'warning))
|
||||
(true-or-false? t (typep condition 'error))))
|
||||
;; heh
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
|
@ -90,7 +91,8 @@
|
|||
(silly-condition #'handle-silly-condition)
|
||||
(most-silly-condition #'handle-most-silly-condition))
|
||||
(signal (make-condition 'most-silly-condition)))
|
||||
(assert-equal ____ *list*)))
|
||||
(assert-equal '(:most-silly-condition :silly-condition :very-silly-condition) *list*)))
|
||||
;; list is reverse order of functions in #'handler-bind
|
||||
|
||||
(define-test handler-order
|
||||
;; The order of binding handlers matters.
|
||||
|
|
|
@ -187,13 +187,16 @@
|
|||
(:method :after ((x bigger-object))
|
||||
(incf (counter x) 2)))
|
||||
|
||||
;; (setq object (make-instance 'bigger-object))
|
||||
;; (makunbound 'object)
|
||||
|
||||
(define-test standard-method-combination-order
|
||||
(let ((object (make-instance 'object)))
|
||||
(calculate object)
|
||||
(assert-equal ____ (counter object)))
|
||||
(assert-equal -1/94 (counter object)))
|
||||
(let ((object (make-instance 'bigger-object)))
|
||||
(calculate object)
|
||||
(assert-equal ____ (counter object))))
|
||||
(assert-equal 197/99 (counter object))))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
|
@ -219,13 +222,13 @@
|
|||
|
||||
(define-test salary-at-company-a
|
||||
(let ((programmer (make-instance 'programmer)))
|
||||
(assert-equal ____ (salary-at-company-a programmer)))
|
||||
(assert-equal 120000 (salary-at-company-a programmer)))
|
||||
(let ((programmer (make-instance 'senior-programmer)))
|
||||
(assert-equal ____ (salary-at-company-a programmer)))
|
||||
(assert-equal 320000 (salary-at-company-a programmer)))
|
||||
(let ((programmer (make-instance 'full-stack-programmer)))
|
||||
(assert-equal ____ (salary-at-company-a programmer)))
|
||||
(assert-equal (+ 48000 120000) (salary-at-company-a programmer)))
|
||||
(let ((programmer (make-instance 'senior-full-stack-programmer)))
|
||||
(assert-equal ____ (salary-at-company-a programmer))))
|
||||
(assert-equal (+ 200000 48000 120000) (salary-at-company-a programmer))))
|
||||
|
||||
;;; It is also possible to define custom method combinations.
|
||||
|
||||
|
@ -239,10 +242,10 @@
|
|||
|
||||
(define-test salary-at-company-b
|
||||
(let ((programmer (make-instance 'programmer)))
|
||||
(assert-equal ____ (salary-at-company-b programmer)))
|
||||
(assert-equal 120000 (salary-at-company-b programmer)))
|
||||
(let ((programmer (make-instance 'senior-programmer)))
|
||||
(assert-equal ____ (salary-at-company-b programmer)))
|
||||
(assert-equal (* 2 120000) (salary-at-company-b programmer)))
|
||||
(let ((programmer (make-instance 'full-stack-programmer)))
|
||||
(assert-equal ____ (salary-at-company-b programmer)))
|
||||
(assert-equal (* 7/5 120000) (salary-at-company-b programmer)))
|
||||
(let ((programmer (make-instance 'senior-full-stack-programmer)))
|
||||
(assert-equal ____ (salary-at-company-b programmer))))
|
||||
(assert-equal (* 2 7/5 120000) (salary-at-company-b programmer))))
|
||||
|
|
Loading…
Reference in New Issue