/[cl-gsl]/cl-gsl/test/test-vector.lisp
ViewVC logotype

Contents of /cl-gsl/test/test-vector.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (show annotations)
Sat Apr 30 22:39:46 2005 UTC (8 years, 11 months ago) by edenny
Branch: MAIN
CVS Tags: HEAD
Changes since 1.6: +46 -55 lines
Slight sylistic changes to a few unit tests.
1 ;;;; -*- Mode: Lisp; Synatx: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;;
3 ;;;; Copyright (C) 2005 Edgar Denny <edgardenny@comcast.net>
4 ;;;; This file is part of CL-GSL.
5 ;;;;
6 ;;;; This program is free software; you can redistribute it and/or modify
7 ;;;; it under the terms of the GNU General Public License as published by
8 ;;;; the Free Software Foundation; either version 2 of the License, or
9 ;;;; (at your option) any later version.
10 ;;;;
11 ;;;; This program is distributed in the hope that it will be useful,
12 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;;; GNU General Public License for more details.
15 ;;;;
16 ;;;; You should have received a copy of the GNU General Public License
17 ;;;; along with this program; if not, write to the Free Software
18 ;;;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20 (in-package #:cl-gsl-test)
21
22 (defconstant +vector+ "vector")
23
24 (deftest "make-vector-double-float" :category +vector+
25 :test-fn
26 #'(lambda ()
27 (let ((v (gsl-array:make-vector 5 :element-type 'double-float)))
28 (prog1
29 (and (= (gsl-array::size v) 5)
30 (eq (gsl-array::element-type v) 'double-float))
31 (gsl-array:free v)))))
32
33
34 (deftest "make-vector-single-float" :category +vector+
35 :test-fn
36 #'(lambda ()
37 (let ((v (gsl-array:make-vector 5 :element-type 'single-float)))
38 (prog1
39 (and (= (gsl-array::size v) 5)
40 (eq (gsl-array::element-type v) 'single-float))
41 (gsl-array:free v)))))
42
43 (deftest "make-vector-integer" :category +vector+
44 :test-fn
45 #'(lambda ()
46 (let ((v (gsl-array:make-vector 5 :element-type 'integer)))
47 (prog1
48 (and (= (gsl-array::size v) 5)
49 (eq (gsl-array::element-type v) 'integer))
50 (gsl-array:free v)))))
51
52 (deftest "make-vector-complex-double-float" :category +vector+
53 :test-fn
54 #'(lambda ()
55 (let ((v (gsl-array:make-vector 5 :element-type
56 '(complex (double-float)))))
57 (prog1
58 (and (= (gsl-array::size v) 5)
59 (equal (gsl-array::element-type v)
60 '(complex (double-float))))
61 (gsl-array:free v)))))
62
63 (deftest "make-vector-complex-single-float" :category +vector+
64 :test-fn
65 #'(lambda ()
66 (let ((v (gsl-array:make-vector 5 :element-type
67 '(complex (single-float)))))
68 (prog1
69 (and (= (gsl-array::size v) 5)
70 (equal (gsl-array::element-type v)
71 '(complex (single-float))))
72 (gsl-array:free v)))))
73
74 ;; ----------------------------------------------------------------------
75
76 (deftest "make-vector-double-float-initial-element" :category +vector+
77 :test-fn
78 #'(lambda ()
79 (let ((v (gsl-array:make-vector 5 :element-type 'double-float
80 :initial-element 1.0d0)))
81 (prog1
82 (dotimes (i 5 t)
83 (unless (= (gsl-array:get-element v i) 1.0d0)
84 (return nil)))
85 (gsl-array:free v)))))
86
87
88 (deftest "make-vector-single-float-initial-element" :category +vector+
89 :test-fn
90 #'(lambda ()
91 (let ((v (gsl-array:make-vector 5 :element-type 'single-float
92 :initial-element 1.0)))
93 (prog1
94 (dotimes (i 5 t)
95 (unless (= (gsl-array:get-element v i) 1.0)
96 (return nil)))
97 (gsl-array:free v)))))
98
99
100 (deftest "make-vector-integer-initial-element" :category +vector+
101 :test-fn
102 #'(lambda ()
103 (let ((v (gsl-array:make-vector 5 :element-type 'integer
104 :initial-element 1)))
105 (prog1
106 (dotimes (i 5 t)
107 (unless (= (gsl-array:get-element v i) 1)
108 (return nil)))
109 (gsl-array:free v)))))
110
111 (deftest "make-vector-complex-double-float-initial-element" :category +vector+
112 :test-fn
113 #'(lambda ()
114 (let ((v (gsl-array:make-vector 5 :element-type
115 '(complex (double-float))
116 :initial-element
117 (complex 1.0d0 1.0d0))))
118 (prog1
119 (dotimes (i 5 t)
120 (unless (= (gsl-array:get-element v i)
121 (complex 1.0d0 1.0d0))
122 (return nil)))
123 (gsl-array:free v)))))
124
125
126 (deftest "make-vector-complex-single-float-initial-element" :category +vector+
127 :test-fn
128 #'(lambda ()
129 (let ((v (gsl-array:make-vector 5 :element-type
130 '(complex (single-float))
131 :initial-element
132 (complex 1.0 1.0))))
133 (prog1
134 (dotimes (i 5 t)
135 (unless (= (gsl-array:get-element v i) (complex 1.0 1.0))
136 (return nil)))
137 (gsl-array:free v)))))
138
139 ;; ----------------------------------------------------------------------
140
141 (deftest "make-vector-double-float-initial-contents" :category +vector+
142 :test-fn
143 #'(lambda ()
144 (let ((v (gsl-array:make-vector
145 5
146 :element-type 'double-float
147 :initial-contents (list 1.0d0 2.0d0 3.0d0 4.0d0 5.0d0)))
148 (ret t)
149 (val 0.0d0))
150 (dotimes (i 5 ret)
151 (unless (= (gsl-array:get-element v i) (incf val 1.0d0))
152 (setq ret nil)))
153 (gsl-array:free v)
154 ret)))
155
156
157 (deftest "make-vector-single-float-initial-contents" :category +vector+
158 :test-fn
159 #'(lambda ()
160 (let ((v (gsl-array:make-vector
161 5
162 :element-type 'single-float
163 :initial-contents (vector -1.0 -2.0 -3.0 -4.0 -5.0)))
164 (ret t)
165 (val 0.0))
166 (dotimes (i 5 ret)
167 (unless (= (gsl-array:get-element v i) (decf val 1.0))
168 (setq ret nil)))
169 (gsl-array:free v)
170 ret)))
171
172
173 (deftest "make-vector-integer-initial-contents" :category +vector+
174 :test-fn
175 #'(lambda ()
176 (let ((v (gsl-array:make-vector
177 5
178 :element-type 'integer
179 :initial-contents (list 1 2 3 4 5)))
180 (ret t)
181 (val 0))
182 (dotimes (i 5 ret)
183 (unless (= (gsl-array:get-element v i) (incf val))
184 (setq ret nil)))
185 (gsl-array:free v)
186 ret)))
187
188 (deftest "make-vector-complex-double-float-initial-contents" :category +vector+
189 :test-fn
190 #'(lambda ()
191 (let ((v (gsl-array:make-vector
192 5
193 :element-type '(complex (double-float))
194 :initial-contents
195 (vector (complex 1.0d0 1.0d0) (complex 2.0d0 2.0d0)
196 (complex 3.0d0 3.0d0) (complex 4.0d0 4.0d0)
197 (complex 5.0d0 5.0d0))))
198 (ret t)
199 (val (complex 0.0d0 0.0d0)))
200 (dotimes (i 5 ret)
201 (unless (= (gsl-array:get-element v i)
202 (incf val (complex 1.0d0 1.0d0)))
203 (setq ret nil)))
204 (gsl-array:free v)
205 ret)))
206
207 (deftest "make-vector-complex-single-float-initial-contents" :category +vector+
208 :test-fn
209 #'(lambda ()
210 (let ((v (gsl-array:make-vector
211 5
212 :element-type '(complex (single-float))
213 :initial-contents
214 (list (complex -1.0 -1.0) (complex -2.0 -2.0)
215 (complex -3.0 -3.0) (complex -4.0 -4.0)
216 (complex -5.0 -5.0))))
217 (ret t)
218 (val (complex 0.0 0.0)))
219 (dotimes (i 5 ret)
220 (unless (= (gsl-array:get-element v i)
221 (decf val (complex 1.0 1.0)))
222 (setq ret nil)))
223 (gsl-array:free v)
224 ret)))
225
226 ;; ----------------------------------------------------------------------
227
228 (deftest "set-all-double-float" :category +vector+
229 :test-fn
230 #'(lambda ()
231 (gsl-array:with-vector (v 5 :element-type 'double-float)
232 (gsl-array:set-all v 5.0d0)
233 (let ((ret t))
234 (dotimes (i 5 ret)
235 (unless (= (gsl-array:get-element v i) 5.0d0)
236 (setq ret nil)))))))
237
238
239 (deftest "set-all-single-float" :category +vector+
240 :test-fn
241 #'(lambda ()
242 (gsl-array:with-vector (v 5 :element-type 'single-float)
243 (gsl-array:set-all v 5.0)
244 (dotimes (i 5 t)
245 (unless (= (gsl-array:get-element v i) 5.0)
246 (return nil))))))
247
248 (deftest "set-all-integer" :category +vector+
249 :test-fn
250 #'(lambda ()
251 (gsl-array:with-vector (v 5 :element-type 'integer)
252 (gsl-array:set-all v 5)
253 (dotimes (i 5 t)
254 (unless (= (gsl-array:get-element v i) 5)
255 (return nil))))))
256
257 (deftest "set-all-complex-double-float" :category +vector+
258 :test-fn
259 #'(lambda ()
260 (gsl-array:with-vector
261 (v 5 :element-type '(complex (double-float)))
262 (gsl-array:set-all v (complex 5.0d0 4.0d0))
263 (let ((ret t))
264 (dotimes (i 5 ret)
265 (unless (= (gsl-array:get-element v i)
266 (complex 5.0d0 4.0d0))
267 (setq ret nil)))))))
268
269 (deftest "set-all-complex-single-float" :category +vector+
270 :test-fn
271 #'(lambda ()
272 (gsl-array:with-vector
273 (v 5 :element-type '(complex (single-float)))
274 (gsl-array:set-all v (complex 5.0 4.0))
275 (let ((ret t))
276 (dotimes (i 5 ret)
277 (unless (= (gsl-array:get-element v i) (complex 5.0 4.0))
278 (setq ret nil)))))))
279
280 ;; ----------------------------------------------------------------------
281
282 (deftest "set-zero-double-float" :category +vector+
283 :test-fn
284 #'(lambda ()
285 (gsl-array:with-vector (v 5 :element-type 'double-float)
286 (gsl-array:set-all v 5.0d0)
287 (gsl-array:set-zero v)
288 (let ((ret t))
289 (dotimes (i 5 ret)
290 (unless (= (gsl-array:get-element v i) 0.0d0)
291 (setq ret nil)))))))
292
293
294 (deftest "set-zero-single-float" :category +vector+
295 :test-fn
296 #'(lambda ()
297 (gsl-array:with-vector (v 5 :element-type 'single-float)
298 (gsl-array:set-all v 5.0)
299 (gsl-array:set-zero v)
300 (let ((ret t))
301 (dotimes (i 5 ret)
302 (unless (= (gsl-array:get-element v i) 0.0)
303 (setq ret nil)))))))
304
305 (deftest "set-zero-integer" :category +vector+
306 :test-fn
307 #'(lambda ()
308 (gsl-array:with-vector (v 5 :element-type 'integer)
309 (gsl-array:set-all v 5)
310 (gsl-array:set-zero v)
311 (let ((ret t))
312 (dotimes (i 5 ret)
313 (unless (= (gsl-array:get-element v i) 0)
314 (setq ret nil)))))))
315
316 (deftest "set-zero-complex-double-float" :category +vector+
317 :test-fn
318 #'(lambda ()
319 (gsl-array:with-vector
320 (v 5 :element-type '(complex (double-float)))
321 (gsl-array:set-all v (complex 5.0d0 4.0d0))
322 (gsl-array:set-zero v)
323 (let ((ret t))
324 (dotimes (i 5 ret)
325 (unless (= (gsl-array:get-element v i)
326 (complex 0.0d0 0.0d0))
327 (setq ret nil)))))))
328
329 (deftest "set-zero-complex-single-float" :category +vector+
330 :test-fn
331 #'(lambda ()
332 (gsl-array:with-vector
333 (v 5 :element-type '(complex (single-float)))
334 (gsl-array:set-all v (complex 5.0 4.0))
335 (gsl-array:set-zero v)
336 (let ((ret t))
337 (dotimes (i 5 ret)
338 (unless (= (gsl-array:get-element v i) (complex 0.0 0.0))
339 (setq ret nil)))))))
340
341 ;; ----------------------------------------------------------------------
342
343 (deftest "set-basis-double-float" :category +vector+
344 :test-fn
345 #'(lambda ()
346 (gsl-array:with-vector (v 5 :element-type 'double-float)
347 (gsl-array:set-basis v 3)
348 (let ((ret t))
349 (dotimes (i 5 ret)
350 (if (= i 3)
351 (unless (= (gsl-array:get-element v i) 1.0d0)
352 (setq ret nil))
353 (unless (= (gsl-array:get-element v i) 0.0d0)
354 (setq ret nil))))))))
355
356 (deftest "set-basis-single-float" :category +vector+
357 :test-fn
358 #'(lambda ()
359 (gsl-array:with-vector (v 5 :element-type 'single-float)
360 (gsl-array:set-basis v 2)
361 (let ((ret t))
362 (dotimes (i 5 ret)
363 (if (= i 2)
364 (unless (= (gsl-array:get-element v i) 1.0)
365 (setq ret nil))
366 (unless (= (gsl-array:get-element v i) 0.0)
367 (setq ret nil))))))))
368
369 (deftest "set-basis-integer" :category +vector+
370 :test-fn
371 #'(lambda ()
372 (gsl-array:with-vector (v 5 :element-type 'integer)
373 (gsl-array:set-basis v 1)
374 (let ((ret t))
375 (dotimes (i 5 ret)
376 (if (= i 1)
377 (unless (= (gsl-array:get-element v i) 1)
378 (setq ret nil))
379 (unless (= (gsl-array:get-element v i) 0)
380 (setq ret nil))))))))
381
382 (deftest "set-basis-complex-double-float" :category +vector+
383 :test-fn
384 #'(lambda ()
385 (gsl-array:with-vector
386 (v 5 :element-type '(complex (double-float)))
387 (gsl-array:set-basis v 4)
388 (let ((ret t))
389 (dotimes (i 5 ret)
390 (if (= i 4)
391 (unless (= (gsl-array:get-element v i)
392 (complex 1.0d0 0.0d0))
393 (setq ret nil))
394 (unless (= (gsl-array:get-element v i)
395 (complex 0.0d0 0.0d0))
396 (setq ret nil))))))))
397
398 (deftest "set-basis-complex-single-float" :category +vector+
399 :test-fn
400 #'(lambda ()
401 (gsl-array:with-vector
402 (v 5 :element-type '(complex (single-float)))
403 (gsl-array:set-basis v 0)
404 (let ((ret t))
405 (dotimes (i 5 ret)
406 (if (= i 0)
407 (unless (= (gsl-array:get-element v i)
408 (complex 1.0 0.0))
409 (setq ret nil))
410 (unless (= (gsl-array:get-element v i)
411 (complex 0.0 0.0))
412 (setq ret nil))))))))
413
414
415 ;; ----------------------------------------------------------------------
416
417 (deftest "set-element-double-float" :category +vector+
418 :test-fn
419 #'(lambda ()
420 (gsl-array:with-vector (v 5 :element-type 'double-float)
421 (gsl-array:set-zero v)
422 (gsl-array:set-element v 3 6.0d0)
423 (let ((ret t))
424 (dotimes (i 5 ret)
425 (if (= i 3)
426 (unless (= (gsl-array:get-element v i) 6.0d0)
427 (setq ret nil))
428 (unless (= (gsl-array:get-element v i) 0.0d0)
429 (setq ret nil))))))))
430
431
432 (deftest "set-element-single-float" :category +vector+
433 :test-fn
434 #'(lambda ()
435 (gsl-array:with-vector (v 5 :element-type 'single-float)
436 (gsl-array:set-zero v)
437 (gsl-array:set-element v 2 6.0)
438 (let ((ret t))
439 (dotimes (i 5 ret)
440 (if (= i 2)
441 (unless (= (gsl-array:get-element v i) 6.0)
442 (setq ret nil))
443 (unless (= (gsl-array:get-element v i) 0.0)
444 (setq ret nil))))))))
445
446 (deftest "set-element-integer" :category +vector+
447 :test-fn
448 #'(lambda ()
449 (gsl-array:with-vector (v 5 :element-type 'integer)
450 (gsl-array:set-zero v)
451 (gsl-array:set-element v 1 6)
452 (let ((ret t))
453 (dotimes (i 5 ret)
454 (if (= i 1)
455 (unless (= (gsl-array:get-element v i) 6)
456 (setq ret nil))
457 (unless (= (gsl-array:get-element v i) 0)
458 (setq ret nil))))))))
459
460 (deftest "set-element-complex-double-float" :category +vector+
461 :test-fn
462 #'(lambda ()
463 (gsl-array:with-vector
464 (v 5 :element-type '(complex (double-float)))
465 (gsl-array:set-zero v)
466 (gsl-array:set-element v 4 (complex 6.0d0 7.0d0))
467 (let ((ret t))
468 (dotimes (i 5 ret)
469 (if (= i 4)
470 (unless (= (gsl-array:get-element v i)
471 (complex 6.0d0 7.0d0))
472 (setq ret nil))
473 (unless (= (gsl-array:get-element v i)
474 (complex 0.0d0 0.0d0))
475 (setq ret nil))))))))
476
477 (deftest "set-element-complex-single-float" :category +vector+
478 :test-fn
479 #'(lambda ()
480 (gsl-array:with-vector
481 (v 5 :element-type '(complex (single-float)))
482 (gsl-array:set-zero v)
483 (gsl-array:set-element v 0 (complex 6.0 7.0))
484 (let ((ret t))
485 (dotimes (i 5 ret)
486 (if (= i 0)
487 (unless (= (gsl-array:get-element v i)
488 (complex 6.0 7.0))
489 (setq ret nil))
490 (unless (= (gsl-array:get-element v i)
491 (complex 0.0 0.0))
492 (setq ret nil))))))))
493
494 ;; ----------------------------------------------------------------------
495
496 (deftest "isnull-double-float" :category +vector+
497 :test-fn
498 #'(lambda ()
499 (gsl-array:with-vector (v 5 :element-type 'double-float)
500 (gsl-array:set-zero v)
501 (gsl-array:isnull v))))
502
503
504 (deftest "isnull-single-float" :category +vector+
505 :test-fn
506 #'(lambda ()
507 (gsl-array:with-vector (v 5 :element-type 'single-float)
508 (gsl-array:set-basis v 0)
509 ;; check for failure of isnull
510 (not (gsl-array:isnull v)))))
511
512
513 (deftest "isnull-integer" :category +vector+
514 :test-fn
515 #'(lambda ()
516 (gsl-array:with-vector (v 5 :element-type 'integer)
517 (gsl-array:set-zero v)
518 (gsl-array:isnull v))))
519
520 (deftest "isnull-complex-double-float" :category +vector+
521 :test-fn
522 #'(lambda ()
523 (gsl-array:with-vector
524 (v 5 :element-type '(complex (double-float)))
525 (gsl-array:set-basis v 1)
526 (not (gsl-array:isnull v)))))
527
528 (deftest "isnull-complex-single-float" :category +vector+
529 :test-fn
530 #'(lambda ()
531 (gsl-array:with-vector
532 (v 5 :element-type '(complex (single-float)))
533 (gsl-array:set-zero v)
534 (gsl-array:isnull v))))
535
536 ;; ----------------------------------------------------------------------
537
538 (deftest "reverse-double-float" :category +vector+
539 :test-fn
540 #'(lambda ()
541 (let ((vec (vector 1.0d0 2.0d0 3.0d0 4.0d0 5.0d0)))
542 (gsl-array:with-vector
543 (v 5 :element-type 'double-float :initial-contents vec)
544 (equalp (reverse vec)
545 (gsl-array:gsl->lisp-vector
546 (gsl-array:reverse-vector v)))))))
547
548 (deftest "reverse-single-float" :category +vector+
549 :test-fn
550 #'(lambda ()
551 (let ((vec (vector 1.0 2.0 3.0 4.0 5.0)))
552 (gsl-array:with-vector
553 (v 5 :element-type 'single-float :initial-contents vec)
554 (equalp (reverse vec)
555 (gsl-array:gsl->lisp-vector
556 (gsl-array:reverse-vector v)))))))
557
558 (deftest "reverse-integer" :category +vector+
559 :test-fn
560 #'(lambda ()
561 (let ((vec (vector 1 2 3 4 5)))
562 (gsl-array:with-vector
563 (v 5 :element-type 'integer :initial-contents vec)
564 (equalp (reverse vec)
565 (gsl-array:gsl->lisp-vector
566 (gsl-array:reverse-vector v)))))))
567
568
569 (deftest "reverse-complex-double-float" :category +vector+
570 :test-fn
571 #'(lambda ()
572 (let ((vec (vector (complex 1.0d0 1.0d0) (complex 2.0d0 2.0d0)
573 (complex 3.0d0 3.0d0) (complex 4.0d0 4.0d0)
574 (complex 5.0d0 5.0d0))))
575 (gsl-array:with-vector
576 (v 5 :element-type '(complex (double-float))
577 :initial-contents vec)
578 (equalp (reverse vec)
579 (gsl-array:gsl->lisp-vector
580 (gsl-array:reverse-vector v)))))))
581
582
583 (deftest "reverse-complex-single-float" :category +vector+
584 :test-fn
585 #'(lambda ()
586 (let ((vec (vector (complex -1.0 -1.0) (complex -2.0 -2.0)
587 (complex -3.0 -3.0) (complex -4.0 -4.0)
588 (complex -5.0 -5.0))))
589 (gsl-array:with-vector
590 (v 5 :element-type '(complex (single-float))
591 :initial-contents vec)
592 (equalp (reverse vec)
593 (gsl-array:gsl->lisp-vector
594 (gsl-array:reverse-vector v)))))))
595
596 ;; ----------------------------------------------------------------------
597
598 (deftest "read-write-double-float" :category +vector+
599 :test-fn
600 #'(lambda ()
601 (let ((vec (vector 1.0d0 2.0d0 3.0d0 4.0d0 5.0d0)))
602 (gsl-array:with-vector
603 (v1 5 :element-type 'double-float :initial-contents vec)
604 (gsl-array:write-to-file "/tmp/test.txt" v1)
605 (gsl-array:with-vector
606 (v2 5 :element-type 'double-float
607 :from-file "/tmp/test.txt")
608 (and (equalp vec (gsl-array:gsl->lisp-vector v1))
609 (equalp vec (gsl-array:gsl->lisp-vector v2))))))))
610
611 (deftest "read-write-single-float" :category +vector+
612 :test-fn
613 #'(lambda ()
614 (let ((vec (vector 1.0 2.0 3.0 4.0 5.0)))
615 (gsl-array:with-vector
616 (v1 5 :element-type 'single-float :initial-contents vec)
617 (gsl-array:write-to-file "/tmp/test.txt" v1)
618 (gsl-array:with-vector
619 (v2 5 :element-type 'single-float
620 :from-file "/tmp/test.txt")
621 (and (equalp vec (gsl-array:gsl->lisp-vector v1))
622 (equalp vec (gsl-array:gsl->lisp-vector v2))))))))
623
624 (deftest "read-write-integer" :category +vector+
625 :test-fn
626 #'(lambda ()
627 (let ((vec (vector 1 2 3 4 5)))
628 (gsl-array:with-vector
629 (v1 5 :element-type 'integer :initial-contents vec)
630 (gsl-array:write-to-file "/tmp/test.txt" v1)
631 (gsl-array:with-vector
632 (v2 5 :element-type 'integer :from-file "/tmp/test.txt")
633 (and (equalp vec (gsl-array:gsl->lisp-vector v1))
634 (equalp vec (gsl-array:gsl->lisp-vector v2))))))))
635
636 (deftest "read-write-complex-double-float" :category +vector+
637 :test-fn
638 #'(lambda ()
639 (let ((vec (vector (complex 1.0d0 1.0d0) (complex 2.0d0 2.0d0)
640 (complex 3.0d0 3.0d0) (complex 4.0d0 4.0d0)
641 (complex 5.0d0 5.0d0))))
642 (gsl-array:with-vector
643 (v1 5 :element-type '(complex (double-float))
644 :initial-contents vec)
645 (gsl-array:write-to-file "/tmp/test.txt" v1)
646 (gsl-array:with-vector
647 (v2 5 :element-type '(complex (double-float))
648 :from-file "/tmp/test.txt")
649 (and (equalp vec (gsl-array:gsl->lisp-vector v1))
650 (equalp vec (gsl-array:gsl->lisp-vector v2))))))))
651
652 (deftest "read-write-complex-single-float" :category +vector+
653 :test-fn
654 #'(lambda ()
655 (let ((vec (vector (complex 1.0 1.0) (complex 2.0 2.0)
656 (complex 3.0 3.0) (complex 4.0 4.0)
657 (complex 5.0 5.0))))
658 (gsl-array:with-vector
659 (v1 5 :element-type '(complex (single-float))
660 :initial-contents vec)
661 (gsl-array:write-to-file "/tmp/test.txt" v1)
662 (gsl-array:with-vector
663 (v2 5 :element-type '(complex (single-float))
664 :from-file "/tmp/test.txt")
665 (and (equalp vec (gsl-array:gsl->lisp-vector v1))
666 (equalp vec (gsl-array:gsl->lisp-vector v2))))))))
667
668
669 ;; ----------------------------------------------------------------------
670
671 (deftest "read-write-binary-double-float" :category +vector+
672 :test-fn
673 #'(lambda ()
674 (let ((vec (vector 1.0000000000001d0 2.0d0 3.0d0 4.0d0 5.0d0)))
675 (gsl-array:with-vector
676 (v1 5 :element-type 'double-float :initial-contents vec)
677 (gsl-array:write-to-binary-file "/tmp/test.bin" v1)
678 (gsl-array:with-vector (v2 5 :element-type 'double-float
679 :from-binary-file "/tmp/test.bin")
680 (and (equalp vec (gsl-array:gsl->lisp-vector v1))
681 (equalp vec (gsl-array:gsl->lisp-vector v2))))))))
682
683 (deftest "read-write-binary-single-float" :category +vector+
684 :test-fn
685 #'(lambda ()
686 (let ((vec (vector 1.0 2.0 3.0 4.0 5.0)))
687 (gsl-array:with-vector
688 (v1 5 :element-type 'single-float :initial-contents vec)
689 (gsl-array:write-to-binary-file "/tmp/test.bin" v1)
690 (gsl-array:with-vector (v2 5 :element-type 'single-float
691 :from-binary-file "/tmp/test.bin")
692 (and (equalp vec (gsl-array:gsl->lisp-vector v1))
693 (equalp vec (gsl-array:gsl->lisp-vector v2))))))))
694
695
696 (deftest "read-write-binary-integer" :category +vector+
697 :test-fn
698 #'(lambda ()
699 (let ((vec (vector 1 2 3 4 5)))
700 (gsl-array:with-vector
701 (v1 5 :element-type 'integer :initial-contents vec)
702 (gsl-array:write-to-binary-file "/tmp/test.bin" v1)
703 (gsl-array:with-vector (v2 5 :element-type 'integer
704 :from-binary-file "/tmp/test.bin")
705 (and (equalp vec (gsl-array:gsl->lisp-vector v1))
706 (equalp vec (gsl-array:gsl->lisp-vector v2))))))))
707
708 (deftest "read-write-binary-complex-double-float" :category +vector+
709 :test-fn
710 #'(lambda ()
711 (let ((vec (vector (complex 1.0d0 1.0d0) (complex 2.0d0 2.0d0)
712 (complex 3.0d0 3.0d0) (complex 4.0d0 4.0d0)
713 (complex 5.0d0 5.0d0))))
714 (gsl-array:with-vector
715 (v1 5 :element-type '(complex (double-float))
716 :initial-contents vec)
717 (gsl-array:write-to-binary-file "/tmp/test.bin" v1)
718 (gsl-array:with-vector
719 (v2 5 :element-type '(complex (double-float))
720 :from-binary-file "/tmp/test.bin")
721 (and (equalp vec (gsl-array:gsl->lisp-vector v1))
722 (equalp vec (gsl-array:gsl->lisp-vector v2))))))))
723
724 (deftest "read-write-binary-complex-single-float" :category +vector+
725 :test-fn
726 #'(lambda ()
727 (let ((vec (vector (complex 1.0 1.0) (complex 2.0 2.0)
728 (complex 3.0 3.0) (complex 4.0 4.0)
729 (complex 5.0 5.0))))
730 (gsl-array:with-vector
731 (v1 5 :element-type '(complex (single-float))
732 :initial-contents vec)
733 (gsl-array:write-to-binary-file "/tmp/test.bin" v1)
734 (gsl-array:with-vector
735 (v2 5 :element-type '(complex (single-float))
736 :from-binary-file "/tmp/test.bin")
737 (and (equalp vec (gsl-array:gsl->lisp-vector v1))
738 (equalp vec (gsl-array:gsl->lisp-vector v2))))))))
739
740 ;; ----------------------------------------------------------------------
741
742 (deftest "copy-double-float" :category +vector+
743 :test-fn
744 #'(lambda ()
745 (let ((vec (vector 1.0d0 2.0d0 3.0d0 4.0d0 5.0d0))
746 (v2)
747 (res))
748 (gsl-array:with-vector
749 (v1 5 :element-type 'double-float :initial-contents vec)
750 (setq v2 (gsl-array:copy v1))
751 (setq res (equalp (gsl-array:gsl->lisp-vector v1)
752 (gsl-array:gsl->lisp-vector v2)))
753 (gsl-array:free v2))
754 res)))
755
756 (deftest "copy-single-float" :category +vector+
757 :test-fn
758 #'(lambda ()
759 (let ((vec (vector 1.0 2.0 3.0 4.0 5.0)))
760 (gsl-array:with-vector
761 (v1 5 :element-type 'single-float :initial-contents vec)
762 (gsl-array:with-vector-copy (v2 v1)
763 (and (equalp vec (gsl-array:gsl->lisp-vector v1))
764 (equalp vec (gsl-array:gsl->lisp-vector v2))))))))
765
766 (deftest "copy-integer" :category +vector+
767 :test-fn
768 #'(lambda ()
769 (let ((vec (vector 1 2 3 4 5)))
770 (gsl-array:with-vector
771 (v1 5 :element-type 'integer :initial-contents vec)
772 (gsl-array:with-vector-copy (v2 v1)
773 (and (equalp vec (gsl-array:gsl->lisp-vector v1))
774 (equalp vec (gsl-array:gsl->lisp-vector v2))))))))
775
776 (deftest "copy-complex-double-float" :category +vector+
777 :test-fn
778 #'(lambda ()
779 (let ((vec (vector (complex 1.0d0 1.0d0) (complex 2.0d0 2.0d0)
780 (complex 3.0d0 3.0d0) (complex 4.0d0 4.0d0)
781 (complex 5.0d0 5.0d0))))
782 (gsl-array:with-vector
783 (v1 5 :element-type '(complex (double-float))
784 :initial-contents vec)
785 (gsl-array:with-vector-copy (v2 v1)
786 (and (equalp vec (gsl-array:gsl->lisp-vector v1))
787 (equalp vec (gsl-array:gsl->lisp-vector v2))))))))
788
789 (deftest "copy-complex-single-float" :category +vector+
790 :test-fn
791 #'(lambda ()
792 (let ((vec (vector (complex 1.0 1.0) (complex 2.0 2.0)
793 (complex 3.0 3.0) (complex 4.0 4.0)
794 (complex 5.0 5.0))))
795 (gsl-array:with-vector
796 (v1 5 :element-type '(complex (single-float))
797 :initial-contents vec)
798 (gsl-array:with-vector-copy (v2 v1)
799 (and (equalp vec (gsl-array:gsl->lisp-vector v1))
800 (equalp vec (gsl-array:gsl->lisp-vector v2))))))))
801
802
803 ;; ----------------------------------------------------------------------
804
805 (deftest "swap-double-float" :category +vector+
806 :test-fn
807 #'(lambda ()
808 (let* ((vec-1 (vector 1.0d0 2.0d0 3.0d0 4.0d0 5.0d0))
809 (vec-2 (reverse vec-1)))
810 (gsl-array:with-vector
811 (v1 5 :element-type 'double-float :initial-contents vec-1)
812 (gsl-array:with-vector
813 (v2 5 :element-type 'double-float :initial-contents vec-2)
814 (gsl-array:swap v1 v2)
815 (and (equalp vec-2 (gsl-array:gsl->lisp-vector v1))
816 (equalp vec-1 (gsl-array:gsl->lisp-vector v2))))))))
817
818 (deftest "swap-single-float" :category +vector+
819 :test-fn
820 #'(lambda ()
821 (let* ((vec-1 (vector 1.0 2.0 3.0 4.0 5.0))
822 (vec-2 (reverse vec-1)))
823 (gsl-array:with-vector
824 (v1 5 :element-type 'single-float :initial-contents vec-1)
825 (gsl-array:with-vector
826 (v2 5 :element-type 'single-float :initial-contents vec-2)
827 (gsl-array:swap v1 v2)
828 (and (equalp vec-2 (gsl-array:gsl->lisp-vector v1))
829 (equalp vec-1 (gsl-array:gsl->lisp-vector v2))))))))
830
831 (deftest "swap-integer" :category +vector+
832 :test-fn
833 #'(lambda ()
834 (let* ((vec-1 (vector 1 2 3 4 5))
835 (vec-2 (reverse vec-1)))
836 (gsl-array:with-vector
837 (v1 5 :element-type 'integer :initial-contents vec-1)
838 (gsl-array:with-vector
839 (v2 5 :element-type 'integer :initial-contents vec-2)
840 (gsl-array:swap v1 v2)
841 (and (equalp vec-2 (gsl-array:gsl->lisp-vector v1))
842 (equalp vec-1 (gsl-array:gsl->lisp-vector v2))))))))
843
844 (deftest "swap-complex-double-float" :category +vector+
845 :test-fn
846 #'(lambda ()
847 (let* ((vec-1 (vector (complex 1.0d0 1.0d0) (complex 2.0d0 2.0d0)
848 (complex 3.0d0 3.0d0) (complex 4.0d0 4.0d0)
849 (complex 5.0d0 5.0d0)))
850 (vec-2 (reverse vec-1)))
851 (gsl-array:with-vector
852 (v1 5 :element-type '(complex (double-float))
853 :initial-contents vec-1)
854 (gsl-array:with-vector
855 (v2 5 :element-type '(complex (double-float))
856 :initial-contents vec-2)
857 (gsl-array:swap v1 v2)
858 (and (equalp vec-2 (gsl-array:gsl->lisp-vector v1))
859 (equalp vec-1 (gsl-array:gsl->lisp-vector v2))))))))
860
861 (deftest "swap-complex-single-float" :category +vector+
862 :test-fn
863 #'(lambda ()
864 (let* ((vec-1 (vector (complex 1.0 1.0) (complex 2.0 2.0)
865 (complex 3.0 3.0) (complex 4.0 4.0)
866 (complex 5.0 5.0)))
867 (vec-2 (reverse vec-1)))
868 (gsl-array:with-vector
869 (v1 5 :element-type '(complex (single-float))
870 :initial-contents vec-1)
871 (gsl-array:with-vector
872 (v2 5 :element-type '(complex (single-float))
873 :initial-contents vec-2)
874 (gsl-array:swap v1 v2)
875 (and (equalp vec-2 (gsl-array:gsl->lisp-vector v1))
876 (equalp vec-1 (gsl-array:gsl->lisp-vector v2))))))))
877
878 ;; ----------------------------------------------------------------------
879
880 (deftest "swap-elements-double-float" :category +vector+
881 :test-fn
882 #'(lambda ()
883 (let ((vec-1 (vector 1.0d0 2.0d0 3.0d0 4.0d0 5.0d0))
884 (vec-2 (vector 1.0d0 2.0d0 4.0d0 3.0d0 5.0d0)))
885 (gsl-array:with-vector
886 (v1 5 :element-type 'double-float :initial-contents vec-1)
887 (gsl-array:swap-elements v1 2 3)
888 (equalp vec-2 (gsl-array:gsl->lisp-vector v1))))))
889
890 (deftest "swap-elements-single-float" :category +vector+
891 :test-fn
892 #'(lambda ()
893 (let ((vec-1 (vector 1.0 2.0 3.0 4.0 5.0))
894 (vec-2 (vector 1.0 2.0 4.0 3.0 5.0)))
895 (gsl-array:with-vector
896 (v1 5 :element-type 'single-float :initial-contents vec-1)
897 (gsl-array:swap-elements v1 2 3)
898 (equalp vec-2 (gsl-array:gsl->lisp-vector v1))))))
899
900 (deftest "swap-elements-integer" :category +vector+
901 :test-fn
902 #'(lambda ()
903 (let ((vec-1 (vector 1 2 3 4 5))
904 (vec-2 (vector 1 2 4 3 5)))
905 (gsl-array:with-vector
906 (v1 5 :element-type 'integer :initial-contents vec-1)
907 (gsl-array:swap-elements v1 2 3)
908 (equalp vec-2 (gsl-array:gsl->lisp-vector v1))))))
909
910 (deftest "swap-elements-complex-double-float" :category +vector+
911 :test-fn
912 #'(lambda ()
913 (let ((vec-1 (vector (complex 1.0d0 1.0d0) (complex 2.0d0 2.0d0)
914 (complex 3.0d0 3.0d0) (complex 4.0d0 4.0d0)
915 (complex 5.0d0 5.0d0)))
916 (vec-2 (vector (complex 1.0d0 1.0d0) (complex 2.0d0 2.0d0)
917 (complex 4.0d0 4.0d0) (complex 3.0d0 3.0d0)
918 (complex 5.0d0 5.0d0))))
919 (gsl-array:with-vector
920 (v1 5 :element-type '(complex (double-float))
921 :initial-contents vec-1)
922 (gsl-array:swap-elements v1 2 3)
923 (equalp vec-2 (gsl-array:gsl->lisp-vector v1))))))
924
925 (deftest "swap-elements-complex-single-float" :category +vector+
926 :test-fn
927 #'(lambda ()
928 (let ((vec-1 (vector (complex 1.0 1.0) (complex 2.0 2.0)
929 (complex 3.0 3.0) (complex 4.0 4.0)
930 (complex 5.0 5.0)))
931 (vec-2 (vector (complex 1.0 1.0) (complex 2.0 2.0)
932 (complex 4.0 4.0) (complex 3.0 3.0)
933 (complex 5.0 5.0))))
934 (gsl-array:with-vector
935 (v1 5 :element-type '(complex (single-float))
936 :initial-contents vec-1)
937 (equalp vec-2 (gsl-array:gsl->lisp-vector
938 (gsl-array:swap-elements v1 2 3)))))))
939
940 ;; ----------------------------------------------------------------------
941
942 (deftest "add-double-float" :category +vector+
943 :test-fn
944 #'(lambda ()
945 (let ((vec-1 (vector 1.0d0 2.0d0 3.0d0 4.0d0 5.0d0))
946 (vec-2 (vector 2.0d0 4.0d0 6.0d0 8.0d0 10.0d0)))
947 (gsl-array:with-vector
948 (v1 5 :element-type 'double-float :initial-contents vec-1)
949 (gsl-array:with-vector
950 (v2 5 :element-type 'double-float :initial-contents vec-1)
951 (gsl-array:add v1 v2)
952 (equalp vec-2 (gsl-array:gsl->lisp-vector v1)))))))
953
954 (deftest "add-single-float" :category +vector+
955 :test-fn
956 #'(lambda ()
957 (let ((vec-1 (vector 1.0 2.0 3.0 4.0 5.0))
958 (vec-2 (vector 2.0 4.0 6.0 8.0 10.0)))
959 (gsl-array:with-vector
960 (v1 5 :element-type 'single-float :initial-contents vec-1)
961 (gsl-array:with-vector
962 (v2 5 :element-type 'single-float :initial-contents vec-1)
963 (gsl-array:add v1 v2)
964 (equalp vec-2 (gsl-array:gsl->lisp-vector v1)))))))
965
966 (deftest "add-integer" :category +vector+
967 :test-fn
968 #'(lambda ()
969 (let ((vec-1 (vector 1 2 3 4 5))
970 (vec-2 (vector 2 4 6 8 10)))
971 (gsl-array:with-vector
972 (v1 5 :element-type 'integer :initial-contents vec-1)
973 (gsl-array:with-vector
974 (v2 5 :element-type 'integer :initial-contents vec-1)
975 (gsl-array:add v1 v2)
976 (equalp vec-2 (gsl-array:gsl->lisp-vector v1)))))))
977
978
979 ;; ----------------------------------------------------------------------
980
981 (deftest "sub-double-float" :category +vector+
982 :test-fn
983 #'(lambda ()
984 (let ((vec-1 (vector 1.0d0 2.0d0 3.0d0 4.0d0 5.0d0))
985 (vec-2 (vector 0.0d0 0.0d0 0.0d0 0.0d0 0.0d0)))
986 (gsl-array:with-vector
987 (v1 5 :element-type 'double-float :initial-contents vec-1)
988 (gsl-array:with-vector
989 (v2 5 :element-type 'double-float :initial-contents vec-1)
990 (gsl-array:sub v1 v2)
991 (equalp vec-2 (gsl-array:gsl->lisp-vector v1)))))))
992
993 (deftest "sub-single-float" :category +vector+
994 :test-fn
995 #'(lambda ()
996 (let ((vec-1 (vector 1.0 2.0 3.0 4.0 5.0))
997 (vec-2 (vector 0.0 0.0 0.0 0.0 0.0)))
998 (gsl-array:with-vector
999 (v1 5 :element-type 'single-float :initial-contents vec-1)
1000 (gsl-array:with-vector
1001 (v2 5 :element-type 'single-float :initial-contents vec-1)
1002 (gsl-array:sub v1 v2)
1003 (equalp vec-2 (gsl-array:gsl->lisp-vector v1)))))))
1004
1005 (deftest "sub-integer" :category +vector+
1006 :test-fn
1007 #'(lambda ()
1008 (let ((vec-1 (vector 1 2 3 4 5))
1009 (vec-2 (vector 0 0 0 0 0)))
1010 (gsl-array:with-vector
1011 (v1 5 :element-type 'integer :initial-contents vec-1)
1012 (gsl-array:with-vector
1013 (v2 5 :element-type 'integer :initial-contents vec-1)
1014 (gsl-array:sub v1 v2)
1015 (equalp vec-2 (gsl-array:gsl->lisp-vector v1)))))))
1016
1017 ;; ----------------------------------------------------------------------
1018
1019 (deftest "mul-double-float" :category +vector+
1020 :test-fn
1021 #'(lambda ()
1022 (let ((vec-1 (vector 1.0d0 2.0d0 3.0d0 4.0d0 5.0d0))
1023 (vec-2 (vector 1.0d0 4.0d0 9.0d0 16.0d0 25.0d0)))
1024 (gsl-array:with-vector
1025 (v1 5 :element-type 'double-float :initial-contents vec-1)
1026 (gsl-array:with-vector
1027 (v2 5 :element-type 'double-float :initial-contents vec-1)
1028 (gsl-array:mul v1 v2)
1029 (equalp vec-2 (gsl-array:gsl->lisp-vector v1)))))))
1030
1031 (deftest "mul-single-float" :category +vector+
1032 :test-fn
1033 #'(lambda ()
1034 (let ((vec-1 (vector 1.0 2.0 3.0 4.0 5.0))
1035 (vec-2 (vector 1.0 4.0 9.0 16.0 25.0)))
1036 (gsl-array:with-vector
1037 (v1 5 :element-type 'single-float :initial-contents vec-1)
1038 (gsl-array:with-vector
1039 (v2 5 :element-type 'single-float :initial-contents vec-1)
1040 (gsl-array:mul v1 v2)
1041 (equalp vec-2 (gsl-array:gsl->lisp-vector v1)))))))
1042
1043 (deftest "mul-integer" :category +vector+
1044 :test-fn
1045 #'(lambda ()
1046 (let ((vec-1 (vector 1 2 3 4 5))
1047 (vec-2 (vector 1 4 9 16 25)))
1048 (gsl-array:with-vector
1049 (v1 5 :element-type 'integer :initial-contents vec-1)
1050 (gsl-array:with-vector
1051 (v2 5 :element-type 'integer :initial-contents vec-1)
1052 (gsl-array:mul v1 v2)
1053 (equalp vec-2 (gsl-array:gsl->lisp-vector v1)))))))
1054
1055 ;; ----------------------------------------------------------------------
1056
1057 (deftest "div-double-float" :category +vector+
1058 :test-fn
1059 #'(lambda ()
1060 (let ((vec-1 (vector 1.0d0 2.0d0 3.0d0 4.0d0 5.0d0))
1061 (vec-2 (vector 1.0d0 1.0d0 1.0d0 1.0d0 1.0d0)))
1062 (gsl-array:with-vector
1063 (v1 5 :element-type 'double-float :initial-contents vec-1)
1064 (gsl-array:with-vector
1065 (v2 5 :element-type 'double-float :initial-contents vec-1)
1066 (gsl-array:div v1 v2)
1067 (equalp vec-2 (gsl-array:gsl->lisp-vector v1)))))))
1068
1069 (deftest "div-single-float" :category +vector+
1070 :test-fn
1071 #'(lambda ()
1072 (let ((vec-1 (vector 1.0 2.0 3.0 4.0 5.0))
1073 (vec-2 (vector 1.0 1.0 1.0 1.0 1.0)))
1074 (gsl-array:with-vector
1075 (v1 5 :element-type 'single-float :initial-contents vec-1)
1076 (gsl-array:with-vector
1077 (v2 5 :element-type 'single-float :initial-contents vec-1)
1078 (gsl-array:div v1 v2)
1079 (equalp vec-2 (gsl-array:gsl->lisp-vector v1)))))))
1080
1081 (deftest "div-integer" :category +vector+
1082 :test-fn
1083 #'(lambda ()
1084 (let ((vec-1 (vector 1 2 3 4 5))
1085 (vec-2 (vector 1 1 1 1 1)))
1086 (gsl-array:with-vector
1087 (v1 5 :element-type 'integer :initial-contents vec-1)
1088 (gsl-array:with-vector
1089 (v2 5 :element-type 'integer :initial-contents vec-1)
1090 (gsl-array:div v1 v2)
1091 (equalp vec-2 (gsl-array:gsl->lisp-vector v1)))))))
1092
1093
1094 ;; ----------------------------------------------------------------------
1095
1096 (deftest "scale-double-float" :category +vector+
1097 :test-fn
1098 #'(lambda ()
1099 (let ((vec-1 (vector 1.0d0 2.0d0 3.0d0 4.0d0 5.0d0))
1100 (vec-2 (vector 10.0d0 20.0d0 30.0d0 40.0d0 50.0d0)))
1101 (gsl-array:with-vector
1102 (v1 5 :element-type 'double-float :initial-contents vec-1)
1103 (gsl-array:scale v1 10.0d0)
1104 (equalp vec-2 (gsl-array:gsl->lisp-vector v1))))))
1105
1106 (deftest "scale-single-float" :category +vector+
1107 :test-fn
1108 #'(lambda ()
1109 (let ((vec-1 (vector 1.0 2.0 3.0 4.0 5.0))
1110 (vec-2 (vector 10.0 20.0 30.0 40.0 50.0)))
1111 (gsl-array:with-vector
1112 (v1 5 :element-type 'single-float :initial-contents vec-1)
1113 (gsl-array:scale v1 10.0)
1114 (equalp vec-2 (gsl-array:gsl->lisp-vector v1))))))
1115
1116 (deftest "scale-integer" :category +vector+
1117 :test-fn
1118 #'(lambda ()
1119 (let ((vec-1 (vector 1 2 3 4 5))
1120 (vec-2 (vector 10 20 30 40 50)))
1121 (gsl-array:with-vector
1122 (v1 5 :element-type 'integer :initial-contents vec-1)
1123 (gsl-array:scale v1 10)
1124 (equalp vec-2 (gsl-array:gsl->lisp-vector v1))))))
1125
1126
1127 ;; ----------------------------------------------------------------------
1128
1129 (deftest "add-constant-double-float" :category +vector+
1130 :test-fn
1131 #'(lambda ()
1132 (let ((vec-1 (vector 1.0d0 2.0d0 3.0d0 4.0d0 5.0d0))
1133 (vec-2 (vector 11.0d0 12.0d0 13.0d0 14.0d0 15.0d0)))
1134 (gsl-array:with-vector
1135 (v1 5 :element-type 'double-float :initial-contents vec-1)
1136 (gsl-array:add-constant v1 10.0d0)
1137 (equalp vec-2 (gsl-array:gsl->lisp-vector v1))))))
1138
1139 (deftest "add-constant-single-float" :category +vector+
1140 :test-fn
1141 #'(lambda ()
1142 (let ((vec-1 (vector 1.0 2.0 3.0 4.0 5.0))
1143 (vec-2 (vector 11.0 12.0 13.0 14.0 15.0)))
1144 (gsl-array:with-vector
1145 (v1 5 :element-type 'single-float :initial-contents vec-1)
1146 (gsl-array:add-constant v1 10.0)
1147 (equalp vec-2 (gsl-array:gsl->lisp-vector v1))))))
1148
1149 (deftest "add-constant-integer" :category +vector+
1150 :test-fn
1151 #'(lambda ()
1152 (let ((vec-1 (vector 1 2 3 4 5))
1153 (vec-2 (vector 11 12 13 14 15)))
1154 (gsl-array:with-vector
1155 (v1 5 :element-type 'integer :initial-contents vec-1)
1156 (gsl-array:add-constant v1 10)
1157 (equalp vec-2 (gsl-array:gsl->lisp-vector v1))))))
1158
1159 ;; ----------------------------------------------------------------------
1160
1161 (deftest "max-value-double-float" :category +vector+
1162 :test-fn
1163 #'(lambda ()
1164 (let ((vec-1 (vector 4.0d0 5.0d0 1.0d0 2.0d0 3.0d0))
1165 (max-val 5.0d0))
1166 (gsl-array:with-vector
1167 (v1 5 :element-type 'double-float :initial-contents vec-1)
1168 (= max-val (gsl-array:max-value v1))))))
1169
1170 (deftest "max-value-single-float" :category +vector+
1171 :test-fn
1172 #'(lambda ()
1173 (let ((vec-1 (vector 4.0 5.0 1.0 2.0 3.0))
1174 (max-val 5.0))
1175 (gsl-array:with-vector
1176 (v1 5 :element-type 'single-float :initial-contents vec-1)
1177 (= max-val (gsl-array:max-value v1))))))
1178
1179 (deftest "max-value-integer" :category +vector+
1180 :test-fn
1181 #'(lambda ()
1182 (let ((vec-1 (vector 4 5 1 2 3))
1183 (max-val 5))
1184 (gsl-array:with-vector
1185 (v1 5 :element-type 'integer :initial-contents vec-1)
1186 (= max-val (gsl-array:max-value v1))))))
1187
1188 ;; ----------------------------------------------------------------------
1189
1190 (deftest "min-value-double-float" :category +vector+
1191 :test-fn
1192 #'(lambda ()
1193 (let ((vec-1 (vector 4.0d0 5.0d0 1.0d0 2.0d0 3.0d0))
1194 (min-val 1.0d0))
1195 (gsl-array:with-vector
1196 (v1 5 :element-type 'double-float :initial-contents vec-1)
1197 (= min-val (gsl-array:min-value v1))))))
1198
1199 (deftest "min-value-single-float" :category +vector+
1200 :test-fn
1201 #'(lambda ()
1202 (let ((vec-1 (vector 4.0 5.0 1.0 2.0 3.0))
1203 (min-val 1.0))
1204 (gsl-array:with-vector
1205 (v1 5 :element-type 'single-float :initial-contents vec-1)
1206 (= min-val (gsl-array:min-value v1))))))
1207
1208 (deftest "min-value-integer" :category +vector+
1209 :test-fn
1210 #'(lambda ()
1211 (let ((vec-1 (vector 4 5 1 2 3))
1212 (min-val 1))
1213 (gsl-array:with-vector
1214 (v1 5 :element-type 'integer :initial-contents vec-1)
1215 (= min-val (gsl-array:min-value v1))))))
1216
1217 ;; ----------------------------------------------------------------------
1218
1219 (deftest "max-index-double-float" :category +vector+
1220 :test-fn
1221 #'(lambda ()
1222 (let ((vec-1 (vector 4.0d0 5.0d0 1.0d0 2.0d0 3.0d0))
1223 (max-idx 1))
1224 (gsl-array:with-vector
1225 (v1 5 :element-type 'double-float :initial-contents vec-1)
1226 (= max-idx (gsl-array:max-index v1))))))
1227
1228 (deftest "max-index-single-float" :category +vector+
1229 :test-fn
1230 #'(lambda ()
1231 (let ((vec-1 (vector 4.0 5.0 1.0 2.0 3.0))
1232 (max-idx 1))
1233 (gsl-array:with-vector
1234 (v1 5 :element-type 'single-float :initial-contents vec-1)
1235 (= max-idx (gsl-array:max-index v1))))))
1236
1237 (deftest "max-index-integer" :category +vector+
1238 :test-fn
1239 #'(lambda ()
1240 (let ((vec-1 (vector 4 5 1 2 3))
1241 (max-idx 1))
1242 (gsl-array:with-vector
1243 (v1 5 :element-type 'integer :initial-contents vec-1)
1244 (= max-idx (gsl-array:max-index v1))))))
1245
1246 ;; ----------------------------------------------------------------------
1247
1248 (deftest "min-index-double-float" :category +vector+
1249 :test-fn
1250 #'(lambda ()
1251 (let ((vec-1 (vector 4.0d0 5.0d0 1.0d0 2.0d0 3.0d0))
1252 (min-idx 2))
1253 (gsl-array:with-vector
1254 (v1 5 :element-type 'double-float :initial-contents vec-1)
1255 (= min-idx (gsl-array:min-index v1))))))
1256
1257 (deftest "min-index-single-float" :category +vector+
1258 :test-fn
1259 #'(lambda ()
1260 (let ((vec-1 (vector 4.0 5.0 1.0 2.0 3.0))
1261 (min-idx 2))
1262 (gsl-array:with-vector
1263 (v1 5 :element-type 'single-float :initial-contents vec-1)
1264 (= min-idx (gsl-array:min-index v1))))))
1265
1266 (deftest "min-index-integer" :category +vector+
1267 :test-fn
1268 #'(lambda ()
1269 (let ((vec-1 (vector 4 5 1 2 3))
1270 (min-idx 2))
1271 (gsl-array:with-vector
1272 (v1 5 :element-type 'integer :initial-contents vec-1)
1273 (= min-idx (gsl-array:min-index v1))))))
1274
1275 ;; ----------------------------------------------------------------------
1276
1277 (deftest "min-max-indicies-double-float" :category +vector+
1278 :test-fn
1279 #'(lambda ()
1280 (let ((vec-1 (vector 4.0d0 5.0d0 1.0d0 2.0d0 3.0d0))
1281 (min-max-idx '(2 1)))
1282 (gsl-array:with-vector
1283 (v1 5 :element-type 'double-float :initial-contents vec-1)
1284 (equal min-max-idx (gsl-array:min-max-indicies v1))))))
1285
1286 (deftest "min-max-indicies-single-float" :category +vector+
1287 :test-fn
1288 #'(lambda ()
1289 (let ((vec-1 (vector 4.0 5.0 1.0 2.0 3.0))
1290 (min-max-idx '(2 1)))
1291 (gsl-array:with-vector
1292 (v1 5 :element-type 'single-float :initial-contents vec-1)
1293 (equal min-max-idx (gsl-array:min-max-indicies v1))))))
1294
1295 (deftest "min-max-indicies-integer" :category +vector+
1296 :test-fn
1297 #'(lambda ()
1298 (let ((vec-1 (vector 4 5 1 2 3))
1299 (min-max-idx '(2 1)))
1300 (gsl-array:with-vector
1301 (v1 5 :element-type 'integer :initial-contents vec-1)
1302 (equal min-max-idx (gsl-array:min-max-indicies v1))))))
1303
1304 ;; ----------------------------------------------------------------------
1305
1306 (deftest "min-max-values-double-float" :category +vector+
1307 :test-fn
1308 #'(lambda ()
1309 (let ((vec-1 (vector 4.0d0 5.0d0 1.0d0 2.0d0 3.0d0))
1310 (min-max-val '(1.0d0 5.0d0)))
1311 (gsl-array:with-vector
1312 (v1 5 :element-type 'double-float :initial-contents vec-1)
1313 (equal min-max-val (gsl-array:min-max-values v1))))))
1314
1315 (deftest "min-max-values-single-float" :category +vector+
1316 :test-fn
1317 #'(lambda ()
1318 (let ((vec-1 (vector 4.0 5.0 1.0 2.0 3.0))
1319 (min-max-val '(1.0 5.0)))
1320 (gsl-array:with-vector
1321 (v1 5 :element-type 'single-float :initial-contents vec-1)
1322 (equal min-max-val (gsl-array:min-max-values v1))))))
1323
1324 (deftest "min-max-values-integer" :category +vector+
1325 :test-fn
1326 #'(lambda ()
1327 (let ((vec-1 (vector 4 5 1 2 3))
1328 (min-max-val '(1 5)))
1329 (gsl-array:with-vector
1330 (v1 5 :element-type 'integer :initial-contents vec-1)
1331 (equal min-max-val (gsl-array:min-max-values v1))))))
1332

  ViewVC Help
Powered by ViewVC 1.1.5