decf.lsp 3.79 KB
Newer Older
1 2 3 4 5
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Thu Sep  4 20:50:54 2003
;;;; Contains: Tests of DECF

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

(deftest decf.1
  (let ((x 12))
    (values
     (decf x)
     x))
  11 11)

(deftest decf.2
  (let ((x 3.0s0))
    (values
     (decf x)
     x))
  2.0s0 2.0s0)

(deftest decf.3
  (let ((x 19.0f0))
    (values
     (decf x)
     x))
  18.0f0 18.0f0)

(deftest decf.4
  (let ((x 813.0d0))
    (values
     (decf x)
     x))
  812.0d0 812.0d0)

(deftest decf.5
  (let ((x -17.0l0))
    (values
     (decf x)
     x))
  -18.0l0 -18.0l0)

(deftest decf.6
  (loop for x from 1 to 5
sds's avatar
sds committed
47 48
        collect (let ((y x))
                  (list (decf y) y)))
49 50 51 52
  ((0 0) (1 1) (2 2) (3 3) (4 4)))

(deftest decf.7
  (loop for x in '(3.0s0 3.0f0 3.0d0 3.0l0)
sds's avatar
sds committed
53 54
        collect (let ((y x))
                  (list (decf y) y)))
pfdietz's avatar
pfdietz committed
55
  ((2.0s0 2.0s0) (2.0f0 2.0f0) (2.0d0 2.0d0) (2.0l0 2.0l0)))
56 57 58

(deftest decf.8
  (loop for x in '(3.0s0 3.0f0 3.0d0 3.0f0)
sds's avatar
sds committed
59 60 61 62 63
        for y = (complex x 0)
        for z = (decf y)
        for x1c = (complex (1- x) 0)
        unless (and (eql y z) (eql x1c y))
        collect (list x y z x1c))
64 65 66 67 68 69 70 71 72 73 74 75 76 77
  nil)

(deftest decf.9
  (let ((x most-negative-fixnum))
    (values (decf x) x))
  #.(1- most-negative-fixnum) #.(1- most-negative-fixnum))

(deftest decf.10
  (let ((x (1- most-negative-fixnum)))
    (values (decf x) x))
  #.(- most-negative-fixnum 2) #.(- most-negative-fixnum 2))

(deftest decf.11
  (loop for x in *numbers*
sds's avatar
sds committed
78 79 80 81 82
        unless (let* ((y x)
                      (z (decf y)))
                 (and (eql y (1- x))
                      (eql y z)))
        collect x)
83 84 85 86 87 88
  nil)

;;; Increment by other than 1

(deftest decf.12
  (loop for x in *numbers*
sds's avatar
sds committed
89 90 91
        unless (let* ((y x) (z (decf y 0)))
                 (and (eql x y) (eql y z)))
        collect x)
92 93 94 95
  nil)

(deftest decf.13
  (loop for x in *numbers*
sds's avatar
sds committed
96 97 98 99 100 101 102
        nconc
        (loop for r = (random-from-interval 1000000)
              repeat 100
              when (let* ((y x) (z (decf y r)))
                        (and (not (and (eql (- x r) y) (eql y z)))
                             (list x y r)))
              collect it))
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 139 140 141
  nil)

(deftest decf.14
  (let ((x 1))
    (values (decf x 0.0s0) x))
  1.0s0 1.0s0)

(deftest decf.15
  (let ((x 1))
    (values (decf x 0.0f0) x))
  1.0f0 1.0f0)

(deftest decf.16
  (let ((x 2))
    (values (decf x 0.0d0) x))
  2.0d0 2.0d0)

(deftest decf.17
  (let ((x 10))
    (values (decf x 0.0l0) x))
  10.0l0 10.0l0)

(deftest decf.18
  (let ((x 1))
    (values (decf x #c(0.0s0 10.0s0)) x))
  #c(1.0s0 -10.0s0) #c(1.0s0 -10.0s0))

(deftest decf.19
  (let ((x 1))
    (values (decf x #c(0.0f0 2.0f0)) x))
  #c(1.0f0 -2.0f0) #c(1.0f0 -2.0f0))

(deftest decf.20
  (let ((x 1))
    (values (decf x #c(0.0d0 2.0d0)) x))
  #c(1.0d0 -2.0d0) #c(1.0d0 -2.0d0))

(deftest decf.21
  (let ((x 1))
pfdietz's avatar
pfdietz committed
142
    (values (decf x #c(0.0l0 -2.0l0)) x))
143 144
  #c(1.0l0 2.0l0) #c(1.0l0 2.0l0))

145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
;;; Test that explicit calls to macroexpand in subforms
;;; are done in the correct environment

(deftest decf.22
  (macrolet
   ((%m (z) z))
   (let ((x 10))
     (values
      (decf (expand-in-current-env (%m x)))
      x)))
  9 9)

(deftest decf.23
  (macrolet
   ((%m (z) z))
   (let ((x 5))
     (values
      (decf x (expand-in-current-env (%m 3)))
      x)))
  2 2)

166
(deftest decf.order.2
167
  (let ((a (vector 1 2 3 4))
sds's avatar
sds committed
168
        (i 0) x y z)
169 170
    (values
     (decf (aref (progn (setf x (incf i)) a)
sds's avatar
sds committed
171 172
                 (progn (setf y (incf i)) 0))
           (progn (setf z (incf i)) 17))
173 174 175
     i x y z a))
  -16 3 1 2 3 #(-16 2 3 4))

176
(deftest decf.order.3
177
  (let ((a (vector 10 2 3 4))
sds's avatar
sds committed
178
        (i 0) x y)
179 180
    (values
     (decf (aref (progn (setf x (incf i)) a)
sds's avatar
sds committed
181
                 (progn (setf y (incf i)) 0)))
182 183
     i x y a))
  9 2 1 2 #(9 2 3 4))
184 185 186 187 188 189 190 191 192

(deftest decf.order.4
  (let ((x 0))
    (progn
      "See CLtS 5.1.3"
      (values
       (decf x (setf x 1))
       x)))
  0 0)