Commit d9e6402a authored by pfdietz's avatar pfdietz

Added more loop tests, for LOOP-AS-ACROSS and LOOP-AS-HASH forms.

parent 6386f0cd
......@@ -217,6 +217,8 @@ the condition to go uncaught if it cannot be classified."
(defun string-invertcase (s)
(map 'string #'char-invertcase s))
(defun symbol< (x &rest args)
(apply #'string< (symbol-name x) (mapcar #'symbol-name args)))
(defun random-from-seq (seq)
"Generate a random member of a sequence."
......
......@@ -79,6 +79,7 @@
(load "loop3.lsp")
(load "loop4.lsp")
(load "loop5.lsp")
(load "loop6.lsp")
;;; Tests of conses
......
......@@ -101,8 +101,20 @@
(loop for e across y collect e))
(b c d))
;;; tests of 'as' form
(deftest loop.5.33
(loop as e across "abc" collect e)
(#\a #\b #\c))
(deftest loop.5.34
(loop as e of-type character across "abc" collect e)
(#\a #\b #\c))
(deftest loop.5.35
(loop as e of-type integer across (the simple-vector (coerce '(1 2 3) 'simple-vector))
sum e)
6)
;;; Error cases
......
;-*- Mode: Lisp -*-
;;;; Author: Paul Dietz
;;;; Created: Sun Nov 10 21:13:04 2002
;;;; Contains: Tests for LOOP-AS-HASH forms
(in-package :cl-test)
(defparameter *loop.6.alist*
'((a . 1) (b . 2) (c . 3)))
(defparameter *loop.6.alist.2*
'(("a" . 1) ("b" . 2) ("c" . 3)))
(defparameter *loop.6.alist.3*
'(((a1 . a2) . 1) ((b1 . b2) . 2) ((c1 . c2) . 3)))
(defparameter *loop.6.hash.1*
(let ((table (make-hash-table :test #'eq)))
(loop for (key . val) in *loop.6.alist*
do (setf (gethash key table) val))
table))
(defparameter *loop.6.hash.2*
(let ((table (make-hash-table :test #'eql)))
(loop for (key . val) in *loop.6.alist*
do (setf (gethash key table) val))
table))
(defparameter *loop.6.hash.3*
(let ((table (make-hash-table :test #'equal)))
(loop for (key . val) in *loop.6.alist.3*
do (setf (gethash key table) val))
table))
;;; (defparameter *loop.6.hash.4*
;;; (let ((table (make-hash-table :test #'equalp)))
;;; (loop for (key . val) in *loop.6.alist.2*
;;; do (setf (gethash key table) val))
;;; table))
(defparameter *loop.6.hash.5*
(let ((table (make-hash-table :test #'eql)))
(loop for (val . key) in *loop.6.alist.3*
do (setf (gethash key table) val))
table))
;;; being {each | the} {hash-value | hash-values | hash-key | hash-keys} {in | of }
(deftest loop.6.1
(loop for x being the hash-value of *loop.6.hash.1* sum x)
6)
(deftest loop.6.2
(loop for x being the hash-values of *loop.6.hash.1* sum x)
6)
(deftest loop.6.3
(loop for x being each hash-value of *loop.6.hash.1* sum x)
6)
(deftest loop.6.4
(loop for x being each hash-values of *loop.6.hash.1* sum x)
6)
(deftest loop.6.5
(loop for x being the hash-values in *loop.6.hash.1* sum x)
6)
(deftest loop.6.6
(sort (loop for x being the hash-key of *loop.6.hash.1* collect x)
#'symbol<)
(a b c))
(deftest loop.6.7
(sort (loop for x being the hash-keys of *loop.6.hash.1* collect x)
#'symbol<)
(a b c))
(deftest loop.6.8
(sort (loop for x being each hash-key of *loop.6.hash.1* collect x)
#'symbol<)
(a b c))
(deftest loop.6.9
(sort (loop for x being each hash-keys of *loop.6.hash.1* collect x)
#'symbol<)
(a b c))
(deftest loop.6.10
(sort (loop for x being each hash-keys in *loop.6.hash.1* collect x)
#'symbol<)
(a b c))
(deftest loop.6.11
(sort (loop for (u . v) being the hash-keys of *loop.6.hash.3* collect u)
#'symbol<)
(a1 b1 c1))
(deftest loop.6.12
(sort (loop for (u . v) being the hash-keys of *loop.6.hash.3* collect v)
#'symbol<)
(a2 b2 c2))
(deftest loop.6.13
(sort (loop for (u . v) being the hash-values of *loop.6.hash.5* collect u)
#'symbol<)
(a1 b1 c1))
(deftest loop.6.14
(sort (loop for (u . v) being the hash-values of *loop.6.hash.5* collect v)
#'symbol<)
(a2 b2 c2))
(deftest loop.6.15
(sort (loop for k being the hash-keys of *loop.6.hash.1* using (hash-value v)
collect (list k v))
#'< :key #'second)
((a 1) (b 2) (c 3)))
(deftest loop.6.16
(sort (loop for v being the hash-values of *loop.6.hash.1* using (hash-key k)
collect (list k v))
#'< :key #'second)
((a 1) (b 2) (c 3)))
(deftest loop.6.17
(sort (loop for (u . nil) being the hash-values of *loop.6.hash.5* collect u)
#'symbol<)
(a1 b1 c1))
(deftest loop.6.18
(sort (loop for (nil . v) being the hash-values of *loop.6.hash.5* collect v)
#'symbol<)
(a2 b2 c2))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment