r8057: add tests for color conversion, hsv-equal
[kmrcl.git] / tests.lisp
index 2c944aa508f3048bebf26a7eca4cc03be3a52c75..bf088b44a2115b29114d57d726c590574918e389 100644 (file)
@@ -1,4 +1,4 @@
-;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
+;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Package: kmrcl-tests -*-
 ;;;; *************************************************************************
 ;;;; FILE IDENTIFICATION
 ;;;;
@@ -7,7 +7,7 @@
 ;;;; Author:        Kevin M. Rosenberg
 ;;;; Date Started:  Apr 2003
 ;;;;
-;;;; $Id: tests.lisp,v 1.21 2003/07/01 22:16:40 kevin Exp $
+;;;; $Id$
 ;;;;
 ;;;; This file is Copyright (c) 2000-2002 by Kevin M. Rosenberg
 ;;;;
 (deftest css.4 (concat-separated-strings "|" '("ab" "cd") nil) "ab|cd")
 (deftest css.5 (concat-separated-strings "|" '("ab" "cd") nil '("ef")) "ab|cd|ef")
 
-(deftest f.1 (filter #'(lambda (x) (when (oddp x) (* x x)))
+(deftest f.1 (map-and-remove-nils #'(lambda (x) (when (oddp x) (* x x)))
                     '(0 1 2 3 4 5 6 7 8 9)) (1 9 25 49 81))
+(deftest f.2 (filter #'(lambda (x) (when (oddp x) (* x x)))
+                    '(0 1 2 3 4 5 6 7 8 9)) (1 3 5 7 9))
 (deftest an.1 (appendnew '(a b c d) '(c c e f)) (a b c d e f))
 
 
 (deftest duqs.4 (decode-uri-query-string "abc+d") "abc d")
 (deftest duqs.5 (decode-uri-query-string "abc%20d") "abc d")
 
+(deftest sse.1 (string-strip-ending "" nil) "")
+(deftest sse.2 (string-strip-ending "abc" nil) "abc")
+(deftest sse.3 (string-strip-ending "abc" "ab") "abc")
+(deftest sse.4 (string-strip-ending "abc" '("ab")) "abc")
+(deftest sse.5 (string-strip-ending "abcd" '("a" "cd")) "ab")
+
+
+(defun test-color-conversion ()
+  (dotimes (ih 11)
+    (dotimes (is 11)
+      (dotimes (iv 11)
+        (let ((h (/ ih 10))
+              (s (/ is 10))
+              (v (/ iv 10)))
+          (multiple-value-bind (r g b) (hsv->rgb h s v)
+            (multiple-value-bind (h2 s2 v2) (rgb->hsv r g b)
+              (unless (hsv-equal h s v h2 s2 v2)
+                (warn "Colors not equal: ~4D ~4D ~4D | ~6D:~6D ~6D:~6D ~6D:~6D~%" 
+                        (float r) (float g) (float b)
+                        (when (typep h 'number) (float h))
+                        (when (typep h2 'number) (float h2))
+                        (float s) (float s2) (float v) (float v2))
+                (return-from test-color-conversion nil))))))))
+  t)
+
+(deftest color (test-color-conversion) t)
+
+  
 ;;; MOP Testing
 
 (eval-when (:compile-toplevel :load-toplevel :execute)
 
 #+kmrtest-mop
 (progn
-  (setf (find-class 'credit-rating) nil)
   (setf (find-class 'monitored-credit-rating) nil)
+  (setf (find-class 'credit-rating) nil)
   
   (defclass credit-rating ()
     ((level :attributes (date-set time-set))