croupier 2.0.0.rc1 → 2.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +19 -20
  3. data/RUNNING_TESTS.md +11 -4
  4. data/lib/croupier.rb +25 -0
  5. data/lib/croupier/cli/application.rb +1 -1
  6. data/lib/croupier/distribution.rb +76 -7
  7. data/lib/croupier/distributions/bernoulli.rb +5 -11
  8. data/lib/croupier/distributions/binomial.rb +5 -16
  9. data/lib/croupier/distributions/cauchy.rb +4 -15
  10. data/lib/croupier/distributions/credit_card.rb +14 -13
  11. data/lib/croupier/distributions/degenerate.rb +4 -7
  12. data/lib/croupier/distributions/exponential.rb +3 -10
  13. data/lib/croupier/distributions/gamma.rb +9 -18
  14. data/lib/croupier/distributions/geometric.rb +3 -10
  15. data/lib/croupier/distributions/nbinomial.rb +4 -16
  16. data/lib/croupier/distributions/normal.rb +12 -19
  17. data/lib/croupier/distributions/poisson.rb +3 -10
  18. data/lib/croupier/distributions/triangular.rb +7 -22
  19. data/lib/croupier/distributions/uniform.rb +19 -25
  20. data/lib/croupier/version.rb +1 -1
  21. data/test/minitest/distribution_class/test_class_methods.rb +117 -3
  22. data/test/minitest/distribution_class/test_instance_methods.rb +19 -1
  23. data/test/minitest/distribution_generator_class/test_class_methods.rb +1 -1
  24. data/test/minitest/distribution_generator_class/test_instance_methods.rb +1 -1
  25. data/test/minitest/distribution_generators/test_enumerator_block_generator.rb +1 -1
  26. data/test/minitest/distribution_generators/test_enumerator_generator.rb +1 -1
  27. data/test/minitest/distribution_generators/test_inverse_cdf_generator.rb +1 -1
  28. data/test/minitest/distribution_generators/test_minimum_sample_generator.rb +1 -1
  29. data/test/minitest/distributions/test_bernoulli_distribution.rb +1 -1
  30. data/test/minitest/distributions/test_binomial_distribution.rb +1 -1
  31. data/test/minitest/distributions/test_cauchy_distribution.rb +1 -1
  32. data/test/minitest/distributions/test_credit_card_distribution.rb +1 -1
  33. data/test/minitest/distributions/test_degenerate_distribution.rb +6 -1
  34. data/test/minitest/distributions/test_exponential_distribution.rb +1 -1
  35. data/test/minitest/distributions/test_gamma_distribution.rb +1 -1
  36. data/test/minitest/distributions/test_geometric_distribution.rb +1 -1
  37. data/test/minitest/distributions/test_normal_distribution.rb +1 -1
  38. data/test/minitest/distributions/test_poisson_distribution.rb +1 -1
  39. data/test/minitest/distributions/test_triangular_distribution.rb +9 -1
  40. data/test/minitest/distributions/test_uniform_distribution.rb +1 -1
  41. data/test/minitest/test_croupier_module.rb +1 -2
  42. data/test/minitest/test_distribution_generators_module.rb +2 -2
  43. data/test/minitest/test_distributions_module.rb +3 -3
  44. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bf6d755404722c636a61587f2381ca5ff96ff62b
4
- data.tar.gz: 2229632adcaab36de7a98fd4d1d6bca922485a6d
3
+ metadata.gz: 3360595bc4f0222b501d7c3d420c8589050a7a7d
4
+ data.tar.gz: e9e3889ae3c87181b2dcd1552457ecd793ccb5ae
5
5
  SHA512:
6
- metadata.gz: c03a5dcb2b26a88b3d6ccfb0bc205b72576ed9d4e802a10823ffca194ee291b8bbbe650870ba6a522e1c473fdee4216e64a1e6e7b78118366fa9f7182bd0a12f
7
- data.tar.gz: 463e5689dc2fe99f689706925acfa1951689369617b9c4b58598f025e9e222661f79fd13f74976a3e3fff4c51b25053b767633703ca2c627e4639c00528fbab4
6
+ metadata.gz: 0da2b840c987376dd020441e08016582e2d0db6b34c41d064409b2a4777319ff3f7dd2861332f21fb73e85583cab9c9952f31085a9597d3c6fc99c318a2ce52a
7
+ data.tar.gz: 47fa3fc6a2426ac785ca207f2b296687b7fb111a206d8467ed8b9a575aa264056f462233788de785449aa519165e13676dc555e6e29ef63dcdd570419570bb91
data/README.md CHANGED
@@ -9,7 +9,7 @@ Croupier generates random samples of numbers with specific probability distribut
9
9
 
10
10
  You need to have Ruby and Rubygems installed in your system. Then install croupier with:
11
11
 
12
- $ gem install croupier
12
+ $ gem install croupier --pre
13
13
 
14
14
  ## Getting Started
15
15
 
@@ -29,8 +29,8 @@ where:
29
29
 
30
30
  ### Examples
31
31
 
32
- $ croupier uniform 500 # => 500 numbers with uniform distribution in [0,1] (default interval)
33
- $ croupier uniform 125 -min 7 -max 15 # => 125 numbers with uniform distribution in [7,15]
32
+ $ croupier uniform 500 # => 500 numbers with uniform distribution in [0,1) (default interval)
33
+ $ croupier uniform 125 --included 15 --excluded 7 # => 125 numbers with uniform distribution in (7,15]
34
34
  $ croupier exponential 1000 -lambda 1.3 # => 1000 numbers following an exponential distribution with rate 1.3
35
35
 
36
36
  ### Available distributions and options
@@ -40,6 +40,7 @@ Current version implements the following distributions:
40
40
  * Bernoulli
41
41
  * Binomial
42
42
  * Cauchy
43
+ * Credit Card
43
44
  * Degenerate
44
45
  * Exponential
45
46
  * Gamma
@@ -66,38 +67,36 @@ First of all require the croupier library:
66
67
 
67
68
  require 'croupier'
68
69
 
69
- And then use the the distribution you want to generate the sample. You can get just one number (using ```.generate_number```) or an array of any given size (using ```.generate_sample(N)```)
70
+ And then use the the distribution you want to generate the sample. Since version 2.0, all ```Croupier::Distribution```s
71
+ are ```Enumerable```s, and the ```.generate_number``` and ```.generate_sample(n)``` methods are now deprecated.
72
+ ```first``` and ```take(n)``` can be used instead.
70
73
 
