1
0
mirror of synced 2026-05-04 15:16:50 +00:00
Files
Interlisp.medley/internal/test/LANGUAGE/AUTO/14-2-MAP.TEST

99 lines
3.3 KiB
Plaintext

;; Function To Be Tested: map
;;
;; Source: CLtL Section 14.2: Concatenating, Mapping, and Reducing Sequences Page: 250
;;
;; Created By: Karin M. Sye
;;
;; Creation Date: Sept. 8 ,1986
;;
;; Last Update: Jan 28, 1987 Jim Blum - put (not (null ...) around function in
;; test 2 to guarantee T being returned
;;
;; Filed As: {eris}<lispcore>cml>test>14-2-map.test
;;
;;
;; Syntax: map RESULT-TYPE FUNCTION SEQUENCE &REST MORE-SEQUENCES
;;
;; Function Description: map returns a sequence such that element j is the result of applying FUNCTION to element j of
;; each of the argument sequences. The result sequence is as long as the shofrtest of the
;; input sequences.
;;
;; Argument(s): RESULT-TYPE - a subtype of the type SEQUENCE
;; FUNCTION - a Lisp function which must take as many arguments as there are sequences provided
;; SEQUENCE(S) -
;;
;; Result: a sequence
;;
(do-test "test map - test cases copied from page 250 of CLtL"
(and (equal (map 'list #'- '(1 2 3 4)) '(-1 -2 -3 -4))
(equal (map 'string #'(lambda (x) (if (oddp x) #\1 #\0)) '(1 2 3 4)) "1010")
)
)
(do-test "test map 1"
(equal (map 'list #'list "12345123451234512345123451234512345123451234512345"
'(6 7 8 9 10 6 7 8 9 10 6 7 8 9 10 6 7 8 9 10 6 7 8 9 10 6 7 8 9 10 6 7 8 9 10 6 7 8 9 10
6 7 8 9 10 6 7 8 9 10 )
(make-array 50 :initial-contents '(a b c d e a b c d e a b c d e a b c d e a b c d e a b c d e
a b c d e a b c d e a b c d e a b c d e)))
(let ((x ())) (dotimes (ignore 10 x) (setq x (append '((#\1 6 a) (#\2 7 b) (#\3 8 c) (#\4 9 d) (#\5 10 e)) x))))
)
)
(do-test "test map 2"
(equal (map 'list #'(lambda (w x y z) (not (null (equal (funcall w x y) z))))
(list #'member #'intersection #'+ #'>= #'subseq #'cons #'find #'typep #'elt #'complexp)
'((a b) (1 2 13 4 (5)) #c(1 -1) 10.0 "funny" 11 #\s "apple" "orange" #c(9 10))
'(((ab) d) (10 20 3 4 5) #c(9 8) 9.999 3 88 "sun" list 5)
'( nil (4) #c(10 7) t "ny" (11 . 88) #\s nil #\e) )
'(t t t t t t t t t)))
(do-test "test map 3"
(let ((a "12345678901234567890")
(b "024680246802468")
(c "9753197531357")
(even t))
(equal (map 'list #'(lambda (x y z)
;; skip every other element slice.
(unless (setf even (not even))
(concatenate 'string (vector x) (vector y) (vector z))))
a b c)
'("109" nil "345" nil "581" nil "727" nil "963" nil "103" nil "347")
)
)
)
(do-test "test map 4"
(equalp (map 'vector #'values '(1 2 3 4 5 6 7 8 9 0)
'(11 22 33 44 55 66 77 88)
'(111 222 333 444 555 666))
'#(1 2 3 4 5 6)))
(do-test "test map 5"
(equal (map 'list #'(lambda (w x y z) (>= (char-code w) (char-code x) (char-code y) (char-code z)))
"cfjiwuyrklmops"
"kiemjcbsywq839ew"
"KLFDDSLFKLDKLD"
"736y47326479738")
'(nil nil t nil t t t nil nil nil nil nil nil nil) ))
(do-test "test map - if the RESULT-TYPE was specified to be nil, map returns nil"
(and (null (map nil #'list "abcde" "defgg" "gdfsdfds"))
(null (map (= 1 2) #'- '(1 2 3 4)))
)
)
STOP