random 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +11 -3
- data/VERSION +1 -1
- data/test/common.rb +44 -0
- metadata +2 -1
data/Rakefile
CHANGED
@@ -64,9 +64,16 @@ UTestFiles = FileList["test/unit/**/test*.rb"]
|
|
64
64
|
ATestFiles = FileList["test/acceptance/**/*test*.rb"]
|
65
65
|
PTestFiles = FileList["test/performance/**/test*.rb"]
|
66
66
|
|
67
|
-
|
68
|
-
|
69
|
-
|
67
|
+
if File.exist?("_darcs")
|
68
|
+
task :setup_for_test => [:pack_and_geminstall] do
|
69
|
+
require 'rubygems'
|
70
|
+
require 'test/common'
|
71
|
+
end
|
72
|
+
else
|
73
|
+
task :setup_for_test do
|
74
|
+
require 'rubygems'
|
75
|
+
require 'test/common'
|
76
|
+
end
|
70
77
|
end
|
71
78
|
|
72
79
|
def load_files(list)
|
@@ -142,6 +149,7 @@ TestFilesToIncludeGlobs = [
|
|
142
149
|
"test/acceptance/**/*",
|
143
150
|
"test/performance/**/*",
|
144
151
|
"test/unit/**/*",
|
152
|
+
"test/*.rb",
|
145
153
|
]
|
146
154
|
|
147
155
|
PkgFileGlobs = BaseFileToIncludeGlobs + TestFilesToIncludeGlobs
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/test/common.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
|
3
|
+
require 'random/testing'
|
4
|
+
|
5
|
+
class Test::Unit::TestCase
|
6
|
+
def assert_chi_square(reps = 1e4, &block)
|
7
|
+
alpha = 0.005
|
8
|
+
bin_counts = Hash.new(0)
|
9
|
+
reps.to_i.times {bin_counts[block.call] += 1}
|
10
|
+
result = Random::Testing.chi_square_test(bin_counts, alpha)
|
11
|
+
if result
|
12
|
+
assert(true)
|
13
|
+
else
|
14
|
+
crit =
|
15
|
+
Math::Statistics.critical_chi_square_value(bin_counts.keys.length - 1,
|
16
|
+
alpha)
|
17
|
+
chisq = Random::Testing.chi_square_statistic(bin_counts.values)
|
18
|
+
assert(false, "Expected a chi square value > #{crit} but got #{chisq} for #{bin_counts.inspect}")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def assert_chi_square_floats(numBins = 10, reps = 1e4, &block)
|
23
|
+
w = 1.0 / numBins
|
24
|
+
assert_chi_square(reps) do
|
25
|
+
v = block.call
|
26
|
+
res = w * (v/w).floor
|
27
|
+
#puts "#{v.inspect}, #{w.inspect}"
|
28
|
+
res
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def assert_rand(rng)
|
33
|
+
assert_kind_of(Float, rng.rand)
|
34
|
+
assert_kind_of(Float, rng.rand(0))
|
35
|
+
assert_kind_of(Float, rng.rand(0.0))
|
36
|
+
assert_kind_of(Float, rng.rand(0.99))
|
37
|
+
|
38
|
+
assert_equal(0, rng.rand(1.0))
|
39
|
+
100.times {assert_equal(0, rng.rand(1))}
|
40
|
+
|
41
|
+
# Very unlikely that we would get a fixnum out of this but it can happen
|
42
|
+
assert_kind_of(Bignum, rng.rand(2**10000))
|
43
|
+
end
|
44
|
+
end
|
metadata
CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: random
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.2.
|
6
|
+
version: 0.2.1
|
7
7
|
date: 2006-04-13 00:00:00 +02:00
|
8
8
|
summary: Stand-alone random number generator (RNG) class allowing multiple, active RNG's at the same time (which is not possible with Ruby's rand/srand).
|
9
9
|
require_paths:
|
@@ -55,6 +55,7 @@ files:
|
|
55
55
|
- test/unit/test_chi_square.rb
|
56
56
|
- test/unit/#mt19937ar.c#
|
57
57
|
- test/unit/test_random_number_generator.rb
|
58
|
+
- test/common.rb
|
58
59
|
test_files: []
|
59
60
|
|
60
61
|
rdoc_options: []
|