random.test 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. ;;;; random.test --- tests guile's uniform arrays -*- scheme -*-
  2. ;;;;
  3. ;;;; Copyright 2013 Free Software Foundation, Inc.
  4. ;;;;
  5. ;;;; This library is free software; you can redistribute it and/or
  6. ;;;; modify it under the terms of the GNU Lesser General Public
  7. ;;;; License as published by the Free Software Foundation; either
  8. ;;;; version 3 of the License, or (at your option) any later version.
  9. ;;;;
  10. ;;;; This library is distributed in the hope that it will be useful,
  11. ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. ;;;; Lesser General Public License for more details.
  14. ;;;;
  15. ;;;; You should have received a copy of the GNU Lesser General Public
  16. ;;;; License along with this library; if not, write to the Free Software
  17. ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. (define-module (test-suite test-random)
  19. #:use-module ((system base compile) #:select (compile))
  20. #:use-module (test-suite lib)
  21. #:use-module (srfi srfi-4)
  22. #:use-module (srfi srfi-4 gnu))
  23. ; see strings.test, arrays.test.
  24. (define exception:wrong-type-arg
  25. (cons #t "Wrong type"))
  26. ;;;
  27. ;;; random:normal-vector!
  28. ;;;
  29. (with-test-prefix "random:normal-vector!"
  30. ;; FIXME need proper function test.
  31. (pass-if "non uniform"
  32. (let ((a (make-vector 4 0))
  33. (b (make-vector 4 0))
  34. (c (make-shared-array (make-vector 8 0)
  35. (lambda (i) (list (+ 1 (* 2 i)))) 4)))
  36. (begin
  37. (random:normal-vector! b (random-state-from-platform))
  38. (random:normal-vector! c (random-state-from-platform))
  39. (and (not (equal? a b)) (not (equal? a c))))))
  40. (pass-if "uniform (f64)"
  41. (let ((a (make-f64vector 4 0))
  42. (b (make-f64vector 4 0))
  43. (c (make-shared-array (make-f64vector 8 0)
  44. (lambda (i) (list (+ 1 (* 2 i)))) 4)))
  45. (begin
  46. (random:normal-vector! b (random-state-from-platform))
  47. (random:normal-vector! c (random-state-from-platform))
  48. (and (not (equal? a b)) (not (equal? a c)))))))