1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 11:50:28 +02:00
guile/test-suite/tests/random.test
Daniel Llorens 70a63479ad Identify scm_is_vector with scm_is_simple_vector
This patch fixes the bug (vector-ref #1@1(1 2 3) 1) => 2.

* libguile/vectors.c: (scm_is_vector): just as scm_is_simple_vector.
* libguile/filesys.c, libguile/random.c, libguile/stime.c, libguile/trees.c,
  libguile/validate.h: use scm_is_vector instead of scm_is_simple_vector.
* libguile/sort.c
  - scm_restricted_vector_sort_x: use scm_array_handle_writable_elements
    instead of scm_vector_writable_elements, to work with non-vector
    rank-1 array objects.
  - scm_sort_x: check for scm_is_array instead of scm_is_vector. Rank
    check is in restricted_vector_sort_x.
  - scm_sort: ditto.
  - scm_stable_sort_x: like scm_restricted_vector_sort_x.
  - scm_stable_sort: like scm_sort.
* test-suite/tests/arrays.test: fix header.
* test-suite/tests/random.test: new coverage test covering
  random:normal-vector!
* test-suite/Makefile.am: include random.test in make check.
2014-01-27 21:45:17 +01:00

55 lines
2.1 KiB
Scheme

;;;; random.test --- tests guile's uniform arrays -*- scheme -*-
;;;;
;;;; Copyright 2013 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-random)
#:use-module ((system base compile) #:select (compile))
#:use-module (test-suite lib)
#:use-module (srfi srfi-4)
#:use-module (srfi srfi-4 gnu))
; see strings.test, arrays.test.
(define exception:wrong-type-arg
(cons #t "Wrong type"))
;;;
;;; random:normal-vector!
;;;
(with-test-prefix "random:normal-vector!"
;; FIXME need proper function test.
(pass-if "non uniform"
(let ((a (make-vector 4 0))
(b (make-vector 4 0))
(c (make-shared-array (make-vector 8 0)
(lambda (i) (list (+ 1 (* 2 i)))) 4)))
(begin
(random:normal-vector! b (random-state-from-platform))
(random:normal-vector! c (random-state-from-platform))
(and (not (equal? a b)) (not (equal? a c))))))
(pass-if "uniform (f64)"
(let ((a (make-f64vector 4 0))
(b (make-f64vector 4 0))
(c (make-shared-array (make-f64vector 8 0)
(lambda (i) (list (+ 1 (* 2 i)))) 4)))
(begin
(random:normal-vector! b (random-state-from-platform))
(random:normal-vector! c (random-state-from-platform))
(and (not (equal? a b)) (not (equal? a c)))))))