~ubuntu-branches/ubuntu/quantal/gclcvs/quantal

« back to all changes in this revision

Viewing changes to ansi-tests/assoc-if.lsp

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2004-06-24 15:13:46 UTC
  • Revision ID: james.westby@ubuntu.com-20040624151346-xh0xaaktyyp7aorc
Tags: 2.7.0-26
C_GC_OFFSET is 2 on m68k-linux

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
;-*- Mode:     Lisp -*-
 
2
;;;; Author:   Paul Dietz
 
3
;;;; Created:  Sun Apr 20 07:27:57 2003
 
4
;;;; Contains: Tests of ASSOC-IF
 
5
 
 
6
(in-package :cl-test)
 
7
 
 
8
(compile-and-load "cons-aux.lsp")
 
9
 
 
10
(deftest assoc-if.1
 
11
    (let* ((x (copy-list '((1 . a) (3 . b) (6 . c) (7 . d))))
 
12
           (xcopy (make-scaffold-copy x))
 
13
           (result (assoc-if #'evenp x)))
 
14
      (and
 
15
       (check-scaffold-copy x xcopy)
 
16
       (eqt result (third x))
 
17
       result))
 
18
  (6 . c))
 
19
 
 
20
(deftest assoc-if.2
 
21
  (let* ((x (copy-list '((1 . a) (3 . b) (6 . c) (7 . d))))
 
22
         (xcopy (make-scaffold-copy x))
 
23
         (result (assoc-if #'oddp x :key #'1+)))
 
24
    (and
 
25
     (check-scaffold-copy x xcopy)
 
26
     (eqt result (third x))
 
27
     result))
 
28
  (6 . c))
 
29
 
 
30
(deftest assoc-if.3
 
31
    (let* ((x (copy-list '((1 . a) nil (3 . b) (6 . c) (7 . d))))
 
32
           (xcopy (make-scaffold-copy x))
 
33
           (result (assoc-if #'evenp x)))
 
34
      (and
 
35
       (check-scaffold-copy x xcopy)
 
36
       (eqt result (fourth x))
 
37
       result))
 
38
  (6 . c))
 
39
 
 
40
(deftest assoc-if.4
 
41
  (assoc-if #'null '((a . b) nil (c . d) (nil . e) (f . g)))
 
42
  (nil . e))
 
43
 
 
44
(deftest assoc-if.5
 
45
  (let () (assoc-if #'null '((a . b) nil (c . d) (nil . e) (f . g))))
 
46
  (nil . e))
 
47
 
 
48
 
 
49
;;; Order of argument evaluation
 
50
 
 
51
(deftest assoc-if.order.1
 
52
  (let ((i 0) x y)
 
53
    (values
 
54
     (assoc-if (progn (setf x (incf i)) #'null)
 
55
               (progn (setf y (incf i))
 
56
                      '((a . 1) (b . 2) (nil . 17) (d . 4))))
 
57
     i x y))
 
58
  (nil . 17) 2 1 2)
 
59
 
 
60
(deftest assoc-if.order.2
 
61
  (let ((i 0) x y z)
 
62
    (values
 
63
     (assoc-if (progn (setf x (incf i)) #'null)
 
64
               (progn (setf y (incf i))
 
65
                      '((a . 1) (b . 2) (nil . 17) (d . 4)))
 
66
               :key (progn (setf z (incf i)) #'null))
 
67
     i x y z))
 
68
  (a . 1) 3 1 2 3)
 
69
 
 
70
;;; Keyword tests
 
71
 
 
72
(deftest assoc-if.allow-other-keys.1
 
73
  (assoc-if #'null '((a . 1) (nil . 2) (c . 3)) :bad t :allow-other-keys t)
 
74
  (nil . 2))
 
75
 
 
76
(deftest assoc-if.allow-other-keys.2
 
77
  (assoc-if #'null '((a . 1) (nil . 2) (c . 3))
 
78
            :allow-other-keys t :also-bad t)
 
79
  (nil . 2))
 
80
 
 
81
(deftest assoc-if.allow-other-keys.3
 
82
  (assoc-if #'null '((a . 1) (nil . 2) (c . 3))
 
83
            :allow-other-keys t :also-bad t :key #'not)
 
84
  (a . 1))
 
85
 
 
86
(deftest assoc-if.allow-other-keys.4
 
87
  (assoc-if #'null '((a . 1) (nil . 2) (c . 3)) :allow-other-keys t)
 
88
  (nil . 2))
 
89
 
 
90
(deftest assoc-if.allow-other-keys.5
 
91
  (assoc-if #'null '((a . 1) (nil . 2) (c . 3)) :allow-other-keys nil)
 
92
  (nil . 2))
 
93
 
 
94
(deftest assoc-if.keywords.6
 
95
  (assoc-if #'null '((a . 1) (nil . 2) (c . 3)) :key #'identity :key #'null)
 
96
  (nil . 2))
 
97
 
 
98
(deftest assoc-if.keywords.7
 
99
  (assoc-if #'null '((a . 1) (nil . 2) (c . 3)) :key nil :key #'null)
 
100
  (nil . 2))
 
101
 
 
102
;;; Error cases
 
103
 
 
104
(deftest assoc-if.error.1
 
105
  (signals-error (assoc-if) program-error)
 
106
  t)
 
107
 
 
108
(deftest assoc-if.error.2
 
109
  (signals-error (assoc-if #'null) program-error)
 
110
  t)
 
111
 
 
112
(deftest assoc-if.error.3
 
113
  (signals-error (assoc-if #'null nil :bad t)
 
114
                 program-error)
 
115
  t)
 
116
 
 
117
(deftest assoc-if.error.4
 
118
  (signals-error (assoc-if #'null nil :key)
 
119
                 program-error)
 
120
  t)
 
121
 
 
122
(deftest assoc-if.error.5
 
123
  (signals-error (assoc-if #'null nil 1 1)
 
124
                 program-error)
 
125
  t)
 
126
 
 
127
(deftest assoc-if.error.6
 
128
  (signals-error (assoc-if #'null nil :bad t :allow-other-keys nil)
 
129
                 program-error)
 
130
  t)
 
131
 
 
132
(deftest assoc-if.error.7
 
133
  (signals-error (assoc-if #'cons '((a b)(c d)))
 
134
                 program-error)
 
135
  t)
 
136
 
 
137
(deftest assoc-if.error.8
 
138
  (signals-error (assoc-if #'identity '((a b)(c d)) :key #'cons)
 
139
                 program-error)
 
140
  t)
 
141
 
 
142
(deftest assoc-if.error.9
 
143
  (signals-error (assoc-if #'car '((a b)(c d)))
 
144
                 type-error)
 
145
  t)
 
146
 
 
147
(deftest assoc-if.error.10
 
148
  (signals-error (assoc-if #'identity '((a b)(c d)) :key #'car)
 
149
                 type-error)
 
150
  t)
 
151
 
 
152
(deftest assoc-if.error.11
 
153
  (signals-error (assoc-if #'null '((a . b) . c))
 
154
                 type-error)
 
155
  t)
 
156
 
 
157
(deftest assoc-if.error.12
 
158
  (signals-error (assoc-if #'null '((a . b) :bad (c . d)))
 
159
                 type-error)
 
160
  t)
 
161
 
 
162
(deftest assoc-if.error.13
 
163
  (signals-error (assoc-if #'null 'y) type-error)
 
164
  t)