71
- dist = Croupier::Distributions::Exponential.new(:lambda => 1.7)
72
- dist.generate_sample(100) #=> returns an array of 100 random numbers following an exponential with rate 1.7
73
- dist.generate_number #=> returns one random number following an exponential with rate 1.7
74
+ dist = Croupier::Distributions.exponential(lambda: 1.7)
75
+ dist.take(100) #=> returns an array of 100 random numbers following an exponential with rate 1.7
76
+ dist.first #=> returns one random number following an exponential with rate 1.7
74
77
 
75
- It's posible to instantiate each Distribution class directly:
78
+ Though it's posible to instantiate each Distribution class directly:
76
79
 
77
- dist = Croupier::Distributions::Exponential.new(:lambda => 1.7)
80
+ dist = Croupier::Distributions::Exponential.new(lambda: 1.7)
78
81
 
79
- or calling Distributions methods:
82
+ calling methods on ```Croupier::Distributions``` (note the final s) module is recommended:
80
83
 
81
- dist = Croupier::Distributions.exponential :lambda => 1.7
84
+ dist = Croupier::Distributions.exponential lambda: 1.7
82
85
 
83
- To get a list of all available distributions/methods in Distributions module call ```list```
86
+ To get a list of all available distributions/methods in ```Distributions``` module call ```list```
84
87
 
85
88
  Croupier::Distributions.list
86
89
 
87
- Distributions have a ```to_enum``` method that return an (infinity) enumerator, so you
88
- can use any Enumerable method on it:
90
+ Distributions' Enumerable behaviour comes from an infinite ```Enumerator::Lazy```. Take this into account
91
+ when calling ```Enumerable``` methods.
89
92
 
90
- dist = Croupier::Distributions.exponential(:lambda => 17).to_enum
93
+ dist = Croupier::Distributions.exponential(lambda: 17)
91
94
  dist.each_slice(2).take(3)
92
95
  => [[0.7455570432863594, 1.6543154039789472], [4.261950709816685, 0.2860058032480469], [1.4761279576207826, 0.6433699882662834]]
93
96
 
94
97
  ## How to generate a new distribution.
95
98
 
96
- There are several ways. The easiest one is to override ```generate_number``` or ```generate_sample``` (one is enough).
97
-
98
- Nonetheless there is another cool way to implement a distribution: implementing ```inv_cdf```:
99
-
100
- ```ìnv_cdf``` receives a parameter ```n``` that is a sample of a uniform distribution. It should return the inverse of the cdf applied to ```n```.
99
+ TO BE COMPLETED WHEN API IS FINISHED.
101
100
 
102
101
  ## License
103
102
 
data/RUNNING_TESTS.md CHANGED
@@ -12,7 +12,14 @@ You can run these tests using the default Rake task:
12
12
 
13
13
  $ rake
14
14
 
15
- ### R tests
15
+ ### R tests (automagic)
16
+
17
+ Make sure you have downloaded all git submodules first since R tests are now a
18
+ dependency. From the 2.0 release, validating the distributions is as simple as running:
19
+
20
+ > rake test:distributions
21
+
22
+ ### R tests (manual steps)
16
23
 
17
24
  There's a group of tests validating the probability distribution of several samples of numbers generated with Croupier.
18
25
  To generate samples to be tested, run the script ```generate_test_data.sh```:
@@ -35,13 +42,13 @@ Other R packages needed:
35
42
  * vcd
36
43
 
37
44
  The test script will try to install all dependencies if they are not found in your R installation.
38
- You can run the test/testsuite.R file:
45
+ You can run the test/rtests.R file:
39
46
 
40
47
  Using Rscript:
41
48
 
42
- $ Rscript testsuite.R
49
+ $ Rscript rtests.R
43
50
 
44
51
  or from the R console:
45
52
 
46
- source('testsuite.R')
53
+ source('rtests.R')
47
54
 
data/lib/croupier.rb CHANGED
@@ -99,5 +99,30 @@ module Croupier
99
99
  def seed
100
100
  random.seed
101
101
  end
102
+
103
+ # Croupier Warn
104
+ #
105
+ # @param *args [String[,String...]] messages
106
+ # @return NilClass
107
+ def warn *args
108
+ if @warn
109
+ args.each {|m| message m }
110
+ end
111
+ end
112
+
113
+ # Activates warning messages (activated by default)
114
+ def activate_warnings
115
+ @warn = true
116
+ end
117
+
118
+ # Deactivates warning messages
119
+ def deactivate_warnings
120
+ @warn = false
121
+ end
122
+
123
+ def warn?
124
+ @warn = true if @warn.nil?
125
+ @warn
126
+ end
102
127
  end
103
128
  end
@@ -27,7 +27,7 @@ module Croupier
27
27
  def run
28
28
  Croupier.trap_interrupt
29
29
  distribution, sample_size, params = parse_distribution_options
30
- distribution.new(params).generate_sample(sample_size).each{|n| Croupier.message n}
30
+ distribution.new(params).take(sample_size).each{|n| Croupier.message n}
31
31
  end
32
32
 
33
33
  private
@@ -62,11 +62,36 @@ module Croupier
62
62
  # @param options [Hash] new cli options
63
63
  # return [Hash] current cli options
64
64
  def cli_options options=nil
65
- @cli_options = options if options
66
- @cli_options || {}
65
+ if options
66
+ cli_banner options[:banner] if options[:banner]
67
+ (options[:options] || []).each do |opt|
68
+ cli_option *opt
69
+ end
70
+ end
71
+ @cli_options ||= {}
67
72
  end
68
73
 
69
- # Sets the cli_name if given
74
+ # Adds an option to the :options Array in cli_options hash.
75
+ #
76
+ # @param option [Symbol] new cli option
77
+ # @param description [String] description of the cli option
78
+ # @param params [Hash] option params for the cli option
79
+ # return [Array] current cli options
80
+ def cli_option option, description, params
81
+ cli_options[:options] ||= []
82
+ define_method_for_option option, params[:type]
83
+ cli_options[:options] << [option, description, params]
84
+ end
85
+
86
+ # Sets the value for the :banner key in cli_options hash.
87
+ #
88
+ # @param banner [String] new cli banner
89
+ # return [String] current cli banner
90
+ def cli_banner banner
91
+ cli_options[:banner] = banner
92
+ end
93
+
94
+ # Sets the cli_name if given.
70
95
  #
71
96
  # @param cli_name [String] new cli name
72
97
  # @return [String] current cli name
@@ -75,6 +100,23 @@ module Croupier
75
100
  @cli_name
76
101
  end
77
102
 
