simple-random 0.10.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,47 +2,67 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
+ # stub: simple-random 1.0.0 ruby lib
5
6
 
6
7
  Gem::Specification.new do |s|
7
- s.name = %q{simple-random}
8
- s.version = "0.10.0"
8
+ s.name = "simple-random"
9
+ s.version = "1.0.0"
9
10
 
10
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = [%q{John D. Cook}, %q{Jason Adams}]
12
- s.date = %q{2014-03-31}
13
- s.description = %q{Simple Random Number Generator including Beta, Cauchy, Chi square, Exponential, Gamma, Inverse Gamma, Laplace (double exponential), Normal, Student t, Uniform, and Weibull. Ported from John D. Cook's C# Code.}
14
- s.email = %q{jasonmadams@gmail.com}
12
+ s.require_paths = ["lib"]
13
+ s.authors = ["John D. Cook", "Jason Adams"]
14
+ s.date = "2014-07-09"
15
+ s.description = "Simple Random Number Generator including Beta, Cauchy, Chi square, Exponential, Gamma, Inverse Gamma, Laplace (double exponential), Normal, Student t, Uniform, and Weibull. Ported from John D. Cook's C# Code."
16
+ s.email = "jasonmadams@gmail.com"
15
17
  s.extra_rdoc_files = [
16
18
  "LICENSE",
17
19
  "README.rdoc"
18
20
  ]
19
21
  s.files = [
20
22
  ".document",
23
+ "Gemfile",
24
+ "Gemfile.lock",
21
25
  "LICENSE",
22
26
  "README.rdoc",
23
27
  "Rakefile",
24
28
  "VERSION",
25
29
  "lib/simple-random.rb",
30
+ "lib/simple-random/multi_threaded_simple_random.rb",
31
+ "lib/simple-random/simple_random.rb",
26
32
  "simple-random.gemspec",
27
33
  "test/helper.rb",
28
34
  "test/test_simple_random.rb"
29
35
  ]
30
- s.homepage = %q{http://github.com/ealdent/simple-random}
31
- s.require_paths = [%q{lib}]
32
- s.rubygems_version = %q{1.8.6}
33
- s.summary = %q{Simple Random Number Generator}
34
- s.license = "Code Project Open License"
36
+ s.homepage = "http://github.com/ealdent/simple-random"
37
+ s.licenses = ["CDDL-1.0"]
38
+ s.rubygems_version = "2.2.2"
39
+ s.summary = "Simple Random Number Generator"
35
40
 
36
41
  if s.respond_to? :specification_version then
37
- s.specification_version = 3
42
+ s.specification_version = 4
38
43
 
39
44
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
+ s.add_development_dependency(%q<minitest>, [">= 0"])
40
46
  s.add_development_dependency(%q<shoulda>, [">= 0"])
47
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
48
+ s.add_development_dependency(%q<bundler>, ["~> 1.0"])
49
+ s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
50
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
41
51
  else
52
+ s.add_dependency(%q<minitest>, [">= 0"])
42
53
  s.add_dependency(%q<shoulda>, [">= 0"])
54
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
55
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
56
+ s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
57
+ s.add_dependency(%q<simplecov>, [">= 0"])
43
58
  end
44
59
  else
60
+ s.add_dependency(%q<minitest>, [">= 0"])
45
61
  s.add_dependency(%q<shoulda>, [">= 0"])
62
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
63
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
64
+ s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
65
+ s.add_dependency(%q<simplecov>, [">= 0"])
46
66
  end
47
67
  end
48
68
 
data/test/helper.rb CHANGED
@@ -1,10 +1,36 @@
1
+ require 'simplecov'
2
+
3
+ module SimpleCov::Configuration
4
+ def clean_filters
5
+ @filters = []
6
+ end
7
+ end
8
+
9
+ SimpleCov.configure do
10
+ clean_filters
11
+ load_profile 'test_frameworks'
12
+ end
13
+
14
+ ENV["COVERAGE"] && SimpleCov.start do
15
+ add_filter "/.rvm/"
16
+ end
1
17
  require 'rubygems'
2
- require 'test/unit'
18
+ require 'bundler'
19
+ begin
20
+ Bundler.setup(:default, :development)
21
+ rescue Bundler::BundlerError => e
22
+ $stderr.puts e.message
23
+ $stderr.puts "Run `bundle install` to install missing gems"
24
+ exit e.status_code
25
+ end
26
+ require 'minitest/autorun'
3
27
  require 'shoulda'
4
28
 
5
29
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
30
  $LOAD_PATH.unshift(File.dirname(__FILE__))
7
31
  require 'simple-random'
8
32
 
9
- class Test::Unit::TestCase
33
+ class MiniTest::Test
10
34
  end
35
+
36
+ MiniTest.autorun
@@ -1,7 +1,7 @@
1
- # TODO: use Kolmogorov-Smirnov test instead: http://en.wikipedia.org/wiki/Kolmogorov_Smirnov
2
-
3
1
  require 'helper'
4
2
 
3
+ # TODO: use Kolmogorov-Smirnov test instead: http://en.wikipedia.org/wiki/Kolmogorov_Smirnov
4
+
5
5
  SAMPLE_SIZE = 10000
6
6
  MAXIMUM_EPSILON = 0.01
7
7
 
@@ -28,7 +28,7 @@ class Array
28
28
  end
29
29
  end
30
30
 
31
- class TestSimpleRandom < Test::Unit::TestCase
31
+ class TestSimpleRandom < MiniTest::Test
32
32
  context "A simple random number generator" do
33
33
  setup do
34
34
  @r = SimpleRandom.new
@@ -69,7 +69,7 @@ class TestSimpleRandom < Test::Unit::TestCase
69
69
 
70
70
  assert epsilon < MAXIMUM_EPSILON
71
71
  end
72
-
72
+
73
73
  should "generate random numbers from triangular(0, 1, 1) in the range [0, 1]" do
74
74
  SAMPLE_SIZE.times do
75
75
  t = @r.triangular(0.0, 1.0, 1.0)
@@ -77,7 +77,7 @@ class TestSimpleRandom < Test::Unit::TestCase
77
77
  assert t >= 0.0
78
78
  end
79
79
  end
80
-
80
+
81
81
  should "generate random numbers from triangular(0, 1, 1) with mean approximately 0.66" do
82
82
  a = 0.0
83
83
  c = 1.0
@@ -120,4 +120,117 @@ class TestSimpleRandom < Test::Unit::TestCase
120
120
  assert @r.weibull(5, 2.3)
121
121
  end
122
122
  end
123
+
124
+ context "A multi-threaded simple random number generator" do
125
+ setup do
126
+ @r = MultiThreadedSimpleRandom.instance
127
+ end
128
+
129
+ should "generate random numbers from a uniform distribution in the interval (0, 1)" do
130
+ SAMPLE_SIZE.times do
131
+ u = @r.uniform
132
+ assert u < 1
133
+ assert u > 0
134
+ end
135
+ end
136
+
137
+ should "generate uniformly random numbers with mean approximately 0.5" do
138
+ numbers = generate_numbers(@r, :uniform)
139
+ epsilon = (0.5 - numbers.mean).abs
140
+
141
+ assert epsilon < MAXIMUM_EPSILON
142
+ end
143
+
144
+ should "generate random numbers from a normal distribution with mean approximately 0" do
145
+ numbers = generate_numbers(@r, :normal)
146
+ epsilon = (0.0 - numbers.mean).abs
147
+
148
+ assert epsilon < MAXIMUM_EPSILON
149
+ end
150
+
151
+ should "generate random numbers from a normal distribution with sample standard deviation approximately 1" do
152
+ numbers = generate_numbers(@r, :normal)
153
+ epsilon = (1.0 - numbers.standard_deviation).abs
154
+
155
+ assert epsilon < MAXIMUM_EPSILON
156
+ end
157
+
158
+ should "generate random numbers from an exponential distribution with mean approximately 1" do
159
+ numbers = generate_numbers(@r, :exponential)
160
+ epsilon = (1.0 - numbers.mean).abs
161
+
162
+ assert epsilon < MAXIMUM_EPSILON
163
+ end
164
+
165
+ should "generate random numbers from triangular(0, 1, 1) in the range [0, 1]" do
166
+ SAMPLE_SIZE.times do
167
+ t = @r.triangular(0.0, 1.0, 1.0)
168
+ assert t <= 1.0
169
+ assert t >= 0.0
170
+ end
171
+ end
172
+
173
+ should "generate random numbers from triangular(0, 1, 1) with mean approximately 0.66" do
174
+ a = 0.0
175
+ c = 1.0
176
+ b = 1.0
177
+ numbers = generate_numbers(@r, :triangular, a, c, b)
178
+ mean = (a + b + c) / 3
179
+ epsilon = (mean - numbers.mean).abs
180
+
181
+ assert epsilon < MAXIMUM_EPSILON
182
+ end
183
+
184
+ should "generate random numbers from triangular(0, 1, 1) with standard deviation approximately 0.23" do
185
+ a = 0.0
186
+ c = 1.0
187
+ b = 1.0
188
+ numbers = generate_numbers(@r, :triangular, a, c, b)
189
+ std_dev = Math.sqrt((a**2 + b**2 + c**2 - a*b - a*c - b*c) / 18)
190
+ epsilon = (std_dev - numbers.standard_deviation).abs
191
+
192
+ assert epsilon < MAXIMUM_EPSILON
193
+ end
194
+
195
+ should "generate a random number sampled from a gamma distribution" do
196
+ assert @r.gamma(5, 2.3)
197
+ end
198
+
199
+ should "generate a random number sampled from an inverse gamma distribution" do
200
+ assert @r.inverse_gamma(5, 2.3)
201
+ end
202
+
203
+ should "generate a random number sampled from a beta distribution" do
204
+ assert @r.beta(5, 2.3)
205
+ end
206
+
207
+ should "generate a random number sampled from a chi-square distribution" do
208
+ assert @r.chi_square(10)
209
+ end
210
+
211
+ should "generate a random number using weibull" do
212
+ assert @r.weibull(5, 2.3)
213
+ end
214
+
215
+ should "work independently in every thread" do
216
+ sample_count = 10
217
+ thread_count = 10
218
+
219
+ samples = Hash.new { |hash, key| hash[key] = [] }
220
+
221
+ threads = Array.new(thread_count) do
222
+ Thread.new do
223
+ sample_count.times do
224
+ samples[Thread.current.object_id] << MultiThreadedSimpleRandom.instance.uniform
225
+ end
226
+ end
227
+ end
228
+
229
+ threads.map(&:join)
230
+
231
+ samples = samples.values
232
+ assert samples.size == thread_count
233
+ assert samples.uniq.size == 1
234
+ end
235
+ end
123
236
  end
metadata CHANGED
@@ -1,88 +1,145 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: simple-random
3
- version: !ruby/object:Gem::Version
4
- hash: 55
5
- prerelease:
6
- segments:
7
- - 0
8
- - 10
9
- - 0
10
- version: 0.10.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - John D. Cook
14
8
  - Jason Adams
15
9
  autorequire:
16
10
  bindir: bin
17
11
  cert_chain: []
18
-
19
- date: 2014-03-31 00:00:00 Z
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2014-07-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: minitest
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
22
29
  name: shoulda
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rdoc
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ~>
47
+ - !ruby/object:Gem::Version
48
+ version: '3.12'
49
+ type: :development
23
50
  prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: '3.12'
56
+ - !ruby/object:Gem::Dependency
57
+ name: bundler
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: '1.0'
33
63
  type: :development
34
- version_requirements: *id001
35
- description: Simple Random Number Generator including Beta, Cauchy, Chi square, Exponential, Gamma, Inverse Gamma, Laplace (double exponential), Normal, Student t, Uniform, and Weibull. Ported from John D. Cook's C# Code.
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '1.0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: jeweler
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 2.0.1
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ~>
82
+ - !ruby/object:Gem::Version
83
+ version: 2.0.1
84
+ - !ruby/object:Gem::Dependency
85
+ name: simplecov
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ description: Simple Random Number Generator including Beta, Cauchy, Chi square, Exponential,
99
+ Gamma, Inverse Gamma, Laplace (double exponential), Normal, Student t, Uniform,
100
+ and Weibull. Ported from John D. Cook's C# Code.
36
101
  email: jasonmadams@gmail.com
37
102
  executables: []
38
-
39
103
  extensions: []
40
-
41
- extra_rdoc_files:
104
+ extra_rdoc_files:
42
105
  - LICENSE
43
106
  - README.rdoc
44
- files:
107
+ files:
45
108
  - .document
109
+ - Gemfile
110
+ - Gemfile.lock
46
111
  - LICENSE
47
112
  - README.rdoc
48
113
  - Rakefile
49
114
  - VERSION
50
115
  - lib/simple-random.rb
116
+ - lib/simple-random/multi_threaded_simple_random.rb
117
+ - lib/simple-random/simple_random.rb
51
118
  - simple-random.gemspec
52
119
  - test/helper.rb
53
120
  - test/test_simple_random.rb
54
121
  homepage: http://github.com/ealdent/simple-random
55
- licenses:
56
- - Code Project Open License
122
+ licenses:
123
+ - CDDL-1.0
124
+ metadata: {}
57
125
  post_install_message:
58
126
  rdoc_options: []
59
-
60
- require_paths:
127
+ require_paths:
61
128
  - lib
62
- required_ruby_version: !ruby/object:Gem::Requirement
63
- none: false
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- hash: 3
68
- segments:
69
- - 0
70
- version: "0"
71
- required_rubygems_version: !ruby/object:Gem::Requirement
72
- none: false
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- hash: 3
77
- segments:
78
- - 0
79
- version: "0"
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
80
139
  requirements: []
81
-
82
140
  rubyforge_project:
83
- rubygems_version: 1.8.15
141
+ rubygems_version: 2.2.2
84
142
  signing_key:
85
- specification_version: 3
143
+ specification_version: 4
86
144
  summary: Simple Random Number Generator
87
145
  test_files: []
88
-