1 ;; Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
3 ;; This program is free software; you can redistribute it and/or modify
4 ;; it under the terms of the GNU General Public License as published by
5 ;; the Free Software Foundation; either version 2, or (at your option)
8 ;; This program is distributed in the hope that it will be useful,
9 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 ;; GNU General Public License for more details.
13 ;; You should have received a copy of the GNU General Public License
14 ;; along with this software; see the file COPYING. If not, write to
15 ;; the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
16 ;; Boston, MA 02111-1307 USA
18 ;; As a special exception, the Free Software Foundation gives permission
19 ;; for additional uses of the text contained in its release of GUILE.
21 ;; The exception is that, if you link the GUILE library with other files
22 ;; to produce an executable, this does not by itself cause the
23 ;; resulting executable to be covered by the GNU General Public License.
24 ;; Your use of that executable is in no way restricted on account of
25 ;; linking the GUILE library code into it.
27 ;; This exception does not however invalidate any other reasons why
28 ;; the executable file might be covered by the GNU General Public License.
30 ;; This exception applies only to the code released by the
31 ;; Free Software Foundation under the name GUILE. If you copy
32 ;; code from other Free Software Foundation releases into a copy of
33 ;; GUILE, as the General Public License permits, the exception does
34 ;; not apply to the code that you add in this way. To avoid misleading
35 ;; anyone as to the status of such modified files, you must delete
36 ;; this exception notice from them.
38 ;; If you write modifications of your own for GUILE, it is your choice
39 ;; whether to permit this exception to apply to your modifications.
40 ;; If you do not wish that, delete this exception notice.
42 ;;;; "test.scm" Test correctness of scheme implementations.
43 ;;; Author: Aubrey Jaffer
44 ;;; Modified: Mikael Djurfeldt (Removed tests which Guile deliberately
45 ;;; won't pass. Made the the tests (test-cont), (test-sc4), and
46 ;;; (test-delay) start to run automatically.
48 ;;; This includes examples from
49 ;;; William Clinger and Jonathan Rees, editors.
50 ;;; Revised^4 Report on the Algorithmic Language Scheme
51 ;;; and the IEEE specification.
53 ;;; The input tests read this file expecting it to be named
54 ;;; "test.scm", so you'll have to run it from the ice-9 source
55 ;;; directory, or copy this file elsewhere
56 ;;; Files `tmp1', `tmp2' and `tmp3' will be created in the course of running
57 ;;; these tests. You may need to delete them in order to run
58 ;;; "test.scm" more than once.
60 ;;; There are three optional tests:
61 ;;; (TEST-CONT) tests multiple returns from call-with-current-continuation
63 ;;; (TEST-SC4) tests procedures required by R4RS but not by IEEE
65 ;;; (TEST-DELAY) tests DELAY and FORCE, which are not required by
68 ;;; If you are testing a R3RS version which does not have `list?' do:
71 ;;; send corrections or additions to jaffer@ai.mit.edu or
72 ;;; Aubrey Jaffer, 84 Pleasant St., Wakefield MA 01880, USA
74 (define cur-section '())(define errs '())
75 (define SECTION (lambda args
76 (display "SECTION") (write args) (newline)
77 (set! cur-section args) #t))
78 (define record-error (lambda (e) (set! errs (cons (list cur-section e) errs))))
81 (lambda (expect fun . args)
82 (write (cons fun args))
87 (cond ((not (equal? expect res))
88 (record-error (list res expect (cons fun args)))
89 (display " BUT EXPECTED ")
94 (if (procedure? fun) (apply fun args) (car args)))))
97 (if (null? errs) (display "Passed all tests")
99 (display "errors were:")
101 (display "(SECTION (got expected (call)))")
103 (for-each (lambda (l) (write l) (newline))
107 (SECTION 2 1);; test that all symbol characters are supported.
108 '(+ - ... !.. $.+ %.- &.! *.: /:. :+. <-. =. >. ?. ~. _. ^.)
111 (define disjoint-type-functions
112 (list boolean? char? null? number? pair? procedure? string? symbol? vector?))
113 (define type-examples
115 #t #f #\a '() 9739 '(test) record-error "test" "" 'test '#() '#(a b c) ))
117 (for-each (lambda (x) (display (make-string i #\ ))
121 disjoint-type-functions)
124 (let ((t (map (lambda (f) (f x)) disjoint-type-functions)))
131 (test '(quote a) 'quote (quote 'a))
132 (test '(quote a) 'quote ''a)
134 (test 12 (if #f + *) 3 4)
136 (test 8 (lambda (x) (+ x x)) 4)
137 (define reverse-subtract
138 (lambda (x y) (- y x)))
139 (test 3 reverse-subtract 7 10)
142 (lambda (y) (+ x y))))
144 (test '(3 4 5 6) (lambda x x) 3 4 5 6)
145 (test '(5 6) (lambda (x y . z) z) 3 4 5 6)
147 (test 'yes 'if (if (> 3 2) 'yes 'no))
148 (test 'no 'if (if (> 2 3) 'yes 'no))
149 (test '1 'if (if (> 3 2) (- 3 2) (+ 3 2)))
152 (test 3 'define (+ x 1))
154 (test 5 'set! (+ x 1))
156 (test 'greater 'cond (cond ((> 3 2) 'greater)
158 (test 'equal 'cond (cond ((> 3 3) 'greater)
161 (test 2 'cond (cond ((assv 'b '((a 1) (b 2))) => cadr)
163 (test 'composite 'case (case (* 2 3)
165 ((1 4 6 8 9) 'composite)))
166 (test 'consonant 'case (case (car '(c d))
170 (test #t 'and (and (= 2 2) (> 2 1)))
171 (test #f 'and (and (= 2 2) (< 2 1)))
172 (test '(f g) 'and (and 1 2 'c '(f g)))
174 (test #t 'or (or (= 2 2) (> 2 1)))
175 (test #t 'or (or (= 2 2) (< 2 1)))
176 (test #f 'or (or #f #f #f))
178 (test '(b c) 'or (or (memq 'b '(a b c)) (+ 3 0)))
180 (test 6 'let (let ((x 2) (y 3)) (* x y)))
181 (test 35 'let (let ((x 2) (y 3)) (let ((x 7) (z (+ x y))) (* z x))))
182 (test 70 'let* (let ((x 2) (y 3)) (let* ((x 7) (z (+ x y))) (* z x))))
183 (test #t 'letrec (letrec ((even?
184 (lambda (n) (if (zero? n) #t (odd? (- n 1)))))
186 (lambda (n) (if (zero? n) #f (even? (- n 1))))))
189 (test 5 'let (let ((x 3)) (define x 5) x))
191 (test 6 'let (let () (define x 6) x))
193 (test 7 'let* (let* ((x 3)) (define x 7) x))
195 (test 8 'let* (let* () (define x 8) x))
197 (test 9 'letrec (letrec () (define x 9) x))
199 (test 10 'letrec (letrec ((x 3)) (define x 10) x))
203 (test 6 'begin (begin (set! x 5) (+ x 1)))
205 (test '#(0 1 2 3 4) 'do (do ((vec (make-vector 5))
208 (vector-set! vec i i)))
209 (test 25 'do (let ((x '(1 3 5 7 9)))
211 (sum 0 (+ sum (car x))))
213 (test 1 'let (let foo () 1))
214 (test '((6 1 3) (-5 -2)) 'let
215 (let loop ((numbers '(3 -2 1 6 -5))
218 (cond ((null? numbers) (list nonneg neg))
219 ((negative? (car numbers))
222 (cons (car numbers) neg)))
225 (cons (car numbers) nonneg)
228 (test '(list 3 4) 'quasiquote `(list ,(+ 1 2) 4))
229 (test '(list a (quote a)) 'quasiquote (let ((name 'a)) `(list ,name ',name)))
230 (test '(a 3 4 5 6 b) 'quasiquote `(a ,(+ 1 2) ,@(map abs '(4 -5 6)) b))
231 (test '((foo 7) . cons)
233 `((foo ,(- 10 3)) ,@(cdr '(c)) . ,(car '(cons))))
235 ;;; sqt is defined here because not all implementations are required to
239 ((> (* i i) x) (- i 1))))
241 (test '#(10 5 2 4 3 8) 'quasiquote `#(10 5 ,(sqt 4) ,@(map sqt '(16 9)) 8))
242 (test 5 'quasiquote `,(+ 2 3))
243 (test '(a `(b ,(+ 1 2) ,(foo 4 d) e) f)
244 'quasiquote `(a `(b ,(+ 1 2) ,(foo ,(+ 1 3) d) e) f))
245 (test '(a `(b ,x ,'y d) e) 'quasiquote
246 (let ((name1 'x) (name2 'y)) `(a `(b ,,name1 ,',name2 d) e)))
247 (test '(list 3 4) 'quasiquote (quasiquote (list (unquote (+ 1 2)) 4)))
248 (test '`(list ,(+ 1 2) 4) 'quasiquote '(quasiquote (list (unquote (+ 1 2)) 4)))
250 (define add3 (lambda (x) (+ x 3)))
251 (test 6 'define (add3 3))
253 (test 1 'define (first '(1 2)))
257 (define foo (lambda (y) (bar x y)))
258 (define bar (lambda (a b) (+ (* a b) a)))
261 (define (foo) (define x 5) x)
264 (define foo (lambda () (define x 5) x))
267 (define (foo x) ((lambda () (define x 5) x)) x)
274 (test #f not (list 3))
280 (test #t boolean? #f)
282 (test #f boolean? '())
287 (test #t eqv? '() '())
288 (test #t eqv? '10000 '10000)
289 (test #f eqv? (cons 1 2)(cons 1 2))
290 (test #f eqv? (lambda () 1) (lambda () 2))
291 (test #f eqv? #f 'nil)
292 (let ((p (lambda (x) x)))
297 (lambda () (set! n (+ n 1)) n))))
298 (let ((g (gen-counter))) (test #t eqv? g g))
299 (test #f eqv? (gen-counter) (gen-counter))
300 (letrec ((f (lambda () (if (eqv? f g) 'f 'both)))
301 (g (lambda () (if (eqv? f g) 'g 'both))))
305 (test #f eq? (list 'a) (list 'a))
306 (test #t eq? '() '())
307 (test #t eq? car car)
308 (let ((x '(a))) (test #t eq? x x))
309 (let ((x '#())) (test #t eq? x x))
310 (let ((x (lambda (x) x))) (test #t eq? x x))
312 (test #t equal? 'a 'a)
313 (test #t equal? '(a) '(a))
314 (test #t equal? '(a (b) c) '(a (b) c))
315 (test #t equal? "abc" "abc")
317 (test #t equal? (make-vector 5 'a) (make-vector 5 'a))
319 (test '(a b c d e) 'dot '(a . (b . (c . (d . (e . ()))))))
320 (define x (list 'a 'b 'c))
322 (and list? (test #t list? y))
324 (test '(a . 4) 'set-cdr! x)
326 (test '(a b c . d) 'dot '(a . (b . (c . d))))
327 (and list? (test #f list? y))
328 (and list? (let ((x (list 'a))) (set-cdr! x x) (test #f 'list? (list? x))))
330 (test #t pair? '(a . b))
331 (test #t pair? '(a . 1))
332 (test #t pair? '(a b c))
334 (test #f pair? '#(a b))
336 (test '(a) cons 'a '())
337 (test '((a) b c d) cons '(a) '(b c d))
338 (test '("a" b c) cons "a" '(b c))
339 (test '(a . 3) cons 'a 3)
340 (test '((a b) . c) cons '(a b) 'c)
342 (test 'a car '(a b c))
343 (test '(a) car '((a) b c d))
344 (test 1 car '(1 . 2))
346 (test '(b c d) cdr '((a) b c d))
347 (test 2 cdr '(1 . 2))
349 (test '(a 7 c) list 'a (+ 3 4) 'c)
352 (test 3 length '(a b c))
353 (test 3 length '(a (b) (c d e)))
356 (test '(x y) append '(x) '(y))
357 (test '(a b c d) append '(a) '(b c d))
358 (test '(a (b) (c)) append '(a (b)) '((c)))
360 (test '(a b c . d) append '(a b) '(c . d))
361 (test 'a append '() 'a)
363 (test '(c b a) reverse '(a b c))
364 (test '((e (f)) d (b c) a) reverse '(a (b c) d (e (f))))
366 (test 'c list-ref '(a b c d) 2)
368 (test '(a b c) memq 'a '(a b c))
369 (test '(b c) memq 'b '(a b c))
370 (test '#f memq 'a '(b c d))
371 (test '#f memq (list 'a) '(b (a) c))
372 (test '((a) c) member (list 'a) '(b (a) c))
373 (test '(101 102) memv 101 '(100 101 102))
375 (define e '((a 1) (b 2) (c 3)))
376 (test '(a 1) assq 'a e)
377 (test '(b 2) assq 'b e)
379 (test #f assq (list 'a) '(((a)) ((b)) ((c))))
380 (test '((a)) assoc (list 'a) '(((a)) ((b)) ((c))))
381 (test '(5 7) assv 5 '((2 3) (5 7) (11 13)))
383 (test #t symbol? 'foo)
384 (test #t symbol? (car '(a b)))
385 (test #f symbol? "bar")
386 (test #t symbol? 'nil)
387 (test #f symbol? '())
389 ;;; But first, what case are symbols in? Determine the standard case:
390 (define char-standard-case char-upcase)
391 (if (string=? (symbol->string 'A) "a")
392 (set! char-standard-case char-downcase))
394 ;(test #t 'standard-case
395 ; (string=? (symbol->string 'a) (symbol->string 'A)))
396 ;(test #t 'standard-case
397 ; (or (string=? (symbol->string 'a) "A")
398 ; (string=? (symbol->string 'A) "a")))
400 (let ((v (make-string (string-length s))))
401 (do ((i (- (string-length v) 1) (- i 1)))
403 (string-set! v i (string-ref s i)))))
404 (define (string-standard-case s)
405 (set! s (str-copy s))
407 (sl (string-length s)))
409 (string-set! s i (char-standard-case (string-ref s i)))))
411 ;(test (string-standard-case "flying-fish") symbol->string 'flying-fish)
412 ;(test (string-standard-case "martin") symbol->string 'Martin)
413 (test "Malvina" symbol->string (string->symbol "Malvina"))
415 ;(test #t 'standard-case (eq? 'a 'A))
417 (define x (string #\a #\b))
418 (define y (string->symbol x))
419 (string-set! x 0 #\c)
420 (test "cb" 'string-set! x)
421 (test "ab" symbol->string y)
422 (test y string->symbol "ab")
425 ;(test #t eq? 'mISSISSIppi 'mississippi)
426 ;(test #f 'string->symbol (eq? 'bitBlt (string->symbol "bitBlt")))
427 (test 'JollyWog string->symbol (symbol->string 'JollyWog))
433 (test #t rational? 3)
444 (test #f > 9 9 -2424)
445 (test #t >= 3 -4 -6246)
448 (test #t < -1 2 3 4 5 6 7 8)
449 (test #f < -1 2 3 4 4 5 6 7)
450 (test #t <= -1 2 3 4 5 6 7 8)
451 (test #t <= -1 2 3 4 4 5 6 7)
459 (test #t positive? 4)
460 (test #f positive? -4)
461 (test #f positive? 0)
462 (test #f negative? 4)
463 (test #t negative? -4)
464 (test #f negative? 0)
474 (test 38 max 34 5 7 38 6)
475 (test -24 min 3 5 5 330 4 -24)
489 (test 5 quotient 35 7)
490 (test -5 quotient -35 7)
491 (test -5 quotient 35 -7)
492 (test 5 quotient -35 -7)
494 (test 1 remainder 13 4)
495 (test 3 modulo -13 4)
496 (test -1 remainder -13 4)
497 (test -3 modulo 13 -4)
498 (test 1 remainder 13 -4)
499 (test -1 modulo -13 -4)
500 (test -1 remainder -13 -4)
501 (define (divtest n1 n2)
502 (= n1 (+ (* n2 (quotient n1 n2))
504 (test #t divtest 238 9)
505 (test #t divtest -238 9)
506 (test #t divtest 238 -9)
507 (test #t divtest -238 -9)
513 (test 288 lcm 32 -36)
516 ;;;;From: fred@sce.carleton.ca (Fred J Kaudel)
517 ;;; Modified by jaffer.
518 (define (test-inexact)
519 (define f3.9 (string->number "3.9"))
520 (define f4.0 (string->number "4.0"))
521 (define f-3.25 (string->number "-3.25"))
522 (define f.25 (string->number ".25"))
523 (define f4.5 (string->number "4.5"))
524 (define f3.5 (string->number "3.5"))
525 (define f0.0 (string->number "0.0"))
526 (define f0.8 (string->number "0.8"))
527 (define f1.0 (string->number "1.0"))
528 (define wto write-test-obj)
529 (define dto display-test-obj)
530 (define lto load-test-obj)
532 (display ";testing inexact numbers; ")
535 (test #t inexact? f3.9)
536 (test #t 'inexact? (inexact? (max f3.9 4)))
537 (test f4.0 'max (max f3.9 4))
538 (test f4.0 'exact->inexact (exact->inexact 4))
539 (test (- f4.0) round (- f4.5))
540 (test (- f4.0) round (- f3.5))
541 (test (- f4.0) round (- f3.9))
542 (test f0.0 round f0.0)
543 (test f0.0 round f.25)
544 (test f1.0 round f0.8)
545 (test f4.0 round f3.5)
546 (test f4.0 round f4.5)
547 (set! write-test-obj (list f.25 f-3.25));.25 inexact errors less likely.
548 (set! display-test-obj (list f.25 f-3.25));.3 often has such errors (~10^-13)
549 (set! load-test-obj (list 'define 'foo (list 'quote write-test-obj)))
550 (test #t call-with-output-file
553 (write-char #\; test-file)
554 (display write-test-obj test-file)
556 (write load-test-obj test-file)
557 (output-port? test-file)))
558 (check-test-file "tmp3")
559 (set! write-test-obj wto)
560 (set! display-test-obj dto)
561 (set! load-test-obj lto)
562 (let ((x (string->number "4195835.0"))
563 (y (string->number "3145727.0")))
564 (test #t 'pentium-fdiv-bug (> f1.0 (- x (* (/ x y) y)))))
567 (define (test-bignum)
570 (= n1 (+ (* n2 (quotient n1 n2))
571 (remainder n1 n2)))))
573 (display ";testing bignums; ")
576 (test 0 modulo -2177452800 86400)
577 (test 0 modulo 2177452800 -86400)
578 (test 0 modulo 2177452800 86400)
579 (test 0 modulo -2177452800 -86400)
580 (test #t 'remainder (tb 281474976710655 65535))
581 (test #t 'remainder (tb 281474976710654 65535))
583 (test 281474976710655 string->number "281474976710655")
584 (test "281474976710655" number->string 281474976710655)
588 (test "0" number->string 0)
589 (test "100" number->string 100)
590 (test "100" number->string 256 16)
591 (test 100 string->number "100")
592 (test 256 string->number "100" 16)
593 (test #f string->number "")
594 (test #f string->number ".")
595 (test #f string->number "d")
596 (test #f string->number "D")
597 (test #f string->number "i")
598 (test #f string->number "I")
599 (test #f string->number "3i")
600 (test #f string->number "3I")
601 (test #f string->number "33i")
602 (test #f string->number "33I")
603 (test #f string->number "3.3i")
604 (test #f string->number "3.3I")
605 (test #f string->number "-")
606 (test #f string->number "+")
609 (test #t eqv? '#\ #\Space)
610 (test #t eqv? #\space '#\Space)
614 (test #t char? '#\newline)
616 (test #f char=? #\A #\B)
617 (test #f char=? #\a #\b)
618 (test #f char=? #\9 #\0)
619 (test #t char=? #\A #\A)
621 (test #t char<? #\A #\B)
622 (test #t char<? #\a #\b)
623 (test #f char<? #\9 #\0)
624 (test #f char<? #\A #\A)
626 (test #f char>? #\A #\B)
627 (test #f char>? #\a #\b)
628 (test #t char>? #\9 #\0)
629 (test #f char>? #\A #\A)
631 (test #t char<=? #\A #\B)
632 (test #t char<=? #\a #\b)
633 (test #f char<=? #\9 #\0)
634 (test #t char<=? #\A #\A)
636 (test #f char>=? #\A #\B)
637 (test #f char>=? #\a #\b)
638 (test #t char>=? #\9 #\0)
639 (test #t char>=? #\A #\A)
641 (test #f char-ci=? #\A #\B)
642 (test #f char-ci=? #\a #\B)
643 (test #f char-ci=? #\A #\b)
644 (test #f char-ci=? #\a #\b)
645 (test #f char-ci=? #\9 #\0)
646 (test #t char-ci=? #\A #\A)
647 (test #t char-ci=? #\A #\a)
649 (test #t char-ci<? #\A #\B)
650 (test #t char-ci<? #\a #\B)
651 (test #t char-ci<? #\A #\b)
652 (test #t char-ci<? #\a #\b)
653 (test #f char-ci<? #\9 #\0)
654 (test #f char-ci<? #\A #\A)
655 (test #f char-ci<? #\A #\a)
657 (test #f char-ci>? #\A #\B)
658 (test #f char-ci>? #\a #\B)
659 (test #f char-ci>? #\A #\b)
660 (test #f char-ci>? #\a #\b)
661 (test #t char-ci>? #\9 #\0)
662 (test #f char-ci>? #\A #\A)
663 (test #f char-ci>? #\A #\a)
665 (test #t char-ci<=? #\A #\B)
666 (test #t char-ci<=? #\a #\B)
667 (test #t char-ci<=? #\A #\b)
668 (test #t char-ci<=? #\a #\b)
669 (test #f char-ci<=? #\9 #\0)
670 (test #t char-ci<=? #\A #\A)
671 (test #t char-ci<=? #\A #\a)
673 (test #f char-ci>=? #\A #\B)
674 (test #f char-ci>=? #\a #\B)
675 (test #f char-ci>=? #\A #\b)
676 (test #f char-ci>=? #\a #\b)
677 (test #t char-ci>=? #\9 #\0)
678 (test #t char-ci>=? #\A #\A)
679 (test #t char-ci>=? #\A #\a)
681 (test #t char-alphabetic? #\a)
682 (test #t char-alphabetic? #\A)
683 (test #t char-alphabetic? #\z)
684 (test #t char-alphabetic? #\Z)
685 (test #f char-alphabetic? #\0)
686 (test #f char-alphabetic? #\9)
687 (test #f char-alphabetic? #\space)
688 (test #f char-alphabetic? #\;)
690 (test #f char-numeric? #\a)
691 (test #f char-numeric? #\A)
692 (test #f char-numeric? #\z)
693 (test #f char-numeric? #\Z)
694 (test #t char-numeric? #\0)
695 (test #t char-numeric? #\9)
696 (test #f char-numeric? #\space)
697 (test #f char-numeric? #\;)
699 (test #f char-whitespace? #\a)
700 (test #f char-whitespace? #\A)
701 (test #f char-whitespace? #\z)
702 (test #f char-whitespace? #\Z)
703 (test #f char-whitespace? #\0)
704 (test #f char-whitespace? #\9)
705 (test #t char-whitespace? #\space)
706 (test #f char-whitespace? #\;)
708 (test #f char-upper-case? #\0)
709 (test #f char-upper-case? #\9)
710 (test #f char-upper-case? #\space)
711 (test #f char-upper-case? #\;)
713 (test #f char-lower-case? #\0)
714 (test #f char-lower-case? #\9)
715 (test #f char-lower-case? #\space)
716 (test #f char-lower-case? #\;)
718 (test #\. integer->char (char->integer #\.))
719 (test #\A integer->char (char->integer #\A))
720 (test #\a integer->char (char->integer #\a))
721 (test #\A char-upcase #\A)
722 (test #\A char-upcase #\a)
723 (test #\a char-downcase #\A)
724 (test #\a char-downcase #\a)
726 (test #t string? "The word \"recursion\\\" has many meanings.")
728 (define f (make-string 3 #\*))
729 (test "?**" 'string-set! (begin (string-set! f 0 #\?) f))
730 (test "abc" string #\a #\b #\c)
732 (test 3 string-length "abc")
733 (test #\a string-ref "abc" 0)
734 (test #\c string-ref "abc" 2)
735 (test 0 string-length "")
736 (test "" substring "ab" 0 0)
737 (test "" substring "ab" 1 1)
738 (test "" substring "ab" 2 2)
739 (test "a" substring "ab" 0 1)
740 (test "b" substring "ab" 1 2)
741 (test "ab" substring "ab" 0 2)
742 (test "foobar" string-append "foo" "bar")
743 (test "foo" string-append "foo")
744 (test "foo" string-append "foo" "")
745 (test "foo" string-append "" "foo")
746 (test "" string-append)
747 (test "" make-string 0)
748 (test #t string=? "" "")
749 (test #f string<? "" "")
750 (test #f string>? "" "")
751 (test #t string<=? "" "")
752 (test #t string>=? "" "")
753 (test #t string-ci=? "" "")
754 (test #f string-ci<? "" "")
755 (test #f string-ci>? "" "")
756 (test #t string-ci<=? "" "")
757 (test #t string-ci>=? "" "")
759 (test #f string=? "A" "B")
760 (test #f string=? "a" "b")
761 (test #f string=? "9" "0")
762 (test #t string=? "A" "A")
764 (test #t string<? "A" "B")
765 (test #t string<? "a" "b")
766 (test #f string<? "9" "0")
767 (test #f string<? "A" "A")
769 (test #f string>? "A" "B")
770 (test #f string>? "a" "b")
771 (test #t string>? "9" "0")
772 (test #f string>? "A" "A")
774 (test #t string<=? "A" "B")
775 (test #t string<=? "a" "b")
776 (test #f string<=? "9" "0")
777 (test #t string<=? "A" "A")
779 (test #f string>=? "A" "B")
780 (test #f string>=? "a" "b")
781 (test #t string>=? "9" "0")
782 (test #t string>=? "A" "A")
784 (test #f string-ci=? "A" "B")
785 (test #f string-ci=? "a" "B")
786 (test #f string-ci=? "A" "b")
787 (test #f string-ci=? "a" "b")
788 (test #f string-ci=? "9" "0")
789 (test #t string-ci=? "A" "A")
790 (test #t string-ci=? "A" "a")
792 (test #t string-ci<? "A" "B")
793 (test #t string-ci<? "a" "B")
794 (test #t string-ci<? "A" "b")
795 (test #t string-ci<? "a" "b")
796 (test #f string-ci<? "9" "0")
797 (test #f string-ci<? "A" "A")
798 (test #f string-ci<? "A" "a")
800 (test #f string-ci>? "A" "B")
801 (test #f string-ci>? "a" "B")
802 (test #f string-ci>? "A" "b")
803 (test #f string-ci>? "a" "b")
804 (test #t string-ci>? "9" "0")
805 (test #f string-ci>? "A" "A")
806 (test #f string-ci>? "A" "a")
808 (test #t string-ci<=? "A" "B")
809 (test #t string-ci<=? "a" "B")
810 (test #t string-ci<=? "A" "b")
811 (test #t string-ci<=? "a" "b")
812 (test #f string-ci<=? "9" "0")
813 (test #t string-ci<=? "A" "A")
814 (test #t string-ci<=? "A" "a")
816 (test #f string-ci>=? "A" "B")
817 (test #f string-ci>=? "a" "B")
818 (test #f string-ci>=? "A" "b")
819 (test #f string-ci>=? "a" "b")
820 (test #t string-ci>=? "9" "0")
821 (test #t string-ci>=? "A" "A")
822 (test #t string-ci>=? "A" "a")
824 (test #t vector? '#(0 (2 2 2 2) "Anna"))
825 (test #t vector? '#())
826 (test '#(a b c) vector 'a 'b 'c)
828 (test 3 vector-length '#(0 (2 2 2 2) "Anna"))
829 (test 0 vector-length '#())
830 (test 8 vector-ref '#(1 1 2 3 5 8 13 21) 5)
831 (test '#(0 ("Sue" "Sue") "Anna") 'vector-set
832 (let ((vec (vector 0 '(2 2 2 2) "Anna")))
833 (vector-set! vec 1 '("Sue" "Sue"))
835 (test '#(hi hi) make-vector 2 'hi)
836 (test '#() make-vector 0)
837 (test '#() make-vector 0 'a)
839 (test #t procedure? car)
840 (test #f procedure? 'car)
841 (test #t procedure? (lambda (x) (* x x)))
842 (test #f procedure? '(lambda (x) (* x x)))
843 (test #t call-with-current-continuation procedure?)
844 (test 7 apply + (list 3 4))
845 (test 7 apply (lambda (a b) (+ a b)) (list 3 4))
846 (test 17 apply + 10 (list 3 4))
847 (test '() apply list '())
848 (define compose (lambda (f g) (lambda args (f (apply g args)))))
849 (test 30 (compose sqt *) 12 75)
851 (test '(b e h) map cadr '((a b) (d e) (g h)))
852 (test '(5 7 9) map + '(1 2 3) '(4 5 6))
853 (test '#(0 1 4 9 16) 'for-each
854 (let ((v (make-vector 5)))
855 (for-each (lambda (i) (vector-set! v i (* i i)))
858 (test -3 call-with-current-continuation
860 (for-each (lambda (x) (if (negative? x) (exit x)))
861 '(54 0 37 -3 245 19))
865 (call-with-current-continuation
867 (letrec ((r (lambda (obj) (cond ((null? obj) 0)
868 ((pair? obj) (+ (r (cdr obj)) 1))
869 (else (return #f))))))
871 (test 4 list-length '(1 2 3 4))
872 (test #f list-length '(a b . c))
873 (test '() map cadr '())
875 ;;; This tests full conformance of call-with-current-continuation. It
876 ;;; is a separate test because some schemes do not support call/cc
877 ;;; other than escape procedures. I am indebted to
878 ;;; raja@copper.ucs.indiana.edu (Raja Sooriamurthi) for fixing this
879 ;;; code. The function leaf-eq? compares the leaves of 2 arbitrary
880 ;;; trees constructed of conses.
881 (define (next-leaf-generator obj eot)
885 (set! cont (lambda (x) (return eot)))
890 (call-with-current-continuation
894 (lambda () (call-with-current-continuation
895 (lambda (ret) (set! return ret) (cont #f))))))
896 (define (leaf-eq? x y)
897 (let* ((eot (list 'eot))
898 (xf (next-leaf-generator x eot))
899 (yf (next-leaf-generator y eot)))
900 (letrec ((loop (lambda (x y)
901 (cond ((not (eq? x y)) #f)
903 (else (loop (xf) (yf)))))))
907 (display ";testing continuations; ")
910 (test #t leaf-eq? '(a (b (c))) '((a) b c))
911 (test #f leaf-eq? '(a (b (c))) '((a) b c d))
914 ;;; Test Optional R4RS DELAY syntax and FORCE procedure
917 (display ";testing DELAY and FORCE; ")
920 (test 3 'delay (force (delay (+ 1 2))))
921 (test '(3 3) 'delay (let ((p (delay (+ 1 2))))
922 (list (force p) (force p))))
923 (test 2 'delay (letrec ((a-stream
924 (letrec ((next (lambda (n)
925 (cons n (delay (next (+ n 1)))))))
928 (tail (lambda (stream) (force (cdr stream)))))
929 (head (tail (tail a-stream)))))
931 (p (delay (begin (set! count (+ count 1))
940 (letrec ((p (delay (if c 3 (begin (set! c #t) (+ (force p) 1)))))
946 (test #t input-port? (current-input-port))
947 (test #t output-port? (current-output-port))
948 (test #t call-with-input-file "test.scm" input-port?)
949 (define this-file (open-input-file "test.scm"))
950 (test #t input-port? this-file)
952 (test #\; peek-char this-file)
953 (test #\; read-char this-file)
954 (test '(define cur-section '()) read this-file)
955 (test #\( peek-char this-file)
956 (test '(define errs '()) read this-file)
957 (close-input-port this-file)
958 (close-input-port this-file)
959 (define (check-test-file name)
960 (define test-file (open-input-file name))
961 (test #t 'input-port?
962 (call-with-input-file
965 (test load-test-obj read test-file)
966 (test #t eof-object? (peek-char test-file))
967 (test #t eof-object? (read-char test-file))
968 (input-port? test-file))))
969 (test #\; read-char test-file)
970 (test display-test-obj read test-file)
971 (test load-test-obj read test-file)
972 (close-input-port test-file))
974 (define write-test-obj
975 '(#t #f #\a () 9739 -3 . #((test) "te \" \" st" "" test #() b c)))
976 (define display-test-obj
977 '(#t #f a () 9739 -3 . #((test) te " " st test #() b c)))
978 (define load-test-obj
979 (list 'define 'foo (list 'quote write-test-obj)))
980 (test #t call-with-output-file
983 (write-char #\; test-file)
984 (display write-test-obj test-file)
986 (write load-test-obj test-file)
987 (output-port? test-file)))
988 (check-test-file "tmp1")
990 (define test-file (open-output-file "tmp2"))
991 (write-char #\; test-file)
992 (display write-test-obj test-file)
994 (write load-test-obj test-file)
995 (test #t output-port? test-file)
996 (close-output-port test-file)
997 (check-test-file "tmp2")
1000 (display ";testing scheme 4 functions; ")
1003 (test '(#\P #\space #\l) string->list "P l")
1004 (test '() string->list "")
1005 (test "1\\\"" list->string '(#\1 #\\ #\"))
1006 (test "" list->string '())
1008 (test '(dah dah didah) vector->list '#(dah dah didah))
1009 (test '() vector->list '#())
1010 (test '#(dididit dah) list->vector '(dididit dah))
1011 (test '#() list->vector '())
1014 (test write-test-obj 'load foo)
1018 (if (and (string->number "0.0") (inexact? (string->number "0.0")))
1021 (let ((n (string->number "281474976710655")))
1022 (if (and n (exact? n))