103
+ # Adds an adjustment. And adjustment is the
104
+ # block that will go through a map after the
105
+ # enumerator is created.
106
+ #
107
+ # @param [Proc] block for the map.
108
+ # @returns [Array] procs
109
+ def adjust &block
110
+ adjustments << block
111
+ end
112
+
113
+ # Returns current adjustments.
114
+ #
115
+ # @returns [Array] array of procs.
116
+ def adjustments
117
+ @adjustment ||= []
118
+ end
119
+
78
120
  def default_parameters
79
121
  Hash[(cli_options[:options]||{}).map do |name, desc, hash|
80
122
  [name,hash[:default]]
@@ -91,6 +133,14 @@ module Croupier
91
133
  def respond_to?(method, include_private = false) # :nodoc:
92
134
  ::Croupier::DistributionGenerators.list.include?(method.to_s) || super(method, include_private)
93
135
  end
136
+
137
+ protected
138
+ def define_method_for_option name, type=:float
139
+ name = :"#{name}?" if type == :boolean
140
+ self.send :define_method, name do
141
+ self.params[name.to_sym]
142
+ end
143
+ end
94
144
  end
95
145
 
96
146
  # Initializes Distribution object and adds received options to the distribution parameters.
@@ -135,21 +185,40 @@ module Croupier
135
185
  end
136
186
 
137
187
  # Make Croupier::Distribution an Enumerable
138
- include Enumerable
188
+ # Read the tests for the instance methods.
189
+ # Then, cry.
190
+ Enumerable.instance_methods.each do |method|
191
+ self.send(:define_method, method) do |*args, &block|
192
+ self.to_enum.send(method, *args, &block)
193
+ end
194
+ end
139
195
 
140
196
  def each &block
141
197
  if block_given?
142
- self.to_enum.each &block
198
+ to_enum.each &block
143
199
  else
144
- self.to_enum.each
200
+ to_enum.each
145
201
  end
146
202
  end
147
203
 
204
+ def take n
205
+ to_enum.take(n).to_a
206
+ end
207
+
148
208
  def to_enum
149
- @enum ||= @generator.to_enum.lazy
209
+ @enum ||= apply_adjustments(@generator.to_enum.lazy)
150
210
  end
151
211
 
152
212
  protected
213
+
214
+ def apply_adjustments enum
215
+ self.class.adjustments.inject(enum) do |enum, adj|
216
+ enum.map do |n|
217
+ self.instance_exec(n, &adj)
218
+ end
219
+ end
220
+ end
221
+
153
222
  def create_generator
154
223
  if self.class.generator_class && self.class.generator_block
155
224
  @generator = self.class.generator_class.new self, &self.class.generator_block
@@ -13,25 +13,19 @@ module Croupier
13
13
 
14
14
  cli_name "bernoulli"
15
15
 
16
- cli_options({
17
- options: [
18
- [:success, 'success probability', {type: :float, short: "-p", default: 0.5}]
19
- ],
20
- banner: "Bernoulli distribution. Discrete probability distribution taking value 1 with success probability p and value 0 with failure probability 1-p."
21
- })
16
+ cli_option :success, 'success probability', {type: :float, short: "-p", default: 0.5}
17
+
18
+ cli_banner "Bernoulli distribution. Discrete probability distribution taking value 1 with success probability p and value 0 with failure probability 1-p."
19
+
22
20
 
23
21
  enumerator do |c|
24
- c.binomial(success: success, size: 1).to_enum.lazy
22
+ c.binomial(success: success, size: 1).to_enum
25
23
  end
26
24
 
27
25
  def initialize(options={})
28
26
  super(options)
29
27
  raise Croupier::InputParamsError, "Probability of success must be in the interval [0,1]" if params[:success] > 1 || params[:success] < 0
30
28
  end
31
-
32
- def success
33
- params[:success]
34
- end
35
29
  end
36
30
  end
37
31
  end
@@ -14,13 +14,11 @@ module Croupier
14
14
 
15
15
  cli_name "binomial"
16
16
 
17
- cli_options({
18
- options: [
19
- [:size, 'number of trials', {type: :integer, default: 1}],
20
- [:success, 'success probability of each trial', {type: :float, short: "-p", default: 0.5}]
21
- ],
22
- banner: "Binomial distribution. Discrete probability distribution of the number of successes in a sequence of Bernoulli trials."
23
- })
17
+ cli_option :size, 'number of trials', {type: :integer, default: 1}
18
+ cli_option :success, 'success probability of each trial', {type: :float, short: "-p", default: 0.5}
19
+
20
+ cli_banner "Binomial distribution. Discrete probability distribution of the number of successes in a sequence of Bernoulli trials."
21
+
24
22
 
25
23
  enumerator_block do |y|
26
24
  g = ::Croupier::Distributions.geometric(success: success).to_enum.lazy
@@ -40,15 +38,6 @@ module Croupier
40
38
  super(options)
41
39
  raise Croupier::InputParamsError, "Probability of success must be in the interval [0,1]" if params[:success] > 1 || params[:success] < 0
42
40
  end
43
-
44
- def size
45
- params[:size]
46
- end
47
-
48
- def success
49
- params[:success]
50
- end
51
-
52
41
  end
53
42
  end
54
43
  end
@@ -13,13 +13,10 @@ module Croupier
13
13
 
14
14
  cli_name "cauchy"
15
15
 
16
- cli_options({
17
- options: [
18
- [:location, 'location param', {type: :float, default:0.0}],
19
- [:scale, 'scale param', {type: :float, default: 1.0}],
20
- ],
21
- banner: "Cauchy continuous distribution. Generate numbers following a Cauchy distribution with location and scale parameters"
22
- })
16
+ cli_option :location, 'location param', {type: :float, default:0.0}
17
+ cli_option :scale, 'scale param', {type: :float, default: 1.0}
18
+
19
+ cli_banner "Cauchy continuous distribution. Generate numbers following a Cauchy distribution with location and scale parameters"
23
20
 
24
21
  inv_cdf do |n|
25
22
  location + (scale * Math.tan( Math::PI * (0.5 - n)))
@@ -29,14 +26,6 @@ module Croupier
29
26
  super(options)
30
27
  raise Croupier::InputParamsError, "Invalid scale value, it must be positive" unless params[:scale] > 0
31
28
  end
32
-
33
- def location
34
- params[:location]
35
- end
36
-
37
- def scale
38
- params[:scale]
39
- end
40
29
  end
41
30
  end
42
31
  end
@@ -13,34 +13,35 @@ module Croupier
13
13
 
14
14
  cli_name "credit_card"
15
15
 
16
- cli_options({
17
- options: [
18
- [:master_card, 'master card type', {type: :boolean, default: false}],
19
- [:american_express, 'american express card type', {type: :boolean, default: false}],
20
- [:visa, 'visa card type', {type: :boolean, default: false}],
21
- [:discover, 'discover card type', {type: :boolean, default: false}],
22
- [:initial_values, 'initial values for the credit card. They will be place after card type if one is given.', {type: :string, default: ""}]
23
- ],
24
- banner: "Credit Card distribution. Generate random card numbers"
25
- })
16
+ cli_option :master_card, 'master card type', {type: :boolean, default: false}
17
+ cli_option :american_express, 'american express card type', {type: :boolean, default: false}
18
+ cli_option :visa, 'visa card type', {type: :boolean, default: false}
19
+ cli_option :discover, 'discover card type', {type: :boolean, default: false}
20
+ cli_option :initial_values, 'initial values for the credit card. They will be placed after card type if one is given.', {type: :string, default: ""}
21
+
22
+ cli_banner "Credit Card distribution. Generate random card numbers"
26
23
 
27
24
  # Returns a lambda that completes
28
25
  # the credit card number up to
29
26
  # 15 numbers.
30
- def fill_number
27
+ def self.fill_number
31
28
  ->(n) { "#{n}#{generate_random_string(15-n.size)}"[0..14] }
32
29
  end
33
30
 
34
31
  # Returns a lambda that adds
35
32
  # the checksum number
36
- def add_checksum
33
+ def self.add_checksum
37
34
  ->(n) { "#{n}#{check_digit_for(n)}" }
38
35
  end
39
36
 
40
37
  enumerator do |c|
41
- c.degenerate(constant: init).to_enum.lazy.map(&fill_number).map(&add_checksum)
38
+ c.degenerate(constant: init)
42
39
  end
43
40
 
41
+ adjust &fill_number
42
+
43
+ adjust &add_checksum
44
+
44
45
  def initialize(options={})
45
46
  super(options)
46
47
  end
@@ -12,16 +12,13 @@ module Croupier
12
12
 
13
13
  cli_name "degenerate"
14
14
 
15
- cli_options({
16
- options: [
17
- [:constant, 'value to be returned', {type: :float, default: 42.0}]
18
- ],
19
- banner: "Degenerate distribution. Discrete probability distribution that returns the same value each time."
20
- })
15
+ cli_option :constant, 'value to be returned', {type: :float, default: 42.0}
16
+
17
+ cli_banner "Degenerate distribution. Discrete probability distribution that returns the same value each time."
21
18
 
22
19
  enumerator_block do |y|
23
20
  loop do
24
- y << params[:constant]
21
+ y << constant
25
22
  end
26
23
  end
27
24
 
@@ -14,12 +14,9 @@ module Croupier
14
14
 
15
15
  cli_name "exponential"
16
16
 
17
- cli_options({
18
- options: [
19
- [:lambda, 'rate param', {type: :float, default: 1.0}]
20
- ],
21
- banner: "Exponential distribution. Generate numbers following a exponential distribution for a given lambda rate"
22
- })
17
+ cli_option :lambda, 'rate param', {type: :float, default: 1.0}
18
+
19
+ cli_banner "Exponential distribution. Generate numbers following a exponential distribution for a given lambda rate"
23
20
 
24
21
  inv_cdf do |n|
25
22
  (-1 / lambda) * Math.log(1 - n)
@@ -29,10 +26,6 @@ module Croupier
29
26
  super(options)
30
27
  raise Croupier::InputParamsError, "lambda cannot be negative" if params[:lambda] <= 0
31
28
  end
32
-
33
- def lambda
34
- params[:lambda]
35
- end
36
29
  end
37
30
  end
38
31
  end
@@ -13,30 +13,21 @@ module Croupier
13
13
 
14
14
  cli_name "gamma"
15
15
 
16
- cli_options({
17
- options: [
18
- [:shape, 'shape of the distribution', {type: :float, default: 1.0}],
19
- [:scale, 'scale of the distribution', {type: :float, default: 1.0}]
20
- ],
21
- banner: "Family of continuous distributions with two parameters, shape and scale."
22
- })
16
+ cli_option :shape, 'shape of the distribution', {type: :float, default: 1.0}
17
+ cli_option :scale, 'scale of the distribution', {type: :float, default: 1.0}
23
18
 
24
- enumerator do |c|
25
- c.degenerate(constant: scale).to_enum.lazy.zip(xi_enum, adjust_enum).map do |s,x,a|
26
- s * (x - a)
27
- end
28
- end
19
+ cli_banner "Family of continuous distributions with two parameters, shape and scale."
29
20
 
30
- def initialize(options={})
31
- super(options)
21
+ enumerator do |c|
22
+ c.degenerate(constant: scale).zip(xi_enum, adjust_enum)
32
23
  end
33
24
 
34
- def shape
35
- params[:shape]
25
+ adjust do |scale, xi, adj|
26
+ scale * (xi - adj)
36
27
  end
37
28
 
38
- def scale
39
- params[:scale]
29
+ def initialize(options={})
30
+ super(options)
40
31
  end
41
32
 
42
33
  def delta
@@ -18,12 +18,9 @@ module Croupier
18
18
 
19
19
  cli_name "geometric"
20
20
 
21
- cli_options({
22
- options: [
23
- [:success, 'success probability of each trial', {type: :float, short: "-p", default: 0.5}]
24
- ],
25
- banner: "Geometric distribution. Discrete probability distribution that expresses the number of X Bernoulli trials needed to get one success, supported on the set { 1, 2, 3, ...} }"
26
- })
21
+ cli_option :success, 'success probability of each trial', {type: :float, short: "-p", default: 0.5}
22
+
23
+ cli_banner "Geometric distribution. Discrete probability distribution that expresses the number of X Bernoulli trials needed to get one success, supported on the set { 1, 2, 3, ...} }"
27
24
 
28
25
  # Fair point: it is not the inverse of the cdf,
29
26
  # but it generates the distribution from an uniform.
@@ -35,10 +32,6 @@ module Croupier
35
32
  super(options)
36
33
  raise Croupier::InputParamsError, "Probability of success must be in the interval [0,1]" if params[:success] > 1 || params[:success] < 0
37
34
  end
38
-
39
- def success
40
- params[:success]
41
- end
42
35
  end
43
36
  end
44
37
  end
@@ -16,16 +16,12 @@ module Croupier
16
16
 
17
17
  cli_name "nbinomial"
18
18
 
19
- cli_options({
20
- options: [
21
- [:size, 'number of errors', {type: :integer, default: 1}],
22
- [:success, 'success probability of each trial', {type: :float, short: "-p", default: 0.5}]
23
- ],
24
- banner: "Negative binomial distribution. Discrete probability distribution of the number of successes in a sequence of Bernoulli trials before a specified (non-random) number of failures (denoted size) occur."
25
- })
19
+ cli_option :size, 'number of errors', {type: :integer, default: 1}
20
+ cli_option :success, 'success probability of each trial', {type: :float, short: "-p", default: 0.5}
21
+ cli_banner "Negative binomial distribution. Discrete probability distribution of the number of successes in a sequence of Bernoulli trials before a specified (non-random) number of failures (denoted size) occur."
26
22
 
27
23
  enumerator do |c|
28
- c.geometric(success: success).to_enum.lazy.each_slice(size).map do |x|
24
+ c.geometric(success: success).each_slice(size).map do |x|
29
25
  x.inject(-size,&:+)
30
26
  end
31
27
  end
@@ -34,14 +30,6 @@ module Croupier
34
30
  super(options)
35
31
  raise Croupier::InputParamsError, "Probability of success must be in the interval [0,1]" if params[:success] > 1 || params[:success] < 0
36
32
  end
37
-
38
- def success
39
- params[:success]
40
- end
41
-
42
- def size
43
- params[:size]
44
- end
45
33
  end
46
34
  end
47
35
  end
@@ -14,13 +14,10 @@ module Croupier
14
14
 
15
15
  cli_name "normal"
16
16
 
17
- cli_options({
18
- options: [
19
- [:mean, 'mean of the distribution', {type: :float, default: 0.0}],
20
- [:std, 'standard deviation of the distribution', {type: :float, default: 1.0}]
21
- ],
22
- banner: "Normal distribution. Generate numbers following a continuous distribution in the real line with mean :mean and standard deviation :std."
23
- })
17
+ cli_option :mean, 'mean of the distribution', {type: :float, default: 0.0}
18
+ cli_option :std, 'standard deviation of the distribution', {type: :float, default: 1.0}
19
+
20
+ cli_banner "Normal distribution. Generate numbers following a continuous distribution in the real line with mean :mean and standard deviation :std."
24
21
 
25
22
  minimum_sample do
26
23
  x, y = 1 - ::Croupier.rand, 1 - ::Croupier.rand
@@ -30,22 +27,18 @@ module Croupier
30
27
  ]
