3 LISP-UNIT Floating Point Tests
5 Copyright
(c) 2010-
2016, Thomas M. Hermann
7 Permission is hereby granted
, free of charge
, to any person obtaining
8 a copy of this software and associated documentation files
(the "Software"),
9 to deal in the Software without restriction
, including without limitation
10 the rights to use
, copy
, modify
, merge
, publish
, distribute
, sublicense
,
11 and
/or sell copies of the Software
, and to permit persons to whom the
12 Software is furnished to do so
, subject to the following conditions
:
14 The above copyright notice and this permission notice shall be included
15 in all copies or substantial portions of the Software.
17 THE SOFTWARE IS PROVIDED
"AS IS", WITHOUT WARRANTY OF ANY KIND
, EXPRESS
18 OR IMPLIED
, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY
,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM
, DAMAGES OR
21 OTHER LIABILITY
, WHETHER IN AN ACTION OF CONTRACT
, TORT OR OTHERWISE
,
22 ARISING FROM
, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 OTHER DEALINGS IN THE SOFTWARE.
27 (in-package :lisp-unit
)
31 (define-test %norm-list
32 "Internal test of %norm on lists."
35 (assert-rational-equal
36 36 (%norm
'(-6 -
5 -
4 -
3 -
2 -
1 0 1 2 3 4 5) 1))
40 '(#C
(1 0) #C
(3 1) #C
(2 3) #C
(0 4)
41 #C
(-2 3) #C
(-3 1) #C
(-1 0))
46 (%norm
'(-6 -
5 -
4 -
3 -
2 -
1 0 1 2 3 4 5) 2))
50 '(#C
(1 0) #C
(3 1) #C
(2 3) #C
(0 4)
51 #C
(-2 3) #C
(-3 1) #C
(-1 0)) 2))
53 (let ((data '(-6 -
5 -
4 -
3 -
2 -
1 0 1 2 3 4 5))
54 (zdata '(#C
(1 0) #C
(3 1) #C
(2 3) #C
(0 4)
55 #C
(-2 3) #C
(-3 1) #C
(-1 0))))
56 (assert-float-equal 8.732892 (%norm data
3))
57 (assert-float-equal 6.064035 (%norm zdata
3)))
59 (assert-rational-equal
61 '(-6 -
5 -
4 -
3 -
2 -
1 0 1 2 3 4 5)
65 '(#C
(1 0) #C
(3 1) #C
(2 3) #C
(0 4)
66 #C
(-2 3) #C
(-3 1) #C
(-1 0))
71 (define-test %norm-vector
72 "Internal test of %norm on vectors"
75 (assert-rational-equal
76 36 (%norm
#(-6 -
5 -
4 -
3 -
2 -
1 0 1 2 3 4 5) 1))
80 #(#C
(1 0) #C
(3 1) #C
(2 3) #C
(0 4)
81 #C
(-2 3) #C
(-3 1) #C
(-1 0))
86 (%norm
#(-6 -
5 -
4 -
3 -
2 -
1 0 1 2 3 4 5) 2))
90 #(#C
(1 0) #C
(3 1) #C
(2 3) #C
(0 4)
91 #C
(-2 3) #C
(-3 1) #C
(-1 0))
94 (let ((data #(-6 -
5 -
4 -
3 -
2 -
1 0 1 2 3 4 5))
95 (zdata #(#C
(1 0) #C
(3 1) #C
(2 3) #C
(0 4)
96 #C
(-2 3) #C
(-3 1) #C
(-1 0))))
97 (assert-float-equal 8.732892 (%norm data
3))
98 (assert-float-equal 6.064035 (%norm zdata
3)))
100 (assert-rational-equal
101 6 (%norm
#(-6 -
5 -
4 -
3 -
2 -
1 0 1 2 3 4 5) :infinity
))
104 #(#C
(1 0) #C
(3 1) #C
(2 3) #C
(0 4)
105 #C
(-2 3) #C
(-3 1) #C
(-1 0))