1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-01 12:20:26 +02:00
guile/test-suite/tests/ramap.test
2005-05-23 20:15:36 +00:00

199 lines
6.5 KiB
Scheme

;;;; ramap.test --- test array mapping functions -*- scheme -*-
;;;;
;;;; Copyright (C) 2004, 2005 Free Software Foundation, Inc.
;;;;
;;;; This program is free software; you can redistribute it and/or modify
;;;; it under the terms of the GNU General Public License as published by
;;;; the Free Software Foundation; either version 2, or (at your option)
;;;; any later version.
;;;;
;;;; This program 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 General Public License for more details.
;;;;
;;;; You should have received a copy of the GNU General Public License
;;;; along with this software; see the file COPYING. If not, write to
;;;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;;;; Boston, MA 02110-1301 USA
;;;;
;;;; As a special exception, the Free Software Foundation gives permission
;;;; for additional uses of the text contained in its release of GUILE.
;;;;
;;;; The exception is that, if you link the GUILE library with other files
;;;; to produce an executable, this does not by itself cause the
;;;; resulting executable to be covered by the GNU General Public License.
;;;; Your use of that executable is in no way restricted on account of
;;;; linking the GUILE library code into it.
;;;;
;;;; This exception does not however invalidate any other reasons why
;;;; the executable file might be covered by the GNU General Public License.
;;;;
;;;; This exception applies only to the code released by the
;;;; Free Software Foundation under the name GUILE. If you copy
;;;; code from other Free Software Foundation releases into a copy of
;;;; GUILE, as the General Public License permits, the exception does
;;;; not apply to the code that you add in this way. To avoid misleading
;;;; anyone as to the status of such modified files, you must delete
;;;; this exception notice from them.
;;;;
;;;; If you write modifications of your own for GUILE, it is your choice
;;;; whether to permit this exception to apply to your modifications.
;;;; If you do not wish that, delete this exception notice.
(define-module (test-suite test-ramap)
#:use-module (test-suite lib))
;;;
;;; array-map!
;;;
(with-test-prefix "array-map!"
(pass-if-exception "no args" exception:wrong-num-args
(array-map!))
(pass-if-exception "one arg" exception:wrong-num-args
(array-map! (make-array #f 5)))
(with-test-prefix "no sources"
(pass-if "closure 0"
(array-map! (make-array #f 5) (lambda () #f))
#t)
(pass-if-exception "closure 1" exception:wrong-num-args
(array-map! (make-array #f 5) (lambda (x) #f)))
(pass-if-exception "closure 2" exception:wrong-num-args
(array-map! (make-array #f 5) (lambda (x y) #f)))
(pass-if-exception "subr_1" exception:wrong-num-args
(array-map! (make-array #f 5) length))
(pass-if-exception "subr_2" exception:wrong-num-args
(array-map! (make-array #f 5) logtest))
(pass-if-exception "subr_2o" exception:wrong-num-args
(array-map! (make-array #f 5) number->string))
(pass-if-exception "cxr with subrf" exception:wrong-num-args
(array-map! (make-array #f 5) $sqrt))
(pass-if "rpsubr"
(let ((a (make-array 'foo 5)))
(array-map! a =)
(equal? a (make-array #t 5))))
(pass-if "asubr"
(let ((a (make-array 'foo 5)))
(array-map! a +)
(equal? a (make-array 0 5))))
;; in Guile 1.6.4 and earlier this resulted in a segv
(pass-if "noop"
(array-map! (make-array #f 5) noop)
#t))
(with-test-prefix "one source"
(pass-if-exception "closure 0" exception:wrong-num-args
(array-map! (make-array #f 5) (lambda () #f)
(make-array #f 5)))
(pass-if "closure 1"
(let ((a (make-array #f 5)))
(array-map! a (lambda (x) 'foo) (make-array #f 5))
(equal? a (make-array 'foo 5))))
(pass-if-exception "closure 2" exception:wrong-num-args
(array-map! (make-array #f 5) (lambda (x y) #f)
(make-array #f 5)))
(pass-if "subr_1"
(let ((a (make-array #f 5)))
(array-map! a length (make-array '(x y z) 5))
(equal? a (make-array 3 5))))
(pass-if-exception "subr_2" exception:wrong-num-args
(array-map! (make-array #f 5) logtest
(make-array 999 5)))
(pass-if "subr_2o"
(let ((a (make-array #f 5)))
(array-map! a number->string (make-array 99 5))
(equal? a (make-array "99" 5))))
(pass-if "cxr with subrf"
(let ((a (make-array #f 5)))
(array-map! a $sqrt (make-array 16.0 5))
(equal? a (make-array 4.0 5))))
(pass-if "rpsubr"
(let ((a (make-array 'foo 5)))
(array-map! a = (make-array 0 5))
(equal? a (make-array #t 5))))
(pass-if "asubr"
(let ((a (make-array 'foo 5)))
(array-map! a - (make-array 99 5))
(equal? a (make-array -99 5))))
;; in Guile 1.6.5 and 1.6.6 this was an error
(pass-if "1+"
(let ((a (make-array #f 5)))
(array-map! a 1+ (make-array 123 5))
(equal? a (make-array 124 5)))))
(with-test-prefix "two sources"
(pass-if-exception "closure 0" exception:wrong-num-args
(array-map! (make-array #f 5) (lambda () #f)
(make-array #f 5) (make-array #f 5)))
(pass-if-exception "closure 1" exception:wrong-num-args
(array-map! (make-array #f 5) (lambda (x) #f)
(make-array #f 5) (make-array #f 5)))
(pass-if "closure 2"
(let ((a (make-array #f 5)))
(array-map! a (lambda (x y) 'foo)
(make-array #f 5) (make-array #f 5))
(equal? a (make-array 'foo 5))))
(pass-if-exception "subr_1" exception:wrong-type-arg
(array-map! (make-array #f 5) length
(make-array #f 5) (make-array #f 5)))
(pass-if "subr_2"
(let ((a (make-array 'foo 5)))
(array-map! a logtest
(make-array 999 5) (make-array 999 5))
(equal? a (make-array #t 5))))
(pass-if "subr_2o"
(let ((a (make-array #f 5)))
(array-map! a number->string
(make-array 32 5) (make-array 16 5))
(equal? a (make-array "20" 5))))
(pass-if "cxr with subrf"
(let ((a (make-array #f 5)))
(array-map! a $sqrt
(make-array 16.0 5) (make-array 16.0 5))
(equal? a (make-array 4.0 5))))
(pass-if "rpsubr"
(let ((a (make-array 'foo 5)))
(array-map! a = (make-array 99 5) (make-array 77 5))
(equal? a (make-array #f 5))))
(pass-if "asubr"
(let ((a (make-array 'foo 5)))
(array-map! a - (make-array 99 5) (make-array 11 5))
(equal? a (make-array 88 5))))
(pass-if "+"
(let ((a (make-array #f 4)))
(array-map! a + #(1 2 3 4) #(5 6 7 8))
(equal? a #(6 8 10 12))))))