31
28
  end
32
29
 
33
- def initialize(options={})
34
- super(options)
30
+ # Adjust std
31
+ adjust do |n|
32
+ n * std
35
33
  end
36
34
 
37
- def std
38
- params[:std]
35
+ # Adjust mean
36
+ adjust do |n|
37
+ n + mean
39
38
  end
40
39
 
41
- def mean
42
- params[:mean]
43
- end
44
-
45
- def to_enum
46
- @generator.to_enum.
47
- map {|x| x * std}. # Adjust standard deviation
48
- map {|x| x + mean} # Adjust mean
40
+ def initialize(options={})
41
+ super(options)
49
42
  end
50
43
  end
51
44
  end
@@ -17,12 +17,9 @@ module Croupier
17
17
 
18
18
  cli_name "poisson"
19
19
 
20
- cli_options({
21
- options: [
22
- [:lambda, 'rate parameter (equal to the mean of the distribution)', {type: :integer, default: 50}]
23
- ],
24
- banner: "Poisson distribution. Discrete probability distribution that expresses the probability of a given number of events occurring in a fixed interval of time."
25
- })
20
+ cli_option :lambda, 'rate parameter (equal to the mean of the distribution)', {type: :integer, default: 50}
21
+
22
+ cli_banner "Poisson distribution. Discrete probability distribution that expresses the probability of a given number of events occurring in a fixed interval of time."
26
23
 
