-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patharray-displacement.lsp
138 lines (118 loc) · 4.13 KB
/
array-displacement.lsp
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
;-*- Mode: Lisp -*-
;;;; Author: Paul Dietz
;;;; Created: Tue Jan 21 06:20:51 2003
;;;; Contains: Tests for ARRAY-DISPLACEMENT
(in-package :cl-test)
;;; The tests in make-array.lsp also test array-displacement
;;; The standard is contradictory about whether arrays created with
;;; :displaced-to NIL should return NIL as their primary value or
;;; not. I will assume (as per Kent Pitman's comment on comp.lang.lisp)
;;; that an implementation is free to implement all arrays as actually
;;; displaced. Therefore, I've omitted all the tests of not-expressly
;;; displaced arrays.
;;; Behavior on expressly displaced arrays
(deftest array-displacement.7
(let* ((a (make-array '(10)))
(b (make-array '(10) :displaced-to a)))
(multiple-value-bind* (dt disp)
(array-displacement b)
(and (eqt a dt)
(eqlt disp 0))))
t)
(deftest array-displacement.8
(let* ((a (make-array '(10)))
(b (make-array '(5) :displaced-to a :displaced-index-offset 2)))
(multiple-value-bind* (dt disp)
(array-displacement b)
(and (eqt a dt)
(eqlt disp 2))))
t)
(deftest array-displacement.9
(let* ((a (make-array '(10) :element-type 'base-char))
(b (make-array '(5) :displaced-to a :displaced-index-offset 2
:element-type 'base-char)))
(multiple-value-bind* (dt disp)
(array-displacement b)
(and (eqt a dt)
(eqlt disp 2))))
t)
(deftest array-displacement.10
(let* ((a (make-array '(10) :element-type 'base-char))
(b (make-array '(5) :displaced-to a
:element-type 'base-char)))
(multiple-value-bind* (dt disp)
(array-displacement b)
(and (eqt a dt)
(eqlt disp 0))))
t)
(deftest array-displacement.11
(let* ((a (make-array '(10) :element-type 'bit))
(b (make-array '(5) :displaced-to a :displaced-index-offset 2
:element-type 'bit)))
(multiple-value-bind* (dt disp)
(array-displacement b)
(and (eqt a dt)
(eqlt disp 2))))
t)
(deftest array-displacement.12
(let* ((a (make-array '(10) :element-type 'bit))
(b (make-array '(5) :displaced-to a
:element-type 'bit)))
(multiple-value-bind* (dt disp)
(array-displacement b)
(and (eqt a dt)
(eqlt disp 0))))
t)
(deftest array-displacement.13
(let* ((a (make-array '(10) :element-type '(integer 0 255)))
(b (make-array '(5) :displaced-to a :displaced-index-offset 2
:element-type '(integer 0 255))))
(multiple-value-bind* (dt disp)
(array-displacement b)
(and (eqt a dt)
(eqlt disp 2))))
t)
(deftest array-displacement.14
(let* ((a (make-array '(10) :element-type '(integer 0 255)))
(b (make-array '(5) :displaced-to a
:element-type '(integer 0 255))))
(multiple-value-bind* (dt disp)
(array-displacement b)
(and (eqt a dt)
(eqlt disp 0))))
t)
(deftest array-displacement.15
(let* ((a (make-array '(10) :initial-contents '(a b c d e f g h i j)))
(b (make-array '(5) :displaced-to a :displaced-index-offset 2)))
(macrolet
((%m (z) z))
(multiple-value-bind
(x y)
(array-displacement (expand-in-current-env (%m b)))
(values (eqlt x a) y))))
t 2)
;;; FIXME: Add tests for other kinds of specialized arrays
;;; (character, other integer types, float types, complex types)
(deftest array-displacement.order.1
(let* ((a (make-array '(10)))
(b (make-array '(10) :displaced-to a))
(i 0))
(multiple-value-bind* (dt disp)
(array-displacement (progn (incf i) b))
(and (eql i 1)
(eqt a dt)
(eqlt disp 0))))
t)
;;; Error tests
(deftest array-displacement.error.1
(signals-error (array-displacement) program-error)
t)
(deftest array-displacement.error.2
(signals-error (array-displacement #(a b c) nil) program-error)
t)
(deftest array-displacement.error.3
(check-type-error #'array-displacement #'arrayp)
nil)
(deftest array-displacement.error.4
(signals-type-error x nil (array-displacement x))
t)