source: trunk/source/tests/ansi-tests/random.lsp @ 8991

Last change on this file since 8991 was 8991, checked in by gz, 12 years ago

Check in the gcl ansi test suite (original, in preparation for making local changes)

File size: 1.8 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Sat Sep  6 15:47:42 2003
4;;;; Contains: Tests of RANDOM
5
6(in-package :cl-test)
7
8(compile-and-load "numbers-aux.lsp")
9(compile-and-load "random-aux.lsp")
10
11(deftest random.error.1
12  (signals-error (random) program-error)
13  t)
14
15(deftest random.error.2
16  (signals-error (random 10 *random-state* nil) program-error)
17  t)
18
19(deftest random.error.3
20  (check-type-error #'random (typef '(real (0))))
21  nil)
22
23(deftest random.1
24  (loop for i from 2 to 30
25        for n = (ash 1 i)
26        nconc
27        (loop for j = (1+ (random n))
28              repeat 20
29              nconc
30              (loop for r = (random j)
31                    repeat i
32                    unless (and (integerp r)
33                                (<= 0 r)
34                                (< r j))
35                    collect (list j r))))
36  nil)
37
38
39(deftest random.2
40  (loop for i from 2 to 20
41        for n = (ash 1 i)
42        nconc
43        (loop for j = (random (float n))
44              repeat 20
45              unless (zerop j)
46              nconc
47              (loop for r = (random j)
48                    repeat 20
49                    unless (and (eql (float r j) r)
50                                (<= 0 r)
51                                (< r j))
52                    collect (list j r))))
53  nil)
54
55(deftest random.3
56  (binomial-distribution-test 10000
57                              #'(lambda () (eql (random 2) 0)))
58  t)
59
60(deftest random.4
61  (binomial-distribution-test 10000
62                              #'(lambda () (< (random 1.0s0) 0.5s0)))
63  t)
64
65(deftest random.5
66  (binomial-distribution-test 10000
67                              #'(lambda () (< (random 1.0d0) 0.5d0)))
68  t)
69
70(deftest random.6
71  (binomial-distribution-test 10000
72                              #'(lambda () (evenp (random 1024))))
73  t)
74
75(deftest random.7
76  (loop for x in '(10.0s0 20.0f0 30.0d0 40.0l0)
77        for r = (random x)
78        unless (eql (float r x) r)
79        collect (list x r))
80  nil)
81
82(deftest random.8
83  (let* ((f1 '(lambda (x) (random (if x 10 20))))
84         (f2 (compile nil f1)))
85    (values
86     (loop repeat 100 always (<= 0 (funcall f2 t) 9))
87     (loop repeat 100 always (<= 0 (funcall f2 nil) 19))))
88  t t)
89   
90
91;;; Do more statistical tests here
92
93       
Note: See TracBrowser for help on using the repository browser.