1
0
mirror of synced 2026-05-05 15:44:25 +00:00
Files
Interlisp.medley/internal/test/LANGUAGE/AUTO/16-1-MAPHASH.TEST

63 lines
1.7 KiB
Plaintext

;; Function To Be Tested: maphash
;;
;; Source: CommonLisp by Steele Section: 16.2: Primitive Hash
;; Functions Page: 285
;;
;; Created By: John Park
;;
;; Creation Date: May 19, 1986
;;
;; Last Update: Oct 9, 1986
;;
;; Filed As: {eris}<lispcore>cml>test>16-2-maphash.test
;;
;;
;; Syntax: maphash function hash-table
;;
;; Function Description: Maphash calls function on two arguments the key of the entry and the value of entry for each entry in hash-table.
;;
;; Argument(s): function to be mapped and hash-table
;;
;; Returns: hash-table or nil
;;
;; Constraints/Limitations: None
;; Alter every entry in hash-table7, replacing the value with its
;; square root. Entries with negative values are removed.
(do-test-group
(set-hash-table
:before (progn
(setf hash-table7 (make-hash-table :size 7))
(setf (gethash 'entry1 hash-table7) 1)
(setf (gethash 'entry2 hash-table7) -2)
(setf (gethash 'entry3 hash-table7) 9)
(setf (gethash 'entry4 hash-table7) -4)
(setf (gethash 'entry5 hash-table7) 25)
(setf (gethash 'entry6 hash-table7) -6)
(setf (gethash 'entry7 hash-table7) 49)
)
)
(do-test maphash-test
(and (eq (maphash
#'(lambda (key val)
(if (minusp val)
(remhash key hash-table7)
(setf (gethash key hash-table7)
(sqrt val))))
hash-table7)
nil)
(eql (gethash 'entry1 hash-table7) 1.0)
(eql (gethash 'entry2 hash-table7) nil)
(eql (gethash 'entry3 hash-table7) 3.0)
(eql (gethash 'entry4 hash-table7) nil)
(eql (gethash 'entry5 hash-table7) 5.0)
(eql (gethash 'entry6 hash-table7) nil)
(eql (gethash 'entry7 hash-table7) 7.0))
)
)
STOP