make-random-state.lsp 1.69 KB
Newer Older
1 2 3 4 5 6 7
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Sat Sep  6 17:53:30 2003
;;;; Contains: Tests of MAKE-RANDOM-STATE

(in-package :cl-test)

8 9
;;; Error tests

10
(deftest make-random-state.error.1
11 12
  (signals-error (make-random-state nil nil) program-error)
  t)
13 14

(deftest make-random-state.error.2
15 16
  (signals-error (make-random-state t nil) program-error)
  t)
17 18

(deftest make-random-state.error.3
19 20
  (signals-error (make-random-state *random-state* nil) program-error)
  t)
21 22

(deftest make-random-state.error.4
pfdietz's avatar
pfdietz committed
23
  (check-type-error #'make-random-state (typef '(or (member nil t) random-state)))
24 25
  nil)

26 27
;;; Non-error tests

28 29 30
(deftest make-random-state.1
  (let ((rs (make-random-state)))
    (and (not (eq rs *random-state*))
sds's avatar
sds committed
31 32
         (random-state-p rs)
         (eqlt (random 1000000) (random 1000000 rs))))
33 34 35 36 37
  t)

(deftest make-random-state.2
  (let ((rs (make-random-state *random-state*)))
    (and (not (eq rs *random-state*))
sds's avatar
sds committed
38 39
         (random-state-p rs)
         (eqlt (random 1000000) (random 1000000 rs))))
40 41 42 43 44 45 46
  t)

(deftest make-random-state.3
  (let ((rs (make-random-state)))
    (random 10)
    (let ((rs2 (make-random-state rs)))
      (and (not (eq rs *random-state*))
sds's avatar
sds committed
47 48 49 50 51
           (not (eq rs rs2))
           (not (eq rs2 *random-state*))
           (random-state-p rs)
           (random-state-p rs2)
           (eqlt (random 1.0 rs) (random 1.0 rs2)))))
52 53 54 55
  t)

(deftest make-random-state.4
  (let ((rs (make-random-state t))
sds's avatar
sds committed
56
        (rs2 (make-random-state t)))
57
    (and (random-state-p rs)
sds's avatar
sds committed
58 59 60 61 62 63 64
         (not (eq rs *random-state*))
         (random-state-p rs2)
         (not (eq rs2 *random-state*))
         (not (eq rs rs2))
         (integerp (random 10 rs))
         (floatp (random 1.0 rs2))
         t))
65 66
  t)

sds's avatar
sds committed
67