File: static-vectors-tests.lisp

package info (click to toggle)
acl2 8.5dfsg-5
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 991,452 kB
  • sloc: lisp: 15,567,759; javascript: 22,820; cpp: 13,929; ansic: 12,092; perl: 7,150; java: 4,405; xml: 3,884; makefile: 3,507; sh: 3,187; ruby: 2,633; ml: 763; python: 746; yacc: 723; awk: 295; csh: 186; php: 171; lex: 154; tcl: 49; asm: 23; haskell: 17
file content (130 lines) | stat: -rw-r--r-- 4,434 bytes parent folder | download | duplicates (3)
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)))))