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
|
;;;; -*- Mode: Lisp; indent-tabs-mode: nil -*-
;;;
;;; --- FiveAM Tests
;;;
(defpackage :static-vectors/test
(:use #:cl #:static-vectors #:fiveam))
(in-package :static-vectors/test)
(in-suite* :static-vectors)
(test (make-static-vector.defaults
:compile-at :definition-time)
(let ((v (make-static-vector 5)))
(is (= 5 (length v)))
(is (equal (array-element-type v)
(upgraded-array-element-type
'(unsigned-byte 8))))))
(test (make-static-vector.element-type.non-literal
:compile-at :definition-time)
(let* ((element-type '(unsigned-byte 16))
(v (make-static-vector 5 :element-type element-type)))
(is (= 5 (length v)))
(is (equal (array-element-type v)
(upgraded-array-element-type
'(unsigned-byte 16))))))
(test (make-static-vector.defaults.notinline
:compile-at :definition-time)
(locally
(declare (notinline make-static-vector))
(let ((v (make-static-vector 5)))
(is (equal 5 (length v))))))
(test (make-static-vector.initial-element.notinline
:compile-at :definition-time)
(locally
(declare (notinline make-static-vector))
(let ((v (make-static-vector 5 :initial-element 3)))
(is (equal 5 (length v)))
(is (not (find 3 v :test-not #'=))))))
(test (make-static-vector.initial-contents.notinline
:compile-at :definition-time)
(locally
(declare (notinline make-static-vector))
(let ((v (make-static-vector 5 :initial-contents '(1 2 3 4 5))))
(is (equal 5 (length v)))
(is (not (mismatch v '(1 2 3 4 5)))))))
(test (with-static-vector.defaults
:compile-at :definition-time)
(with-static-vector (v 5)
(is (= 5 (length v)))
(is (equal (array-element-type v)
(upgraded-array-element-type
'(unsigned-byte 8))))))
(test (with-static-vector.element-type.literal
:compile-at :definition-time)
(with-static-vector (v 3 :element-type '(unsigned-byte 16))
(is (= 3 (length v)))
(is (equal (array-element-type v)
(upgraded-array-element-type
'(unsigned-byte 16))))))
(test (with-static-vector.element-type.non-literal
:compile-at :definition-time)
(let ((element-type '(unsigned-byte 16)))
(with-static-vector (v 3 :element-type element-type)
(is (= 3 (length v)))
(is (equal (array-element-type v)
(upgraded-array-element-type
'(unsigned-byte 16)))))))
(test (with-static-vector.initial-element.non-literal
:compile-at :definition-time)
(let ((element-type '(unsigned-byte 16))
(initial-element 5))
(with-static-vector (v 3 :element-type element-type
:initial-element initial-element)
(is (= 3 (length v)))
(is (equal (array-element-type v)
(upgraded-array-element-type
'(unsigned-byte 16))))
(is (= 5 (aref v 0))))))
(test (with-static-vector.initial-contents.non-literal
:compile-at :definition-time)
(let ((element-type '(unsigned-byte 16))
(initial-contents '(1 2 3)))
(with-static-vector (v 3 :element-type element-type
:initial-contents initial-contents)
(is (= 3 (length v)))
(is (equal (array-element-type v)
(upgraded-array-element-type
'(unsigned-byte 16))))
(is (every #'= v initial-contents)))))
(deftype eltype ()
'(unsigned-byte 32))
(test (with-static-vector.element-type.deftype
:compile-at :definition-time)
(with-static-vector (v 3 :element-type 'eltype)
(is (= 3 (length v)))
(is (equal (array-element-type v)
(upgraded-array-element-type
'(unsigned-byte 32))))))
(test (with-static-vector.initial-element
:compile-at :definition-time)
(with-static-vector (v 3 :initial-element 7)
(is (= 3 (length v)))
(is (equalp v #(7 7 7)))))
(test (with-static-vector.initial-contents
:compile-at :definition-time)
(with-static-vector (v 3 :initial-contents '(3 14 29))
(is (= 3 (length v)))
(is (equalp v #(3 14 29)))))
(test (with-static-vectors.initialization
:compile-at :definition-time)
(with-static-vectors ((v1 3 :initial-element 7)
(v2 5 :initial-contents '(1 2 3 4 5)))
(is (equalp v1 #(7 7 7)))
(is (equalp v2 #(1 2 3 4 5)))))
|