-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathash.lsp
79 lines (64 loc) · 1.62 KB
/
ash.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
;-*- Mode: Lisp -*-
;;;; Author: Paul Dietz
;;;; Created: Sun Sep 7 08:43:03 2003
;;;; Contains: Tests of ASH
(in-package :cl-test)
;;; Error tests
(deftest ash.error.1
(signals-error (ash) program-error)
t)
(deftest ash.error.2
(signals-error (ash 1 1 1) program-error)
t)
(deftest ash.error.3
(signals-error (ash 1 1 nil) program-error)
t)
(deftest ash.error.4
(check-type-error #'(lambda (x) (ash x 0)) #'integerp)
nil)
(deftest ash.error.5
(check-type-error #'(lambda (x) (ash 0 x)) #'integerp)
nil)
;;; Non-error tests
(deftest ash.1
(loop for x in *integers*
always (eql (ash x 0) x))
t)
(deftest ash.2
(loop for i = (random-fixnum)
for s = (random-from-interval 40)
for ishifted = (ash i s)
repeat 1000
always (eql (floor (* i (expt 2 s))) ishifted))
t)
(deftest ash.3
(let* ((nbits 100)
(bound (expt 2 nbits)))
(loop for i = (random-from-interval bound)
for s = (random-from-interval (+ nbits 20))
for ishifted = (ash i s)
repeat 1000
always (eql (floor (* i (expt 2 s))) ishifted)))
t)
(deftest ash.4
(loop for i from -1 downto -1000
always (eql (ash i i) -1))
t)
(deftest ash.5
(loop for i from 1 to 100
for j = (- (ash 1 i))
always (eql (ash j j) -1))
t)
(deftest ash.6
(macrolet
((%m (z) z))
(values
(ash (expand-in-current-env (%m 3)) 1)
(ash 1 (expand-in-current-env (%m 3)))))
6 8)
(deftest ash.order.1
(let ((i 0) x y)
(values (ash (progn (setf x (incf i)) 1)
(progn (setf y (incf i)) 2))
i x y))
4 2 1 2)