27
24
  enumerator_block do |y|
28
25
  l = Math.exp(-lambda)
@@ -39,10 +36,6 @@ module Croupier
39
36
  def initialize(options={})
40
37
  super(options)
41
38
  end
42
-
43
- def lambda
44
- params[:lambda]
45
- end
46
39
  end
47
40
  end
48
41
  end
@@ -13,14 +13,11 @@ module Croupier
13
13
 
14
14
  cli_name "triangular"
15
15
 
16
- cli_options({
17
- options: [
18
- [:lower, 'lower limit', {type: :float, short: '-a', default: 0.0}],
19
- [:upper, 'upper limit', {type: :float, short: '-b', default: 1.0}],
20
- [:mode, 'mode', {type: :float, short: '-c', default: 0.5}]
21
- ],
22
- banner: "Triangular distribution. Continuous distribution whose support is the interval (a,b), with mode c."
23
- })
16
+ cli_option :lower, 'lower limit', {type: :float, short: '-a', default: 0.0}
17
+ cli_option :upper, 'upper limit', {type: :float, short: '-b', default: 1.0}
18
+ cli_option :mode, 'mode', {type: :float, short: '-c', default: 0.5}
19
+
20
+ cli_banner "Triangular distribution. Continuous distribution whose support is the interval (a,b), with mode c."
24
21
 
25
22
  inv_cdf do |n|
26
23
  if n < @F_c
@@ -33,28 +30,16 @@ module Croupier
33
30
  def initialize(options={})
34
31
  super(options)
35
32
  if params[:lower] >= params[:upper]
36
- warn("Lower limit is greater than upper limit. Changing their values.")
33
+ ::Croupier.warn("Lower limit is greater than upper limit. Changing their values.")
37
34
  params[:lower], params[:upper] = params[:upper], params[:lower]
38
35
  end
39
36
  if params[:mode] < params[:lower] || params[:upper] < params[:mode]
40
- warn("Mode is not in the support. Mode value will be change to median.")
37
+ ::Croupier.warn("Mode is not in the support. Mode value will be change to median.")
41
38
  params[:mode] = (params[:lower]+params[:upper])/2.0;
42
39
  end
43
40
  @F_c = (params[:mode]-params[:lower]).to_f/(params[:upper]-params[:lower])
44
41
  end
45
42
 
46
- def lower
47
- params[:lower]
48
- end
49
-
50
- def upper
51
- params[:upper]
52
- end
53
-
54
- def mode
55
- params[:mode]
56
- end
57
-
58
43
  def range
59
44
  @range ||= upper - lower
60
45
  end
@@ -14,13 +14,24 @@ module Croupier
14
14
 
15
15
  cli_name "uniform"
16
16
 
