mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-19 05:39:18 +02:00
By convention, a library meant for testing exports "run-tests". Also by convention, assume the test for (foo bar) is (foo bar-test), keeping the test in the same directory and avoiding confusion since (chibi test) is not a test for (chibi). - Avoids the hack of "load"ing test, with resulting namespace complications. - Allows keeping tests together with the libraries. - Allows setting up test hooks before running. - Allows implicit inference of test locations when using above conventions.
27 lines
952 B
Scheme
27 lines
952 B
Scheme
(define-library (srfi 27 test)
|
|
(export run-tests)
|
|
(import (chibi)
|
|
(srfi 27)
|
|
(chibi test))
|
|
(begin
|
|
(define (run-tests)
|
|
(test-begin "srfi-27: random")
|
|
(define (test-random rand n)
|
|
(test-assert (<= 0 (rand n) (- n 1))))
|
|
(let ((rs (make-random-source)))
|
|
;; chosen by fair dice roll. guaranteed to be random
|
|
(random-source-pseudo-randomize! rs 4 4)
|
|
(let ((rand (random-source-make-integers rs)))
|
|
(do ((k 0 (+ k 5))
|
|
(n 1 (* n 2)))
|
|
((> k 1024))
|
|
(test-random rand n))
|
|
(let* ((state (random-source-state-ref rs))
|
|
(x (rand 1000000)))
|
|
;; the next int won't be the same, but it will be after
|
|
;; resetting the state
|
|
(test-not (= x (rand 1000000)))
|
|
(random-source-state-set! rs state)
|
|
;; (test x (rand 1000000))
|
|
)))
|
|
(test-end))))
|