remhash.lsp 1.96 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Fri Nov 28 08:58:06 2003
;;;; Contains: Tests of REMHASH

(in-package :cl-test)

(deftest remhash.1
  (let ((table (make-hash-table)))
    (values (gethash 'a table)
sds's avatar
sds committed
11 12 13 14 15
            (remhash 'a table)
            (setf (gethash 'a table) 'b)
            (gethash 'a table)
            (notnot (remhash 'a table))
            (gethash 'a table)))
16 17 18 19 20
  nil nil b b t nil)

(deftest remhash.2
  (let ((table (make-hash-table :test 'eq)))
    (values (gethash 'a table)
sds's avatar
sds committed
21 22 23 24 25
            (remhash 'a table)
            (setf (gethash 'a table) 'b)
            (gethash 'a table)
            (notnot (remhash 'a table))
            (gethash 'a table)))
26 27 28 29 30
  nil nil b b t nil)

(deftest remhash.3
  (let ((table (make-hash-table :test 'equal)))
    (values (gethash 'a table)
sds's avatar
sds committed
31 32 33 34 35
            (remhash 'a table)
            (setf (gethash 'a table) 'b)
            (gethash 'a table)
            (notnot (remhash 'a table))
            (gethash 'a table)))
36 37 38 39 40
  nil nil b b t nil)

(deftest remhash.4
  (let ((table (make-hash-table :test 'equalp)))
    (values (gethash 'a table)
sds's avatar
sds committed
41 42 43 44 45
            (remhash 'a table)
            (setf (gethash 'a table) 'b)
            (gethash 'a table)
            (notnot (remhash 'a table))
            (gethash 'a table)))
46 47 48 49 50 51 52 53
  nil nil b b t nil)

(deftest remhash.5
  (remhash 'a (make-hash-table))
  nil)

(deftest remhash.6
  (notnot-mv (remhash nil (let ((table (make-hash-table)))
sds's avatar
sds committed
54 55
                            (setf (gethash nil table) t)
                            table)))
56 57 58 59 60 61
  t)

(deftest remhash.order.1
  (let ((i 0) x y)
    (values
     (remhash (progn (setf x (incf i)) 'a)
sds's avatar
sds committed
62
              (progn (setf y (incf i)) (make-hash-table)))
63 64 65 66 67 68
     i x y))
  nil 2 1 2)

;;; Error tests

(deftest remhash.error.1
69 70
  (signals-error (remhash) program-error)
  t)
71 72

(deftest remhash.error.2
73 74
  (signals-error (remhash 'a) program-error)
  t)
75 76

(deftest remhash.error.3
77 78
  (signals-error (remhash 'a (make-hash-table) nil) program-error)
  t)
79 80 81 82 83 84 85







sds's avatar
sds committed
86