17
- cli_options({
18
- options: [
19
- [:included, 'interval included value', {type: :float, short: "-i", default: 0.0}],
20
- [:excluded, 'interval excluded value', {type: :float, short: "-e", default: 1.0}]
21
- ],
22
- banner: "Uniform distribution. Generate numbers following a continuous distribution on [a,b] (given a=min(included, excluded) and b=max(included,excluded)) where all points in the interval are equally likely."
23
- })
17
+ cli_option :included, 'interval included value', {type: :float, short: "-i", default: 0.0}
18
+ cli_option :excluded, 'interval excluded value', {type: :float, short: "-e", default: 1.0}
19
+
20
+ cli_banner "Uniform distribution. Generate numbers following a continuous distribution on [a,b] (given a=min(included, excluded) and b=max(included,excluded)) where all points in the interval are equally likely."
21
+
22
+ enumerator_block do |y|
23
+ loop do
24
+ y << ::Croupier.rand
25
+ end
26
+ end
27
+
28
+ adjust do |n|
29
+ exclude_value.(n)
30
+ end
31
+
32
+ adjust do |n|
33
+ min + range * n
34
+ end
24
35
 
25
36
  def initialize(options={})
26
37
  super options
@@ -40,24 +51,7 @@ module Croupier
40
51
  attr_reader :exclude_value, :min, :max, :range
41
52
 
42
53
  def inverted?
43
- params[:included] > params[:excluded]
44
- end
45
-
46
- def to_enum
47
- @enum ||= base_enum.lazy.
48
- map(&exclude_value).
49
- map do |n|
50
- min + range * n
51
- end
52
- end
53
-
54
- protected
55
- def base_enum
56
- Enumerator.new do |y|
57
- loop do
58
- y << Croupier.rand
59
- end
60
- end
54
+ included > excluded
61
55
  end
62
56
  end
63
57
  end
@@ -1,3 +1,3 @@
1
1
  module Croupier
2
- VERSION = "2.0.0.rc1"
2
+ VERSION = "2.0.0.rc2"
3
3
  end
@@ -1,7 +1,11 @@
1
- require 'minitest/autorun'
2
- require 'croupier'
1
+ require "minitest/autorun"
2
+ require "croupier"
3
3
 
4
- class TestDistributionClassClassMethods < MiniTest::Unit::TestCase
4
+ class TestDistributionClassClassMethods < Minitest::Test
5
+
6
+ def distribution_subclass
7
+ Class.new ::Croupier::Distribution
8
+ end
5
9
 
6
10
  def distribution_subclass_with_name name
7
11
  Class.new Croupier::Distribution do
@@ -33,6 +37,12 @@ class TestDistributionClassClassMethods < MiniTest::Unit::TestCase
33
37
  end
34
38
  end
35
39
 
40
+ def distribution_subclass_with_cli_banner banner
41
+ Class.new Croupier::Distribution do
42
+ cli_banner banner
43
+ end
44
+ end
45
+
36
46
  def distribution_subclass_with_cli_name name
37
47
  Class.new Croupier::Distribution do
38
48
  cli_name name
@@ -78,6 +88,65 @@ class TestDistributionClassClassMethods < MiniTest::Unit::TestCase
78
88
  assert_nil Croupier::Distribution.cli_name
79
89
  end
80
90
 
91
+ def test_cli_banner_setter_adds_the_cli_banner
92
+ a = distribution_subclass_with_cli_banner "Instructions for use of this Distribution"
93
+ assert_equal "Instructions for use of this Distribution", a.cli_options[:banner]
94
+ end
95
+
96
+ def test_cli_banner_sets_separated_banners_for_each_subclass
97
+ a = distribution_subclass_with_cli_banner "a"
98
+ b = distribution_subclass_with_cli_banner "b"
99
+ assert_equal "a", a.cli_options[:banner]
100
+ assert_equal "b", b.cli_options[:banner]
101
+ assert_nil Croupier::Distribution.cli_options[:banner]
102
+ end
103
+
104
+ def test_cli_option_setter_adds_a_cli_option
105
+ option = [:abc, "prints ABC", {}]
106
+ a = distribution_subclass_with_name "Test"
107
+ a.cli_option option[0], option[1], option[2]
108
+ assert_equal [option], a.cli_options[:options]
109
+ end
110
+
111
+ def test_cli_option_does_not_delete_previous_cli_options
112
+ opts = {banner: 'Hey', options: [[:a, "A", {type: :boolean}], [:b, "B", {type: :float}]]}
113
+ option = [:abc, "prints ABC", {}]
114
+ a = distribution_subclass_with_cli_options opts
115
+ a.cli_option option[0], option[1], option[2]
116
+ assert_equal (opts[:options] << option), a.cli_options[:options]
117
+ end
118
+
119
+ def test_cli_option_adds_separated_option_for_each_subclass
120
+ optionA = [:abc, "prints ABC", {}]
121
+ optionB = [:xyz, "prints XYZ", {type: :boolean}]
122
+ a = distribution_subclass_with_name "A"
123
+ b = distribution_subclass_with_name "B"
124
+ a.cli_option optionA[0], optionA[1], optionA[2]
125
+ b.cli_option optionB[0], optionB[1], optionB[2]
126
+ assert_equal [optionA], a.cli_options[:options]
127
+ assert_equal [optionB], b.cli_options[:options]
128
+ assert_empty Croupier::Distribution.cli_options
129
+ end
130
+
131
+ def test_cli_option_adds_instance_method
132
+ a = distribution_subclass_with_name "A"
133
+ a.cli_option :cowabunga, "TMNT", {type: :float}
134
+ assert_respond_to a.new, :cowabunga
135
+ end
136
+
137
+ def test_cli_options_adds_instance_method_with_modified_name
138
+ a = distribution_subclass_with_name "A"
139
+ a.cli_option :are_you_my_mummy, "Doctor Who", {type: :boolean}
140
+ assert_respond_to a.new, :are_you_my_mummy?
141
+ end
142
+
143
+ def test_cli_option_defines_an_accessor
144
+ a = distribution_subclass_with_name "A"
145
+ a.cli_option :cowabunga, "TMNT", {type: :float}
146
+ instance = a.new cowabunga: 1.3
147
+ assert_equal 1.3, instance.cowabunga
148
+ end
149
+
81
150
  def test_cli_options_setter_adds_the_options
82
151
  opts = Hash.new
83
152
  a = distribution_subclass_with_cli_options opts
@@ -139,4 +208,49 @@ class TestDistributionClassClassMethods < MiniTest::Unit::TestCase
139
208
  assert_equal pb, b.generator_block
140
209
  assert_nil Croupier::Distribution.generator_block
141
210
  end
