73e009b8588b1bd877064ed80fda33ad84e850e8
[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.01))
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   0.07874 0.052494 0.094634 1 0.328084 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   0.07874 0.052494 0.094634 1 0.328084 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   0.07874 0.052494 0.094634 1 0.328084 100)
68
69 (def-numeric-test 
70  :mag.1 (magnification :focal-length 50 :image-distance 100 :units :mm) 1)
71
72 (def-numeric-test 
73  :mag.2 (magnification :focal-length 50 :image-distance 100 :units :feet) 1)
74
75 (def-numeric-test 
76  :mag.3 (magnification :focal-length 50 :object-distance 100 :units :mm) 1)
77
78 (def-numeric-test 
79  :mag.4 (magnification :focal-length 50 :object-distance (cl-photo::mm->feet 100)
80                        :units :feet) 1)
81
82 (def-numeric-test 
83  :mag.5 (magnification :image-distance 100 :object-distance 100 :units :mm) 1)
84
85 (def-numeric-test 
86  :mag.6 (magnification :image-distance 100 :object-distance (cl-photo::mm->feet 100)
87                        :units :feet) 1)
88