1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-29 19:30:36 +02:00
guile/test-suite/tests/r6rs-lists.test
Ian Price d825841db0 Fix R6RS `fold-left' so the accumulator is the first argument.
* module/rnrs/lists.scm (fold-left): New procedure.

* module/rnrs/records/syntactic.scm (define-record-type): Fix to use
  corrected `fold-left'.

* test-suite/tests/r6rs-lists.test: Add tests.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2011-11-01 01:11:46 +01:00

58 lines
2.1 KiB
Text
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

;;; r6rs-lists.test --- Test suite for R6RS (rnrs lists)
;; Copyright (C) 2010 Free Software Foundation, Inc.
;;
;; This library is free software; you can redistribute it and/or
;; modify it under the terms of the GNU Lesser General Public
;; License as published by the Free Software Foundation; either
;; version 3 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
;; Lesser General Public License for more details.
;;
;; You should have received a copy of the GNU Lesser General Public
;; License along with this library; if not, write to the Free Software
;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
(define-module (test-suite test-r6rs-lists)
:use-module ((rnrs lists) :version (6))
:use-module (test-suite lib))
(with-test-prefix "memp"
(pass-if "memp simple"
(equal? (memp even? '(3 1 4 1 5 9 2 6 5)) '(4 1 5 9 2 6 5))))
(with-test-prefix "assp"
(pass-if "assp simple"
(let ((d '((3 a) (1 b) (4 c))))
(equal? (assp even? d) '(4 c)))))
(with-test-prefix "fold-left"
(pass-if "fold-left sum"
(equal? (fold-left + 0 '(1 2 3 4 5))
15))
(pass-if "fold-left reverse"
(equal? (fold-left (lambda (a e) (cons e a)) '() '(1 2 3 4 5))
'(5 4 3 2 1)))
(pass-if "fold-left max-length"
(equal? (fold-left (lambda (max-len s)
(max max-len (string-length s)))
0
'("longest" "long" "longer"))
7))
(pass-if "fold-left with-cons"
(equal? (fold-left cons '(q) '(a b c))
'((((q) . a) . b) . c)))
(pass-if "fold-left sum-multiple"
(equal? (fold-left + 0 '(1 2 3) '(4 5 6))
21))
(pass-if "fold-left pairlis"
(equal? (fold-left (lambda (accum e1 e2)
(cons (cons e1 e2) accum))
'((d . 4))
'(a b c)
'(1 2 3))
'((c . 3) (b . 2) (a . 1) (d . 4)))))