/usr/share/common-lisp/source/mcclim/Drei/Tests/cl-automaton/eqv-hash-tests.lisp is in cl-mcclim 0.9.6.dfsg.cvs20100315-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | ;;; -*- Mode: Lisp; Package: COMMON-LISP-USER -*-
;;; (c) copyright 2005 by
;;; Aleksandar Bakic (a_bakic@yahoo.com)
;;; (c) copyright 2006 by
;;; Troels Henriksen (athas@sigkill.dk)
;;; This library is free software; you can redistribute it and/or
;;; modify it under the terms of the GNU Library General Public
;;; License as published by the Free Software Foundation; either
;;; version 2 of the License, or (at your option) any later version.
;;;
;;; This library is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;;; Library General Public License for more details.
;;;
;;; You should have received a copy of the GNU Library General Public
;;; License along with this library; if not, write to the
;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;;; Boston, MA 02111-1307 USA.
(cl:in-package :drei-tests)
(def-suite eqv-hash-tests :description "The test suite for
CL-AUTOMATON eqv-hash related tests." :in automaton-tests)
(in-suite eqv-hash-tests)
(defclass foo ()
((slot1 :initform 0 :initarg :slot1 :type fixnum :accessor slot1)
(slot2 :initform 0 :initarg :slot2 :type fixnum :accessor slot2)))
(defclass foo-intention (equalp-key-situation) ())
(defparameter +foo-intention+ (make-instance 'foo-intention))
(defmethod eqv ((foo1 foo) (foo2 foo) (s (eql +foo-intention+)))
(eql (slot1 foo1) (slot1 foo2)))
(defmethod hash ((foo1 foo) (s (eql +foo-intention+)))
(floor (slot1 foo1) 2))
(test htref.test-1 ; (eqv i1 i2), (= (hash i1) (hash i2))
(let ((ght (make-generalized-hash-table +foo-intention+))
(i1 (make-instance 'foo :slot1 1 :slot2 2))
(i2 (make-instance 'foo :slot1 1 :slot2 3)))
(setf (htref ght i1) i1)
(setf (htref ght i2) i2)
(is (= (cnt ght) 1))
(is (eq (htref ght i1) i2))
(is (htref ght i2) i2)))
(test htref.test-2 ; (not (eqv i1 i2)), (= (hash i1) (hash i2))
(let ((ght (make-generalized-hash-table +foo-intention+))
(i1 (make-instance 'foo :slot1 2))
(i2 (make-instance 'foo :slot1 3)))
(setf (htref ght i1) i1)
(setf (htref ght i2) i2)
(is (= (cnt ght) 2))
(is (eq (htref ght i1) i1))
(is (eq (htref ght i2) i2))))
(test htref.test-3 ; (not (eqv i1 i2)), (/= (hash i1) (hash i2))
(let ((ght (make-generalized-hash-table +foo-intention+))
(i1 (make-instance 'foo :slot1 2))
(i2 (make-instance 'foo :slot1 4)))
(setf (htref ght i1) i1)
(setf (htref ght i2) i2)
(is (= (cnt ght) 2))
(is (eq (htref ght i1) i1))
(is (eq (htref ght i2) i2))))
(test htref.test-4
(let ((ght (make-generalized-hash-table +foo-intention+))
(i1 (make-instance 'foo :slot1 1 :slot2 2))
(i2 (make-instance 'foo :slot1 1 :slot2 3)))
(setf (htref ght i1) i1)
(is (= (cnt ght) 1))
(is (eq (htref ght i2) i1))))
(test htref.test-5
(let ((ght (make-generalized-hash-table +foo-intention+))
(i1 (make-instance 'foo :slot1 1 :slot2 2))
(i2 (make-instance 'foo :slot1 1 :slot2 3)))
(setf (htref ght i1) i1)
(multiple-value-bind (v vp)
(htref ght i2)
(declare (ignore v))
(is (= (cnt ght) 1))
(is-true vp))))
(test htref.test-6
(let ((ght (make-generalized-hash-table +foo-intention+))
(i1 (make-instance 'foo :slot1 2))
(i2 (make-instance 'foo :slot1 3)))
(setf (htref ght i1) i1)
(multiple-value-bind (a b)
(htref ght i2)
(is-false a)
(is-false b))))
(test htref.test-7
(let ((ght (make-generalized-hash-table +foo-intention+))
(i1 (make-instance 'foo :slot1 2))
(i2 (make-instance 'foo :slot1 3)))
(is (eq (setf (htref ght i1) i2) i2))
(is (= (cnt ght) 1))))
(test htadd.test-1
(let ((ght (make-generalized-hash-table +foo-intention+))
(i1 (make-instance 'foo :slot1 2)))
(is-true (htadd ght i1))
(is-true (htref ght i1))))
(test htadd.test-2
(let ((ght (make-generalized-hash-table +foo-intention+))
(i1 (make-instance 'foo :slot1 2)))
(multiple-value-bind (a b)
(htref ght i1)
(is-false a)
(is-false b))))
(test htadd.test-3
(let ((ght (make-generalized-hash-table +foo-intention+))
(i1 (make-instance 'foo :slot1 2))
(i2 (make-instance 'foo :slot1 3)))
(htadd ght i1)
(multiple-value-bind (a b)
(htref ght i2)
(is-false a)
(is-false b))))
(test htpresent.test-1
(let ((ght (make-generalized-hash-table +foo-intention+))
(i1 (make-instance 'foo :slot1 2)))
(htadd ght i1)
(is (= (cnt ght) 1))
(is (htpresent ght i1))))
(test htpresent.test-2
(let ((ght (make-generalized-hash-table +foo-intention+))
(i1 (make-instance 'foo :slot1 2)))
(is (= (cnt ght) 0))
(is-false (htpresent ght i1))))
(test htremove.test-1
(let ((ght (make-generalized-hash-table +foo-intention+))
(i1 (make-instance 'foo :slot1 2)))
(is-false (htremove ght i1))
(is (= (cnt ght) 0))
(is-false (htref ght i1))))
(test htremove.test-2
(let ((ght (make-generalized-hash-table +foo-intention+))
(i1 (make-instance 'foo :slot1 2)))
(htadd ght i1)
(is-true (htremove ght i1))
(is-true (= (cnt ght) 0))
(is-false (htref ght i1))))
(test with-ht.test-1
(let ((ght (make-generalized-hash-table +foo-intention+))
(i1 (make-instance 'foo :slot1 2))
(i2 (make-instance 'foo :slot1 3))
l)
(htadd ght i1)
(htadd ght i2)
(with-ht (k v) ght
(push (cons k v) l))
(is (= (length l) 2))
(is (equal (assoc i1 l) (cons i1 t)))
(is (equal (assoc i2 l) (cons i2 t)))))
(test with-ht.test-2
(let ((ght (make-generalized-hash-table +foo-intention+))
l)
(with-ht (k v) ght
(push (cons k v) l))
(is-false l)))
(test with-ht-collect.test-1
(let ((ght (make-generalized-hash-table +foo-intention+))
(i1 (make-instance 'foo :slot1 2))
(i2 (make-instance 'foo :slot1 3)))
(htadd ght i1)
(htadd ght i2)
(let ((l (with-ht-collect (k v) ght (cons k v))))
(is (= (length l) 2))
(is (equal (assoc i1 l) (cons i1 t)))
(is (equal (assoc i2 l) (cons i2 t))))))
(test with-ht-collect.test-2
(let ((ght (make-generalized-hash-table +foo-intention+)))
(is-false (with-ht-collect (k v) ght (cons k v)))))
|