r10472: more tests
[cl-photo.git] / tests.lisp
1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          cl-photo-tests.lisp
6 ;;;; Purpose:       Cl-Photo tests file
7 ;;;; Programmer:    Kevin M. Rosenberg
8 ;;;; Date Started:  Apr 2003
9 ;;;;
10 ;;;; $Id$
11 ;;;;
12 ;;;; This file is Copyright (c) 2000-2003 by Kevin M. Rosenberg
13 ;;;; *************************************************************************
14
15 (defpackage #:cl-photo-tests
16   (:use #:cl-photo #:cl #:rtest #:kmrcl))
17 (in-package #:cl-photo-tests)
18
19 (rem-all-tests)
20
21 (defun verify-results (alist blist)
22   (every #'identity
23          (mapcar
24           (lambda (a b) (numbers-within-percentage a b 0.001))
25           alist blist)))
26
27 (defmacro def-numeric-test (name test &rest values)
28   `(deftest ,name
29             (let ((results (multiple-value-list ,test)))
30               (verify-results results ',values))
31             t))
32
33 (def-numeric-test
34  :gl.1 (gaussian-lens :focal-length 50 :object-distance 100) 100)
35
36 (def-numeric-test
37  :gl.2 (gaussian-lens :focal-length 50 :image-distance 200) 66.66667)
38
39 (def-numeric-test
40  :gl.3 (gaussian-lens :object-distance 100 :image-distance 100) 50)
41
42 (def-numeric-test
43  :aov.1 (aov 50 36 24) 39.5977 26.9915 46.7930)
44  
45 (def-numeric-test 
46  :fov.1 (fov 50 24 16 :magnification 1 :units :mm)
47  24 16 28.8444 1 100 100)
48
49 (def-numeric-test 
50  :fov.2 (fov 50 24 16 :magnification 1 :units :feet)
51  2.583338E-4 1.7222258E-4 3.10478E-4 1 0.328083 100)
52
53 (def-numeric-test 
54  :fov.3 (fov 50 24 16 :image-distance 100 :units :mm)
55  24 16 28.8444 1 100 100)
56
57 (def-numeric-test 
58  :fov.4 (fov 50 24 16 :image-distance 100 :units :feet)
59  2.583338E-4 1.7222258E-4 3.10478E-4 1 0.328083 100)
60
61 (def-numeric-test 
62  :fov.5 (fov 50 24 16 :object-distance 100 :units :mm)
63  24 16 28.8444 1 100 100)
64
65 (def-numeric-test 
66  :fov.6 (fov 50 24 16 :object-distance (cl-photo::mm->feet 100) :units :feet)
67  2.583338E-4 1.7222258E-4 3.10478E-4 1 0.328083 100)
68
69
70 (def-numeric-test 
71  :mag.1 (magnification :focal-length 50 :image-distance 100 :units :mm) 1)
72
73 (def-numeric-test 
74  :mag.2 (magnification :focal-length 50 :image-distance 100 :units :feet) 1)
75
76 (def-numeric-test 
77  :mag.3 (magnification :focal-length 50 :object-distance 100 :units :mm) 1)
78
79 (def-numeric-test 
80  :mag.4 (magnification :focal-length 50 :object-distance (cl-photo::mm->feet 100)
81                        :units :feet) 1)
82
83 (def-numeric-test 
84  :mag.5 (magnification :image-distance 100 :object-distance 100 :units :mm) 1)
85
86 (def-numeric-test 
87  :mag.6 (magnification :image-distance 100 :object-distance (cl-photo::mm->feet 100)
88                        :units :feet) 1)
89