1 | (in-package :cl-user) |
---|
2 | |
---|
3 | (let ((element-bits '(8 16 32)) |
---|
4 | (length 16)) |
---|
5 | (prove:plan (* (length element-bits) 3)) |
---|
6 | (dolist (bits element-bits) |
---|
7 | (let* ((type |
---|
8 | `(unsigned-byte ,bits)) |
---|
9 | (exclusive-max |
---|
10 | (expt 2 bits)) |
---|
11 | (max |
---|
12 | (1- exclusive-max))) |
---|
13 | (prove:ok |
---|
14 | (let ((array (make-array length :element-type type :initial-element max))) |
---|
15 | (typep (aref array 0) type)) |
---|
16 | (format nil "Able to make (SIMPLE-ARRAY ~a (~a)) filled with maximum value ~a" |
---|
17 | type length max)) |
---|
18 | (prove:is-condition |
---|
19 | (let ((array (make-array length :element-type type :initial-element -1))) |
---|
20 | (typep (aref array 0) type)) |
---|
21 | 'type-error |
---|
22 | (format nil "Making a (SIMPLE-ARRAY ~a (~a)) filled with -1 signals a type-error" |
---|
23 | type length)) |
---|
24 | (prove:is-condition |
---|
25 | (let ((array (make-array 16 :element-type type :initial-element exclusive-max))) |
---|
26 | (typep (aref array 0) type)) |
---|
27 | 'type-error |
---|
28 | (format nil "Making a (SIMPLE-ARRAY ~a (~a)) filled with ~a signals a type-error" |
---|
29 | type length exclusive-max))))) |
---|
30 | |
---|
31 | ;; pfdietz |
---|
32 | (prove:plan 1) |
---|
33 | (prove:ok |
---|
34 | (handler-case |
---|
35 | (stable-sort (make-array '(0)) '<) |
---|
36 | (t (e) nil)) |
---|
37 | "Able to STABLE-SORT an empty vector.") |
---|
38 | |
---|
39 | ;; nibbles failures |
---|
40 | |
---|
41 | |
---|
42 | (let* ((unspecialized |
---|
43 | #(2025373960 3099658457 3238582529 148439321 |
---|
44 | 3099658456 3238582528 3000000000 1000000000 |
---|
45 | 2000000000 2900000000 2400000000 2800000000 |
---|
46 | 0 1)) |
---|
47 | (array |
---|
48 | (make-array (length unspecialized) |
---|
49 | :element-type '(unsigned-byte 32) |
---|
50 | :initial-contents unspecialized))) |
---|
51 | (prove:plan (length array)) |
---|
52 | (loop :for i :below (length array) |
---|
53 | :doing |
---|
54 | (let ((x0 |
---|
55 | (elt unspecialized i)) |
---|
56 | (x1 |
---|
57 | (elt array i))) |
---|
58 | (prove:ok |
---|
59 | (equal x0 x1) |
---|
60 | (format nil "~a: ~a equals ~a" i x0 x1))))) |
---|
61 | |
---|
62 | ;;;; test :nio-buffer argument |
---|
63 | (prove:plan 1) |
---|
64 | (let* |
---|
65 | ((original |
---|
66 | (make-array 4 :element-type '(unsigned-byte 8) |
---|
67 | :initial-contents '(0 255 128 127))) |
---|
68 | (java-array |
---|
69 | (jnew-array-from-array "byte" original)) |
---|
70 | (nio-buffer |
---|
71 | (#"allocate" 'java.nio.ByteBuffer |
---|
72 | (jarray-length java-array)))) |
---|
73 | (#"put" nio-buffer java-array) |
---|
74 | (let ((result |
---|
75 | (make-array 4 :element-type '(unsigned-byte 8) |
---|
76 | :nio-buffer nio-buffer))) |
---|
77 | (prove:ok |
---|
78 | (equalp original result) |
---|
79 | (format nil "Creating an (unsigned-byte 8) array from nio-buffer where~%~2t~a EQUALP ~a" result result)))) |
---|
80 | |
---|
81 | (prove:plan 1) |
---|
82 | (let* |
---|
83 | ((original |
---|
84 | (make-array 4 :element-type '(unsigned-byte 16) |
---|
85 | :initial-contents `(0 ,(1- (expt 2 16)) 128 127))) |
---|
86 | (java-array |
---|
87 | (jnew-array-from-array "char" original)) |
---|
88 | (nio-buffer |
---|
89 | (#"allocate" 'java.nio.CharBuffer |
---|
90 | (jarray-length java-array)))) |
---|
91 | (#"put" nio-buffer java-array) |
---|
92 | (let ((result |
---|
93 | (make-array 4 :element-type '(unsigned-byte 16) |
---|
94 | :nio-buffer nio-buffer))) |
---|
95 | (prove:ok |
---|
96 | (equalp original result) |
---|
97 | (format nil "Creating an (unsigned-byte 16) array from nio-buffer where~%~2t~a EQUALP ~a" result result)))) |
---|
98 | |
---|
99 | (prove:plan 1) |
---|
100 | (let* |
---|
101 | ((original |
---|
102 | (make-array 4 :element-type '(unsigned-byte 32) |
---|
103 | :initial-contents `(0 ,(1- (expt 2 32)) 128 127))) |
---|
104 | (java-array |
---|
105 | (jnew-array-from-array "int" original)) |
---|
106 | (nio-buffer |
---|
107 | (#"allocate" 'java.nio.IntBuffer |
---|
108 | (jarray-length java-array)))) |
---|
109 | (#"put" nio-buffer java-array) |
---|
110 | (let ((result |
---|
111 | (make-array 4 :element-type '(unsigned-byte 32) |
---|
112 | :nio-buffer nio-buffer))) |
---|
113 | (prove:ok |
---|
114 | (equalp original result) |
---|
115 | (format nil "Creating an (unsigned-byte 8) array from nio-buffer where~%~2t~a EQUALP ~a" result result)))) |
---|
116 | |
---|
117 | (prove:finalize) |
---|
118 | |
---|