211
+
212
+ def test_adjustments_is_empty_at_first
213
+ a = distribution_subclass
214
+ assert_empty a.adjustments, "Adjustments are not empty"
215
+ end
216
+
217
+ def test_adjustment_add_proc_to_adjustments_in_order
218
+ a = distribution_subclass
219
+ proc1 = -> { 1 }
220
+ proc2 = -> { 2 }
221
+ a.adjust &proc1
222
+ a.adjust &proc2
223
+ assert_equal 2, a.adjustments.length
224
+ assert_equal proc1, a.adjustments.first
225
+ assert_equal proc2, a.adjustments.last
226
+ end
227
+
228
+ def test_adjustment_adds_separated_adjustment_for_different_subclasses
229
+ a = distribution_subclass
230
+ a.adjust do |x| 1 end
231
+ b = distribution_subclass
232
+ b.adjust do |x| 2 end
233
+
234
+ assert a.adjustments != b.adjustments
235
+ assert_empty distribution_subclass.adjustments
236
+ end
237
+
238
+ def test_adjustments_are_called_in_order
239
+ a = distribution_subclass
240
+ a.enumerator_block do |y|
241
+ num = 0
242
+ loop do
243
+ num += 1; y << num
244
+ end
245
+ end
246
+ a.adjust do |n|
247
+ n + 3
248
+ end
249
+
250
+ a.adjust do |n|
251
+ n * 2
252
+ end
253
+
254
+ assert_equal [8, 10, 12], a.new.take(3)
255
+ end
142
256
  end
@@ -1,6 +1,6 @@
1
1
  require "minitest/autorun"
2
2
  require "croupier"
3
- class TestDistributionClassInstanceMethods < MiniTest::Unit::TestCase
3
+ class TestDistributionClassInstanceMethods < Minitest::Test
4
4
 
5
5
  def test_distribution_has_name_and_description
6
6
  dist = Croupier::Distribution.new
@@ -53,4 +53,22 @@ class TestDistributionClassInstanceMethods < MiniTest::Unit::TestCase
53
53
  d = c.new
54
54
  assert_kind_of ::Croupier::DistributionGenerators::InverseCDFGenerator, d.generator
55
55
  end
56
+
57
+ # What The Fuck
58
+ # Making ::Croupier::Distribution a subclass of Enumerator::Lazy
59
+ # is a fucking hell. Impossible, as far as I am concerned.
60
+ # Yes, I can say fucking since trying to do so made MRI to break
61
+ # and cry like Captain Hammer at the end of Dr. Horrible.
62
+ # If Enumerable gets just included, we lose the lazy part.
63
+ #
64
+ # My solution, bang my head against the train window and then
65
+ # delegate all the methods to the enum.
66
+ def test_distribution_is_enumerable
67
+ dist = ::Croupier::Distribution.new
68
+
69
+ assert_respond_to dist, :each, "distribution does not respond to each"
70
+ Enumerable.instance_methods.each do |method|
71
+ assert_respond_to dist, method, "distribution does not respond to #{method}"
72
+ end
73
+ end
56
74
  end
@@ -1,7 +1,7 @@
1
1
  require "minitest/autorun"
2
2
  require "croupier"
3
3
 
4
- class DistributionGeneratorClassClassMethods < MiniTest::Unit::TestCase
4
+ class DistributionGeneratorClassClassMethods < Minitest::Test
5
5
 
6
6
  def create_generator_with_method_name name
7
7
  Class.new Croupier::DistributionGenerator do
@@ -1,7 +1,7 @@
1
1
  require "minitest/autorun"
2
2
  require "croupier"
3
3
 
4
- class DistributionGeneratorClassIntanceMethods < MiniTest::Unit::TestCase
4
+ class DistributionGeneratorClassIntanceMethods < Minitest::Test
5
5
 
6
6
  def setup
7
7
  @distribution = Croupier::Distribution.new
@@ -1,7 +1,7 @@
1
1
  require "minitest/autorun"
2
2
  require "croupier"
3
3
 
4
- class TestEnumeratorBlockGenerator < MiniTest::Unit::TestCase
4
+ class TestEnumeratorBlockGenerator < Minitest::Test
5
5
 
6
6
  def setup
7
7
  @klazz = Class.new(::Croupier::Distribution) do
@@ -1,7 +1,7 @@
1
1
  require "minitest/autorun"
2
2
  require "croupier"
3
3
 
4
- class TestEnumeratorGenerator < MiniTest::Unit::TestCase
4
+ class TestEnumeratorGenerator < Minitest::Test
5
5
 
6
6
  def setup
7
7
  @klazz = Class.new(::Croupier::Distribution) do
@@ -1,6 +1,6 @@
1
1
  require "minitest/autorun"
2
2
  require "croupier"
3
- class TestInverseCdfGenerator < MiniTest::Unit::TestCase
3
+ class TestInverseCdfGenerator < Minitest::Test
4
4
 
5
5
  def setup
6
6
  @distribution = ::Croupier::Distribution.new
@@ -1,6 +1,6 @@
1
1
  require "minitest/autorun"
2
2
  require "croupier"
3
- class TestMinimumSampleGenerator < MiniTest::Unit::TestCase
3
+ class TestMinimumSampleGenerator < Minitest::Test
4
4
 
5
5
  def setup
6
6
  @distribution = ::Croupier::Distribution.new
@@ -1,6 +1,6 @@
1
1
  require "minitest/autorun"
2
2
  require "croupier"
3
- class TestBinomialDistribution < MiniTest::Unit::TestCase
3
+ class TestBinomialDistribution < Minitest::Test
4
4
 
5
5
  def bernoulli *args
6
6
  ::Croupier::Distributions.bernoulli *args
@@ -1,6 +1,6 @@
1
1
  require "minitest/autorun"
2
2
  require "croupier"
3
- class TestBinomialDistribution < MiniTest::Unit::TestCase
3
+ class TestBinomialDistribution < Minitest::Test
4
4
 
5
5
  def binomial *args
6
6
  ::Croupier::Distributions.binomial *args
@@ -1,6 +1,6 @@
1
1
  require "minitest/autorun"
2
2
  require "croupier"
3
- class TestCauchyDistribution < MiniTest::Unit::TestCase
3
+ class TestCauchyDistribution < Minitest::Test
4
4
 
5
5
  def cauchy *args
6
6
  ::Croupier::Distributions.cauchy *args
@@ -1,6 +1,6 @@
1
1
  require "minitest/autorun"
2
2
  require "croupier"
3
- class TestDistributionClass < MiniTest::Unit::TestCase
3
+ class TestDistributionClass < Minitest::Test
4
4
 
