(defpackage #:kmrcl-tests
(:use #:kmrcl #:cl #:rtest))
(in-package #:kmrcl-tests)
-
+
(rem-all-tests)
(dotimes (ih 11)
(dotimes (is 11)
(dotimes (iv 11)
- (let ((h (/ ih 10))
+ (let ((h (* ih 30))
(s (/ is 10))
(v (/ iv 10)))
(multiple-value-bind (r g b) (hsv->rgb h s v)
(return-from test-color-conversion nil))))))))
t)
-(deftest color (test-color-conversion) t)
+(defun test-color-conversion-float-255 ()
+ (dotimes (ih 11)
+ (dotimes (is 11)
+ (dotimes (iv 11)
+ (let ((h (* ih 30))
+ (s (/ is 10))
+ (v (/ iv 10)))
+ (multiple-value-bind (r g b) (hsv->rgb h s v)
+ (setf r (round (* 255 r))
+ g (round (* 255 g))
+ b (round (* 255 b)))
+ (multiple-value-bind (h2 s2 v2) (rgb255->hsv255 r g b)
+ (unless (hsv-similar h s v h2 (/ s2 255) (/ v2 255)
+ :hue-range 10 :saturation-range .1
+ :value-range 1 :black-limit 0 :gray-limit 0)
+ (warn "Colors not equal: ~4D ~4D ~4D | ~6D:~6D ~6D:~6D ~6D:~6D~%"
+ r g b
+ (when (typep h 'number) (float h))
+ (when (typep h2 'number) (float h2))
+ (float s) (float (/ s2 255)) (float v) (float (/ v2 255)))
+ (return-from test-color-conversion-float-255 nil))))))))
+ t)
-
-;;; MOP Testing
+(defun test-color-conversion-255-float ()
+ (dotimes (ih 11)
+ (dotimes (is 11)
+ (dotimes (iv 11)
+ (let ((h (* ih 30))
+ (s (/ is 10))
+ (v (/ iv 10)))
+ (multiple-value-bind (r g b) (hsv255->rgb255 h (truncate (* 255 s))
+ (truncate (* 255 v)))
+ (setf r (/ r 255)
+ g (/ g 255)
+ b (/ b 255))
+
+ (multiple-value-bind (h2 s2 v2) (rgb->hsv r g b)
+ (unless (hsv-similar h s v h2 s2 v2
+ :hue-range 10 :saturation-range .1
+ :value-range 1 :black-limit 0 :gray-limit 0)
+ (warn "Colors not equal: ~4D ~4D ~4D | ~6D:~6D ~6D:~6D ~6D:~6D~%"
+ r g b
+ (when (typep h 'number) (float h))
+ (when (typep h2 'number) (float h2))
+ (float s) (float (/ s2 255)) (float v) (float (/ v2 255)))
+ (return-from test-color-conversion-255-float nil))))))))
+ t)
+
+(defun test-color-conversion-255 ()
+ (dotimes (ih 11)
+ (dotimes (is 11)
+ (dotimes (iv 11)
+ (let ((h (* ih 30))
+ (s (truncate (* 255 (/ is 10))))
+ (v (truncate (* 255 (/ iv 10)))))
+ (multiple-value-bind (r g b) (hsv255->rgb255 h s v)
+ (multiple-value-bind (h2 s2 v2) (rgb255->hsv255 r g b)
+ (unless (hsv255-similar h s v h2 s2 v2 :hue-range 10 :saturation-range 5
+ :value-range 5 :black-limit 0 :gray-limit 0)
+ (warn "Colors not equal: ~D ~D ~D |~
+ ~3,'0D:~3,'0D ~3,'0D:~3,'0D ~3,'0D:~3,'0D~%"
+ r g b
+ h h2 s s2 v v2)
+ (return-from test-color-conversion-255 nil))))))))
+ t)
+
+(deftest color.conv (test-color-conversion) t)
+(deftest color.conv.float.255 (test-color-conversion-float-255) t)
+(deftest color.conv.255.float (test-color-conversion-255-float) t)
+(deftest color.conv.255 (test-color-conversion-255) t)
+
+(deftest hue.diff.1 (hue-difference 10 10) 0)
+(deftest hue.diff.2 (hue-difference 10 9) -1)
+(deftest hue.diff.3 (hue-difference 9 10) 1)
+(deftest hue.diff.4 (hue-difference 10 nil) 360)
+(deftest hue.diff.5 (hue-difference nil 1) 360)
+(deftest hue.diff.7 (hue-difference 10 190) 180)
+(deftest hue.diff.8 (hue-difference 190 10) -180)
+(deftest hue.diff.9 (hue-difference 1 359) -2)
+(deftest hue.diff.10 (hue-difference 1 182) -179)
+(deftest hue.diff.11 (hue-difference 1 270) -91)
+
+(deftest hsv.sim.1 (hsv-similar 100 .5 .5 110 .5 .5 :hue-range 5
+ :value-range 0 :saturation-range 0
+ :black-limit 0 :gray-limit 0) nil)
+(deftest hsv.sim.2 (hsv-similar 100 .5 .5 110 .5 .5 :hue-range 15
+ :value-range 0 :saturation-range 0
+ :black-limit 0 :gray-limit 0) t)
+(deftest hsv.sim.3 (hsv-similar 100 .5 .5 110 .5 .6 :hue-range 15
+ :value-range .2 :saturation-range 0
+ :black-limit 0 :gray-limit 0) t)
+(deftest hsv.sim.4 (hsv-similar 100 .5 .5 110 .5 .8 :hue-range 15
+ :value-range 0.2 :saturation-range 0
+ :black-limit 0 :gray-limit 0) nil)
+(deftest hsv.sim.5 (hsv-similar 100 .5 .5 110 .6 .6 :hue-range 15
+ :value-range 0.2 :saturation-range .2
+ :black-limit 0 :gray-limit 0) t)
+(deftest hsv.sim.6 (hsv-similar 100 .5 .5 110 .6 .8 :hue-range 15
+ :value-range 0.2 :saturation-range .2
+ :black-limit 0 :gray-limit 0) nil)
+(deftest hsv.sim.7 (hsv-similar 100 .5 .05 110 .6 .01 :hue-range 0
+ :value-range 0 :saturation-range 0
+ :black-limit .1 :gray-limit 0) t)
+(deftest hsv.sim.8 (hsv-similar 100 .01 .5 110 .09 .6 :hue-range 0
+ :value-range 0.2 :saturation-range 0
+ :black-limit 0 :gray-limit .1) t)
+(deftest hsv.sim.9 (hsv-similar 100 .01 .5 110 .09 .6 :hue-range 0
+ :value-range 0.05 :saturation-range 0
+ :black-limit 0 :gray-limit .1) nil)
+
+#+ignore
+(progn
+(deftest dst.1
+ (is-dst-change-usa-spring-utime
+ (encode-universal-time 0 0 0 2 4 2000)) t)
+(deftest dst.2
+ (is-dst-change-usa-spring-utime
+ (encode-universal-time 0 0 0 1 4 2000)) nil)
+(deftest dst.3
+ (is-dst-change-usa-spring-utime
+ (encode-universal-time 0 0 0 3 4 2000)) nil)
+(deftest dst.4
+ (is-dst-change-usa-fall-utime
+ (encode-universal-time 0 0 0 31 10 2004)) t)
+(deftest dst.5
+ (is-dst-change-usa-fall-utime
+ (encode-universal-time 0 0 0 30 10 2004)) nil)
+(deftest dst.6
+ (is-dst-change-usa-fall-utime
+ (encode-universal-time 0 0 0 1 11 2000)) nil)
+)
+
+
+(deftest ekdc.1
+ (ensure-keyword-default-case (read-from-string "TYPE")) :type)
+
+(deftest ekdc.2
+ (ensure-keyword-default-case (read-from-string "type")) :type)
+
+
+ ;;; MOP Testing
(eval-when (:compile-toplevel :load-toplevel :execute)
(when (find-package '#:kmr-mop)
(pushnew :kmrtest-mop cl:*features*)))
#+kmrtest-mop
-(progn
- (setf (find-class 'monitored-credit-rating) nil)
- (setf (find-class 'credit-rating) nil)
+(setf (find-class 'monitored-credit-rating) nil)
+#+kmrtest-mop
+(setf (find-class 'credit-rating) nil)
- (defclass credit-rating ()
- ((level :attributes (date-set time-set))
- (id :attributes (person-setting)))
- (:metaclass attributes-class)
- #+lispworks (:optimize-slot-access nil)
- )
+#+kmrtest-mop
+(defclass credit-rating ()
+ ((level :attributes (date-set time-set))
+ (id :attributes (person-setting)))
+ #+lispworks (:optimize-slot-access nil)
+ (:metaclass attributes-class))
+
- (defclass monitored-credit-rating (credit-rating)
- ((level :attributes (last-checked interval date-set))
- (cc :initarg :cc)
- (id :attributes (verified)))
- (:metaclass attributes-class))
-
- (deftest attrib.mop.1
- (let ((cr (make-instance 'credit-rating)))
- (slot-attribute cr 'level 'date-set))
- nil)
-
- (deftest attrib.mop.2
- (let ((cr (make-instance 'credit-rating)))
- (setf (slot-attribute cr 'level 'date-set) "12/15/1990")
- (slot-attribute cr 'level 'date-set))
- "12/15/1990")
-
- (deftest attrib.mop.3
- (let ((mcr (make-instance 'monitored-credit-rating)))
- (setf (slot-attribute mcr 'level 'date-set) "01/05/2002")
- (slot-attribute mcr 'level 'date-set))
- "01/05/2002")
+#+kmrtest-mop
+(defclass monitored-credit-rating ()
+ ((level :attributes (last-checked interval date-set))
+ (cc :initarg :cc)
+ (id :attributes (verified)))
+ (:metaclass attributes-class))
+
+#+kmrtest-mop
+(deftest attrib.mop.1
+ (let ((cr (make-instance 'credit-rating)))
+ (slot-attribute cr 'level 'date-set))
+ nil)
+
+#+kmrtest-mop
+(deftest attrib.mop.2
+ (let ((cr (make-instance 'credit-rating)))
+ (setf (slot-attribute cr 'level 'date-set) "12/15/1990")
+ (let ((result (slot-attribute cr 'level 'date-set)))
+ (setf (slot-attribute cr 'level 'date-set) nil)
+ result))
+ "12/15/1990")
+
+#+kmrtest-mop
+(deftest attrib.mop.3
+ (let ((mcr (make-instance 'monitored-credit-rating)))
+ (setf (slot-attribute mcr 'level 'date-set) "01/05/2002")
+ (let ((result (slot-attribute mcr 'level 'date-set)))
+ (setf (slot-attribute mcr 'level 'date-set) nil)
+ result))
+ "01/05/2002")
- ) ;; kmrcl-mop
#+kmrtest-mop
(eval-when (:compile-toplevel :load-toplevel :execute)