OSDN Git Service

cl-jama : import.
[cl-jama/cl-jama.git] / test / utils.lisp
1 ;;; -*- mode: lisp; coding: utf-8 -*-
2
3 (in-package :cl-jama-test)
4
5 (defun make-matrix (x)
6   (let ((m (length x))
7         (n (length (first x))))
8     (make-array (list m n) :initial-contents x)))
9
10 (defun make-vector (x)
11   (make-array (list (length x)) :initial-contents x))
12
13 (defun dump-matrix (x &optional (s *standard-output*) (w 11) (d 4))
14   (loop :for i :from 0 :below (array-dimension x 0)
15         :do (loop :for j :from 0 :below (array-dimension x 1)
16                   :do (format s "~V,VF" w d (aref x i j)))
17             (terpri s))
18   (values))
19
20 (defun dump-vector (x &optional (s *standard-output*))
21   (loop :for i :from 0 :below (array-dimension x 0)
22         :do (format s "~11,4F" (aref x i)))
23   (terpri s)
24   (values))
25
26 (rem-all-tests)
27
28 (deftest make-matrix.1
29     (make-matrix '((1.23 -2.34 3.45) (-4.56 5.67 -6.78)))
30   #2A((1.23 -2.34 3.45) (-4.56 5.67 -6.78)))
31
32 (deftest make-vector.1
33     (make-vector '(9.87 -8.76 7.65))
34   #(9.87 -8.76 7.65))
35
36 (deftest dump-matrix.1
37     (with-output-to-string (os) (dump-matrix #2A((1.23 -2.34 3.45) (-4.56 5.67 -6.78)) os))
38 "     1.2300    -2.3400     3.4500
39     -4.5600     5.6700    -6.7800
40 ")
41
42 (deftest dump-vector.1
43     (with-output-to-string (os) (dump-vector #(9.87 -8.76 7.65) os))
44 "     9.8700    -8.7600     7.6500
45 ")
46
47 (deftest copy-array.1
48     (copy-array #(1.23 -2.34 3.45))
49   #(1.23 -2.34 3.45))
50
51 (deftest copy-array.2
52     (copy-array #2A((-4.56 5.67 -6.78) (7.89 -8.90 9.01)))
53   #2A((-4.56 5.67 -6.78) (7.89 -8.90 9.01)))
54
55 (deftest transpose.1
56     (transpose #2A((-4.56 5.67 -6.78) (7.89 -8.90 9.01)))
57   #2A((-4.56 7.89) (5.67 -8.90) (-6.78 9.01)))
58
59 (deftest multiply.1
60     (multiply #2A((1 1 1) (2 2 2) (3 3 3)) #2A((1 2 3) (1 2 3) (1 2 3)))
61   #2A((3 6 9) (6 12 18) (9 18 27)))
62
63 (do-tests)