5
5
  def valid_options(optional={})
6
6
  {}.merge(optional)
@@ -1,6 +1,6 @@
1
1
  require "minitest/autorun"
2
2
  require "croupier"
3
- class TestDegenerateDistribution < MiniTest::Unit::TestCase
3
+ class TestDegenerateDistribution < Minitest::Test
4
4
 
5
5
  def test_distribution_has_name_and_description
6
6
  dist = Croupier::Distributions::Degenerate.new
@@ -8,6 +8,11 @@ class TestDegenerateDistribution < MiniTest::Unit::TestCase
8
8
  assert_respond_to dist, 'description'
9
9
  end
10
10
 
11
+ def test_constant_returns_current_distribution_constant
12
+ dist = Croupier::Distributions::Degenerate.new constant: "Macarena"
13
+ assert_equal "Macarena", dist.constant
14
+ end
15
+
11
16
  def test_returns_only_one_value
12
17
  dist = Croupier::Distributions::Degenerate.new constant: 5.34
13
18
  5.times do
@@ -1,6 +1,6 @@
1
1
  require "minitest/autorun"
2
2
  require "croupier"
3
- class TestExponentialDistribution < MiniTest::Unit::TestCase
3
+ class TestExponentialDistribution < Minitest::Test
4
4
 
5
5
  def exponential *args
6
6
  ::Croupier::Distributions.exponential *args
@@ -1,6 +1,6 @@
1
1
  require "minitest/autorun"
2
2
  require "croupier"
3
- class TestGammaDistribution < MiniTest::Unit::TestCase
3
+ class TestGammaDistribution < Minitest::Test
4
4
 
5
5
  def gamma *args
6
6
  ::Croupier::Distributions.gamma *args
@@ -1,6 +1,6 @@
1
1
  require "minitest/autorun"
2
2
  require "croupier"
3
- class TestGeometricDistribution < MiniTest::Unit::TestCase
3
+ class TestGeometricDistribution < Minitest::Test
4
4
 
5
5
  def geometric *args
6
6
  ::Croupier::Distributions.geometric *args
@@ -1,6 +1,6 @@
1
1
  require "minitest/autorun"
2
2
  require "croupier"
3
- class TestNormalDistribution < MiniTest::Unit::TestCase
3
+ class TestNormalDistribution < Minitest::Test
4
4
  def normal *args
5
5
  ::Croupier::Distributions.normal *args
6
6
  end
@@ -1,6 +1,6 @@
1
1
  require "minitest/autorun"
2
2
  require "croupier"
3
- class TestPoissonDistribution < MiniTest::Unit::TestCase
3
+ class TestPoissonDistribution < Minitest::Test
4
4
 
5
5
  def poisson *args
6
6
  ::Croupier::Distributions.poisson *args
@@ -1,11 +1,19 @@
1
1
  require "minitest/autorun"
2
2
  require "croupier"
3
- class TestTriangularDistribution < MiniTest::Unit::TestCase
3
+ class TestTriangularDistribution < Minitest::Test
4
4
 
5
5
  def triangular(opts={})
6
6
  ::Croupier::Distributions.triangular(opts)
7
7
  end
8
8
 
9
+ def setup
10
+ ::Croupier.deactivate_warnings
11
+ end
12
+
13
+ def teardown
14
+ ::Croupier.activate_warnings
15
+ end
16
+
9
17
  def test_change_lower_and_upper_values_if_they_are_not_in_the_right_order
10
18
  t = triangular lower: 8, upper: 3, mode: 4
11
19
  assert_equal 3, t.lower, "lower is not 3"
@@ -1,6 +1,6 @@
1
1
  require "minitest/autorun"
2
2
  require "croupier"
3
- class TestUniformDistribution < MiniTest::Unit::TestCase
3
+ class TestUniformDistribution < Minitest::Test
4
4
 
5
5
  def uniform(opts={})
6
6
  ::Croupier::Distributions.uniform(opts)
@@ -1,6 +1,6 @@
1
1
  require "minitest/autorun"
2
2
  require "croupier"
3
- class TestCroupierModule < MiniTest::Unit::TestCase
3
+ class TestCroupierModule < Minitest::Test
4
4
 
5
5
  def test_module_manages_a_croupier_cli_application_object
6
6
  app = Croupier.application
@@ -12,5 +12,4 @@ class TestCroupierModule < MiniTest::Unit::TestCase
12
12
  Croupier.application = app
13
13
  assert Croupier.application == app
14
14
  end
15
-
16
15
  end
@@ -1,7 +1,7 @@
1
1
  require "minitest/autorun"
2
2
  require "croupier"
3
3
 
4
- class TestDistributionGeneratorsModule < MiniTest::Unit::TestCase
4
+ class TestDistributionGeneratorsModule < Minitest::Test
5
5
 
6
6
  def test_list_of_all_distribution_generators
7
7
  all = Croupier::DistributionGenerators.all
@@ -27,7 +27,7 @@ class TestDistributionGeneratorsModule < MiniTest::Unit::TestCase
27
27
  assert_includes list, d.method_name, "#{d.method_name} not included in list"
28
28
  }
29
29
  end
30
-
30
+
31
31
  def test_all_and_list_have_same_size
32
32
  all = Croupier::DistributionGenerators.all
33
33
  list = Croupier::DistributionGenerators.list
@@ -1,6 +1,6 @@
1
1
  require "minitest/autorun"
2
2
  require "croupier"
3
- class TestDistributionsModule < MiniTest::Unit::TestCase
3
+ class TestDistributionsModule < Minitest::Test
4
4
 
5
5
  def test_list_of_all_distributions
6
6
  all = Croupier::Distributions.all
@@ -25,13 +25,13 @@ class TestDistributionsModule < MiniTest::Unit::TestCase
25
25
  assert list.include?(d.cli_name), "#{d.cli_name} not included in list"
26
26
  }
27
27
  end
28
-
28
+
29
29
  def test_all_and_list_have_same_size
30
30
  all = Croupier::Distributions.all
31
31
  list = Croupier::Distributions.list
32
32
  assert list.size == all.size
33
33
  end
34
-
34
+
35
35
  def test_dynamic_distribution_methods
36
36
  Croupier::Distributions.list.each{|method|
37
37
  assert Croupier::Distributions.respond_to?(method), "No response for #{method} method"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: croupier
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.rc1
4
+ version: 2.0.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juanjo Bazán
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-24 00:00:00.000000000 Z
12
+ date: 2013-10-22 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Croupier is a Ruby gem to generate a random sample of numbers with a
15
15
  given probability distribution.