array-dimension.lsp 1.59 KB
Newer Older
pfdietz's avatar
pfdietz committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Tue Jan 21 06:55:14 2003
;;;; Contains: Tests of ARRAY-DIMENSION

(in-package :cl-test)

;;; array-dimension is also tested by the tests in make-array.lsp

(deftest array-dimension.1
  (array-dimension #(0 1 2 3) 0)
  4)

(deftest array-dimension.2
  (array-dimension "abcdef" 0)
  6)

(deftest array-dimension.3
  (array-dimension #2a((1 2 3 4)(5 6 7 8)) 0)
  2)

(deftest array-dimension.4
  (array-dimension #2a((1 2 3 4)(5 6 7 8)) 1)
  4)

(deftest array-dimension.5
  (let ((a (make-array '(10) :fill-pointer 5)))
    (array-dimension a 0))
  10)

(deftest array-dimension.6
  (let ((a (make-array '(10) :adjustable t)))
    (values
     (array-dimension a 0)
     (progn
       (adjust-array a '(20))
       (array-dimension a 0))))
  10 20)

40 41
(deftest array-dimension.7
  (macrolet ((%m (z) z))
sds's avatar
sds committed
42
            (array-dimension (expand-in-current-env (%m "abc")) 0))
43 44 45 46
  3)

(deftest array-dimension.8
  (macrolet ((%m (z) z))
sds's avatar
sds committed
47 48
            (array-dimension #2a((a b)(c d)(e f))
                             (expand-in-current-env (%m 0))))
49 50
  3)

51 52 53 54
(deftest array-dimension.order.1
  (let ((i 0) a b)
    (values
     (array-dimension (progn (setf a (incf i)) #(a b c d))
sds's avatar
sds committed
55
                      (progn (setf b (incf i)) 0))
56 57 58
     i a b))
  4 2 1 2)

pfdietz's avatar
pfdietz committed
59 60 61
;;; Error tests

(deftest array-dimension.error.1
62 63
  (signals-error (array-dimension) program-error)
  t)
pfdietz's avatar
pfdietz committed
64 65

(deftest array-dimension.error.2
66 67
  (signals-error (array-dimension #(a b c)) program-error)
  t)
pfdietz's avatar
pfdietz committed
68 69

(deftest array-dimension.error.3
70
  (signals-error (array-dimension #(a b c) 0 nil)
sds's avatar
sds committed
71
                 program-error)
72
  t)