distribution 0.7.3 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +4 -6
  3. data/.yardopts +5 -0
  4. data/History.txt +3 -0
  5. data/README.md +87 -44
  6. data/benchmark/binomial_coefficient.rb +19 -23
  7. data/benchmark/binomial_coefficient/experiment.rb +33 -36
  8. data/benchmark/factorial_hash.rb +7 -8
  9. data/benchmark/factorial_method.rb +4 -6
  10. data/benchmark/odd.rb +6 -7
  11. data/benchmark/power.rb +11 -11
  12. data/bin/distribution +26 -26
  13. data/distribution.gemspec +3 -4
  14. data/lib/distribution.rb +55 -96
  15. data/lib/distribution/beta/gsl.rb +10 -5
  16. data/lib/distribution/beta/ruby.rb +3 -1
  17. data/lib/distribution/binomial/ruby.rb +5 -2
  18. data/lib/distribution/bivariatenormal.rb +4 -5
  19. data/lib/distribution/bivariatenormal/gsl.rb +2 -2
  20. data/lib/distribution/bivariatenormal/java.rb +1 -1
  21. data/lib/distribution/bivariatenormal/ruby.rb +245 -254
  22. data/lib/distribution/chisquare.rb +8 -10
  23. data/lib/distribution/chisquare/gsl.rb +24 -19
  24. data/lib/distribution/chisquare/java.rb +1 -1
  25. data/lib/distribution/chisquare/ruby.rb +25 -25
  26. data/lib/distribution/chisquare/statistics2.rb +16 -13
  27. data/lib/distribution/distributable.rb +40 -0
  28. data/lib/distribution/exponential.rb +4 -5
  29. data/lib/distribution/exponential/gsl.rb +13 -9
  30. data/lib/distribution/exponential/ruby.rb +14 -9
  31. data/lib/distribution/f.rb +1 -1
  32. data/lib/distribution/f/gsl.rb +26 -22
  33. data/lib/distribution/f/java.rb +1 -1
  34. data/lib/distribution/f/ruby.rb +16 -19
  35. data/lib/distribution/f/statistics2.rb +22 -19
  36. data/lib/distribution/gamma.rb +5 -7
  37. data/lib/distribution/gamma/gsl.rb +13 -9
  38. data/lib/distribution/gamma/java.rb +1 -1
  39. data/lib/distribution/gamma/ruby.rb +5 -11
  40. data/lib/distribution/hypergeometric.rb +5 -8
  41. data/lib/distribution/hypergeometric/gsl.rb +4 -5
  42. data/lib/distribution/hypergeometric/java.rb +1 -1
  43. data/lib/distribution/hypergeometric/ruby.rb +34 -35
  44. data/lib/distribution/logistic.rb +5 -8
  45. data/lib/distribution/logistic/ruby.rb +13 -8
  46. data/lib/distribution/lognormal.rb +5 -7
  47. data/lib/distribution/lognormal/gsl.rb +8 -6
  48. data/lib/distribution/lognormal/ruby.rb +5 -9
  49. data/lib/distribution/math_extension.rb +6 -15
  50. data/lib/distribution/math_extension/chebyshev_series.rb +281 -272
  51. data/lib/distribution/math_extension/erfc.rb +26 -29
  52. data/lib/distribution/math_extension/exponential_integral.rb +17 -17
  53. data/lib/distribution/math_extension/gammastar.rb +19 -20
  54. data/lib/distribution/math_extension/gsl_utilities.rb +12 -12
  55. data/lib/distribution/math_extension/incomplete_beta.rb +52 -61
  56. data/lib/distribution/math_extension/incomplete_gamma.rb +166 -168
  57. data/lib/distribution/math_extension/log_utilities.rb +20 -22
  58. data/lib/distribution/normal.rb +11 -13
  59. data/lib/distribution/normal/gsl.rb +13 -10
  60. data/lib/distribution/normal/java.rb +14 -13
  61. data/lib/distribution/normal/ruby.rb +68 -58
  62. data/lib/distribution/normal/statistics2.rb +5 -2
  63. data/lib/distribution/normalmultivariate.rb +64 -64
  64. data/lib/distribution/poisson.rb +11 -13
  65. data/lib/distribution/poisson/gsl.rb +7 -7
  66. data/lib/distribution/poisson/java.rb +19 -24
  67. data/lib/distribution/poisson/ruby.rb +38 -9
  68. data/lib/distribution/shorthand.rb +17 -0
  69. data/lib/distribution/t.rb +13 -15
  70. data/lib/distribution/t/gsl.rb +27 -24
  71. data/lib/distribution/t/java.rb +1 -1
  72. data/lib/distribution/t/ruby.rb +99 -100
  73. data/lib/distribution/t/statistics2.rb +19 -19
  74. data/lib/distribution/uniform.rb +26 -0
  75. data/lib/distribution/uniform/gsl.rb +36 -0
  76. data/lib/distribution/uniform/ruby.rb +91 -0
  77. data/lib/distribution/version.rb +1 -1
  78. data/lib/distribution/weibull.rb +6 -7
  79. data/lib/distribution/weibull/gsl.rb +16 -16
  80. data/lib/distribution/weibull/ruby.rb +30 -23
  81. data/spec/beta_spec.rb +45 -47
  82. data/spec/binomial_spec.rb +77 -85
  83. data/spec/bivariatenormal_spec.rb +28 -35
  84. data/spec/chisquare_spec.rb +48 -52
  85. data/spec/distribution_spec.rb +10 -10
  86. data/spec/exponential_spec.rb +44 -49
  87. data/spec/f_spec.rb +4 -4
  88. data/spec/gamma_spec.rb +50 -53
  89. data/spec/hypergeometric_spec.rb +63 -69
  90. data/spec/logistic_spec.rb +32 -37
  91. data/spec/lognormal_spec.rb +25 -31
  92. data/spec/math_extension_spec.rb +192 -210
  93. data/spec/normal_spec.rb +80 -73
  94. data/spec/poisson_spec.rb +63 -41
  95. data/spec/shorthand_spec.rb +19 -22
  96. data/spec/spec_helper.rb +8 -9
  97. data/spec/t_spec.rb +63 -77
  98. data/spec/uniform_spec.rb +154 -0
  99. data/spec/weibull_spec.rb +13 -14
  100. metadata +17 -8
@@ -1,67 +1,62 @@
1
- require File.expand_path(File.dirname(__FILE__)+"/spec_helper.rb")
2
-
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper.rb')
2
+
3
3
  describe Distribution::Logistic do
4
-
5
- shared_examples_for "logistic engine" do
6
- it "should return correct pdf" do
4
+ shared_examples_for 'logistic engine' do
5
+ it 'should return correct pdf' do
7
6
  if @engine.respond_to? :pdf
8
7
  1.upto(10) {
9
- u=rand()
10
- s=rand()+1
11
- x=rand()*100-50
12
- exp=Math.exp(-(x-u) / s) / (s*(1+Math.exp(-(x-u) / s)**2))
13
- @engine.pdf(x,u,s).should eq(exp)
8
+ u = rand
9
+ s = rand + 1
10
+ x = rand * 100 - 50
11
+ exp = Math.exp(-(x - u) / s) / (s * (1 + Math.exp(-(x - u) / s)**2))
12
+ expect(@engine.pdf(x, u, s)).to eq(exp)
14
13
  }
15
14
  else
16
15
  pending("No #{@engine}.pdf")
17
16
  end
18
17
  end
19
-
20
- it "should return correct cdf" do
18
+
19
+ it 'should return correct cdf' do
21
20
  if @engine.respond_to? :cdf
22
21
  1.upto(100) {
23
- u=rand()
24
- s=rand()*100
25
- x=rand()*100-50
26
- exp=1/(1+Math.exp(-(x-u) / s))
27
-
28
- @engine.cdf(x,u,s).should eq(exp)
22
+ u = rand
23
+ s = rand * 100
24
+ x = rand * 100 - 50
25
+ exp = 1 / (1 + Math.exp(-(x - u) / s))
26
+
27
+ expect(@engine.cdf(x, u, s)).to eq(exp)
29
28
  }
30
-
29
+
31
30
  else
32
31
  pending("No #{@engine}.cdf")
33
32
  end
34
33
  end
35
-
36
-
37
- it "should return correct p_value" do
34
+
35
+ it 'should return correct p_value' do
38
36
  if @engine.respond_to? :p_value
39
- 1.upto(9) {|i|
40
- u=rand()
41
- s=rand()*100
42
- x=@engine.p_value(i/10.0,u,s)
43
- @engine.cdf(x,u,s).should be_within(1e-10).of(i/10.0)
44
- }
37
+ 1.upto(9) {|i|
38
+ u = rand
39
+ s = rand * 100
40
+ x = @engine.p_value(i / 10.0, u, s)
41
+ expect(@engine.cdf(x, u, s)).to be_within(1e-10).of(i / 10.0)
42
+ }
45
43
  else
46
44
  pending("No #{@engine}.cdf")
47
45
  end
48
46
  end
49
47
  end
50
-
51
48
 
52
- describe "singleton" do
49
+ describe 'singleton' do
53
50
  before do
54
- @engine=Distribution::Logistic
51
+ @engine = Distribution::Logistic
55
52
  end
56
- it_should_behave_like "logistic engine"
53
+ it_should_behave_like 'logistic engine'
57
54
  end
58
-
55
+
59
56
  describe Distribution::Logistic::Ruby_ do
60
57
  before do
61
- @engine=Distribution::Logistic::Ruby_
58
+ @engine = Distribution::Logistic::Ruby_
62
59
  end
63
- it_should_behave_like "logistic engine"
64
-
60
+ it_should_behave_like 'logistic engine'
65
61
  end
66
-
67
62
  end
@@ -1,60 +1,54 @@
1
- require File.expand_path(File.dirname(__FILE__)+"/spec_helper.rb")
2
-
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper.rb')
2
+
3
3
  describe Distribution::LogNormal do
4
-
5
- shared_examples_for "log-normal engine" do
6
- it "should return correct pdf" do
4
+ shared_examples_for 'log-normal engine' do
5
+ it 'should return correct pdf' do
7
6
  if @engine.respond_to? :pdf
8
7
  1.upto(10) {
9
- u=rand()
10
- s=rand()*100
11
- x=rand()*50
12
- exp=(1.0/(x*s*Math.sqrt(2*Math::PI)))*Math.exp(-((Math.log(x)-u)**2 / (2*s**2)))
13
- @engine.pdf(x,u,s).should be_within(1e-10).of(exp)
8
+ u = rand
9
+ s = rand * 100
10
+ x = rand * 50
11
+ exp = (1.0 / (x * s * Math.sqrt(2 * Math::PI))) * Math.exp(-((Math.log(x) - u)**2 / (2 * s**2)))
12
+ expect(@engine.pdf(x, u, s)).to be_within(1e-10).of(exp)
14
13
  }
15
14
  else
16
15
  pending("No #{@engine}.pdf")
17
16
  end
18
17
  end
19
- it "should return correct cdf" do
18
+ it 'should return correct cdf' do
20
19
  if @engine.respond_to? :cdf
21
20
  1.upto(10) {
22
- u=rand()
23
- s=rand()*100
24
- x=rand()*50
25
- exp=Distribution::Normal.cdf((Math.log(x) - u) / s)
26
- @engine.cdf(x,u,s).should be_within(1e-10).of(exp)
21
+ u = rand
22
+ s = rand * 100
23
+ x = rand * 50
24
+ exp = Distribution::Normal.cdf((Math.log(x) - u) / s)
25
+ expect(@engine.cdf(x, u, s)).to be_within(1e-10).of(exp)
27
26
  }
28
27
  else
29
28
  pending("No #{@engine}.cdf")
30
29
  end
31
30
  end
32
-
33
31
  end
34
-
35
- describe "singleton" do
32
+
33
+ describe 'singleton' do
36
34
  before do
37
- @engine=Distribution::LogNormal
35
+ @engine = Distribution::LogNormal
38
36
  end
39
- it_should_behave_like "log-normal engine"
37
+ it_should_behave_like 'log-normal engine'
40
38
  end
41
-
39
+
42
40
  describe Distribution::LogNormal::Ruby_ do
43
41
  before do
44
- @engine=Distribution::LogNormal::Ruby_
42
+ @engine = Distribution::LogNormal::Ruby_
45
43
  end
46
- it_should_behave_like "log-normal engine"
47
-
44
+ it_should_behave_like 'log-normal engine'
48
45
  end
49
46
  if Distribution.has_gsl?
50
47
  describe Distribution::LogNormal::GSL_ do
51
48
  before do
52
- @engine=Distribution::LogNormal::GSL_
49
+ @engine = Distribution::LogNormal::GSL_
53
50
  end
54
- it_should_behave_like "log-normal engine"
51
+ it_should_behave_like 'log-normal engine'
55
52
  end
56
- end
57
-
58
-
59
-
53
+ end
60
54
  end
@@ -1,281 +1,263 @@
1
- require File.expand_path(File.dirname(__FILE__)+"/spec_helper.rb")
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper.rb')
2
2
  include ExampleWithGSL
3
3
  describe Distribution::MathExtension do
4
- it "binomial coefficient should be correctly calculated" do
5
- n=50
4
+ it 'binomial coefficient should be correctly calculated' do
5
+ n = 50
6
6
  n.times do |k|
7
- Math.binomial_coefficient(n,k).should eq(Math.factorial(n).quo(Math.factorial(k)*Math.factorial(n-k))),"not correct for k=#{k}"
7
+ expect(Math.binomial_coefficient(n, k)).to eq(Math.factorial(n).quo(Math.factorial(k) * Math.factorial(n - k))), "not correct for k=#{k}"
8
8
  end
9
9
  end
10
10
 
11
- it "ChebyshevSeries for :sin should return correct values" do
12
- #Math::SIN_CS.evaluate()
11
+ it 'ChebyshevSeries for :sin should return correct values' do
12
+ # Math::SIN_CS.evaluate()
13
13
  end
14
14
 
15
- it "log_1plusx_minusx should return correct values" do
15
+ it 'log_1plusx_minusx should return correct values' do
16
16
  # Tests from GSL-1.9
17
- Math::Log.log_1plusx_minusx(1.0e-10).should be_within(1e-10).of(-4.999999999666666667e-21)
18
- Math::Log.log_1plusx_minusx(1.0e-8).should be_within(1e-10).of(-4.999999966666666917e-17)
19
- Math::Log.log_1plusx_minusx(1.0e-4).should be_within(1e-10).of(-4.999666691664666833e-09)
20
- Math::Log.log_1plusx_minusx(0.1).should be_within(1e-10).of(-0.004689820195675139956)
21
- Math::Log.log_1plusx_minusx(0.49).should be_within(1e-10).of(-0.09122388004263222704)
22
-
23
- Math::Log.log_1plusx_minusx(-0.49).should be_within(1e-10).of(-0.18334455326376559639)
24
- Math::Log.log_1plusx_minusx(1.0).should be_within(1e-10).of(Math::LN2 - 1.0)
25
- Math::Log.log_1plusx_minusx(-0.99).should be_within(1e-10).of(-3.615170185988091368)
17
+ expect(Math::Log.log_1plusx_minusx(1.0e-10)).to be_within(1e-10).of(-4.999999999666666667e-21)
18
+ expect(Math::Log.log_1plusx_minusx(1.0e-8)).to be_within(1e-10).of(-4.999999966666666917e-17)
19
+ expect(Math::Log.log_1plusx_minusx(1.0e-4)).to be_within(1e-10).of(-4.999666691664666833e-09)
20
+ expect(Math::Log.log_1plusx_minusx(0.1)).to be_within(1e-10).of(-0.004689820195675139956)
21
+ expect(Math::Log.log_1plusx_minusx(0.49)).to be_within(1e-10).of(-0.09122388004263222704)
22
+
23
+ expect(Math::Log.log_1plusx_minusx(-0.49)).to be_within(1e-10).of(-0.18334455326376559639)
24
+ expect(Math::Log.log_1plusx_minusx(1.0)).to be_within(1e-10).of(Math::LN2 - 1.0)
25
+ expect(Math::Log.log_1plusx_minusx(-0.99)).to be_within(1e-10).of(-3.615170185988091368)
26
26
  end
27
27
 
28
- it "log_1plusx should return correct values" do
28
+ it 'log_1plusx should return correct values' do
29
29
  # Tests from GSL-1.9
30
- Math::Log.log_1plusx(1.0e-10).should be_within(1e-10).of(9.999999999500000000e-11)
31
- Math::Log.log_1plusx(1.0e-8).should be_within(1e-10).of(9.999999950000000333e-09)
32
- Math::Log.log_1plusx(1.0e-4).should be_within(1e-10).of(0.00009999500033330833533)
33
- Math::Log.log_1plusx(0.1).should be_within(1e-10).of(0.09531017980432486004)
34
- Math::Log.log_1plusx(0.49).should be_within(1e-10).of(0.3987761199573677730)
35
-
36
- Math::Log.log_1plusx(-0.49).should be_within(1e-10).of(-0.6733445532637655964)
37
- Math::Log.log_1plusx(1.0).should be_within(1e-10).of(Math::LN2)
38
- Math::Log.log_1plusx(-0.99).should be_within(1e-10).of(-4.605170185988091368)
30
+ expect(Math::Log.log_1plusx(1.0e-10)).to be_within(1e-10).of(9.999999999500000000e-11)
31
+ expect(Math::Log.log_1plusx(1.0e-8)).to be_within(1e-10).of(9.999999950000000333e-09)
32
+ expect(Math::Log.log_1plusx(1.0e-4)).to be_within(1e-10).of(0.00009999500033330833533)
33
+ expect(Math::Log.log_1plusx(0.1)).to be_within(1e-10).of(0.09531017980432486004)
34
+ expect(Math::Log.log_1plusx(0.49)).to be_within(1e-10).of(0.3987761199573677730)
35
+
36
+ expect(Math::Log.log_1plusx(-0.49)).to be_within(1e-10).of(-0.6733445532637655964)
37
+ expect(Math::Log.log_1plusx(1.0)).to be_within(1e-10).of(Math::LN2)
38
+ expect(Math::Log.log_1plusx(-0.99)).to be_within(1e-10).of(-4.605170185988091368)
39
39
  end
40
40
 
41
- it "log_beta should return correct values" do
42
- Math::Beta.log_beta(1.0e-8, 1.0e-8).first.should be_within(1e-10).of(19.113827924512310617)
43
- Math::Beta.log_beta(1.0e-8, 0.01).first.should be_within(1e-10).of(18.420681743788563403)
44
- Math::Beta.log_beta(1.0e-8, 1.0).first.should be_within(1e-10).of(18.420680743952365472)
45
- Math::Beta.log_beta(1.0e-8, 10.0).first.should be_within(1e-10).of(18.420680715662683009)
46
- Math::Beta.log_beta(1.0e-8, 1000.0).first.should be_within(1e-10).of(18.420680669107656949)
47
- Math::Beta.log_beta(0.1, 0.1).first.should be_within(1e-10).of(2.9813614810376273949)
48
- Math::Beta.log_beta(0.1, 1.0).first.should be_within(1e-10).of(2.3025850929940456840)
49
- Math::Beta.log_beta(0.1, 100.0).first.should be_within(1e-10).of(1.7926462324527931217)
50
- Math::Beta.log_beta(0.1, 1000).first.should be_within(1e-10).of(1.5619821298353164928)
51
- Math::Beta.log_beta(1.0, 1.00025).first.should be_within(1e-10).of(-0.0002499687552073570)
52
- Math::Beta.log_beta(1.0, 1.01).first.should be_within(1e-10).of(-0.009950330853168082848)
53
- Math::Beta.log_beta(1.0, 1000.0).first.should be_within(1e-10).of(-6.907755278982137052)
54
- Math::Beta.log_beta(100.0, 100.0).first.should be_within(1e-10).of(-139.66525908670663927)
55
- Math::Beta.log_beta(100.0, 1000.0).first.should be_within(1e-10).of(-336.4348576477366051)
56
- Math::Beta.log_beta(100.0, 1.0e+8).first.should be_within(1e-10).of(-1482.9339185256447309)
41
+ it 'log_beta should return correct values' do
42
+ expect(Math::Beta.log_beta(1.0e-8, 1.0e-8).first).to be_within(1e-10).of(19.113827924512310617)
43
+ expect(Math::Beta.log_beta(1.0e-8, 0.01).first).to be_within(1e-10).of(18.420681743788563403)
44
+ expect(Math::Beta.log_beta(1.0e-8, 1.0).first).to be_within(1e-10).of(18.420680743952365472)
45
+ expect(Math::Beta.log_beta(1.0e-8, 10.0).first).to be_within(1e-10).of(18.420680715662683009)
46
+ expect(Math::Beta.log_beta(1.0e-8, 1000.0).first).to be_within(1e-10).of(18.420680669107656949)
47
+ expect(Math::Beta.log_beta(0.1, 0.1).first).to be_within(1e-10).of(2.9813614810376273949)
48
+ expect(Math::Beta.log_beta(0.1, 1.0).first).to be_within(1e-10).of(2.3025850929940456840)
49
+ expect(Math::Beta.log_beta(0.1, 100.0).first).to be_within(1e-10).of(1.7926462324527931217)
50
+ expect(Math::Beta.log_beta(0.1, 1000).first).to be_within(1e-10).of(1.5619821298353164928)
51
+ expect(Math::Beta.log_beta(1.0, 1.00025).first).to be_within(1e-10).of(-0.0002499687552073570)
52
+ expect(Math::Beta.log_beta(1.0, 1.01).first).to be_within(1e-10).of(-0.009950330853168082848)
53
+ expect(Math::Beta.log_beta(1.0, 1000.0).first).to be_within(1e-10).of(-6.907755278982137052)
54
+ expect(Math::Beta.log_beta(100.0, 100.0).first).to be_within(1e-10).of(-139.66525908670663927)
55
+ expect(Math::Beta.log_beta(100.0, 1000.0).first).to be_within(1e-10).of(-336.4348576477366051)
56
+ expect(Math::Beta.log_beta(100.0, 1.0e+8).first).to be_within(1e-10).of(-1482.9339185256447309)
57
57
  end
58
58
 
59
- it "regularized_beta should return correct values" do
60
- Math.regularized_beta(0.0,1.0, 1.0).should be_within(1e-10).of(0.0)
61
- Math.regularized_beta(1.0, 1.0, 1.0).should be_within(1e-10).of(1.0)
62
- Math.regularized_beta(1.0, 0.1, 0.1).should be_within(1e-10).of(1.0)
63
- Math.regularized_beta(0.5, 1.0, 1.0).should be_within(1e-10).of(0.5)
64
- Math.regularized_beta(0.5, 0.1, 1.0).should be_within(1e-10).of(0.9330329915368074160)
65
- Math.regularized_beta(0.5, 10.0, 1.0).should be_within(1e-10).of(0.0009765625000000000000)
66
- Math.regularized_beta(0.5, 50.0, 1.0).should be_within(1e-10).of(8.881784197001252323e-16)
67
- Math.regularized_beta(0.5, 1.0, 0.1).should be_within(1e-10).of(0.06696700846319258402)
68
- Math.regularized_beta(0.5, 1.0, 10.0).should be_within(1e-10).of(0.99902343750000000000)
69
- Math.regularized_beta(0.5, 1.0, 50.0).should be_within(1e-10).of(0.99999999999999911180)
70
- Math.regularized_beta(0.1, 1.0, 1.0).should be_within(1e-10).of(0.10)
71
- Math.regularized_beta(0.1, 1.0, 2.0).should be_within(1e-10).of(0.19)
72
- Math.regularized_beta(0.9, 1.0, 2.0).should be_within(1e-10).of(0.99)
73
- Math.regularized_beta(0.5, 50.0, 60.0).should be_within(1e-10).of(0.8309072939016694143)
74
- Math.regularized_beta(0.5, 90.0, 90.0).should be_within(1e-10).of(0.5)
75
- Math.regularized_beta(0.5, 500.0, 500.0).should be_within(1e-10).of(0.5)
76
- Math.regularized_beta(0.4, 5000.0, 5000.0).should be_within(1e-10).of(4.518543727260666383e-91)
77
- Math.regularized_beta(0.6, 5000.0, 5000.0).should be_within(1e-10).of(1.0)
78
- Math.regularized_beta(0.6, 5000.0, 2000.0).should be_within(1e-10).of(8.445388773903332659e-89)
59
+ it 'regularized_beta should return correct values' do
60
+ expect(Math.regularized_beta(0.0, 1.0, 1.0)).to be_within(1e-10).of(0.0)
61
+ expect(Math.regularized_beta(1.0, 1.0, 1.0)).to be_within(1e-10).of(1.0)
62
+ expect(Math.regularized_beta(1.0, 0.1, 0.1)).to be_within(1e-10).of(1.0)
63
+ expect(Math.regularized_beta(0.5, 1.0, 1.0)).to be_within(1e-10).of(0.5)
64
+ expect(Math.regularized_beta(0.5, 0.1, 1.0)).to be_within(1e-10).of(0.9330329915368074160)
65
+ expect(Math.regularized_beta(0.5, 10.0, 1.0)).to be_within(1e-10).of(0.0009765625000000000000)
66
+ expect(Math.regularized_beta(0.5, 50.0, 1.0)).to be_within(1e-10).of(8.881784197001252323e-16)
67
+ expect(Math.regularized_beta(0.5, 1.0, 0.1)).to be_within(1e-10).of(0.06696700846319258402)
68
+ expect(Math.regularized_beta(0.5, 1.0, 10.0)).to be_within(1e-10).of(0.99902343750000000000)
69
+ expect(Math.regularized_beta(0.5, 1.0, 50.0)).to be_within(1e-10).of(0.99999999999999911180)
70
+ expect(Math.regularized_beta(0.1, 1.0, 1.0)).to be_within(1e-10).of(0.10)
71
+ expect(Math.regularized_beta(0.1, 1.0, 2.0)).to be_within(1e-10).of(0.19)
72
+ expect(Math.regularized_beta(0.9, 1.0, 2.0)).to be_within(1e-10).of(0.99)
73
+ expect(Math.regularized_beta(0.5, 50.0, 60.0)).to be_within(1e-10).of(0.8309072939016694143)
74
+ expect(Math.regularized_beta(0.5, 90.0, 90.0)).to be_within(1e-10).of(0.5)
75
+ expect(Math.regularized_beta(0.5, 500.0, 500.0)).to be_within(1e-10).of(0.5)
76
+ expect(Math.regularized_beta(0.4, 5000.0, 5000.0)).to be_within(1e-10).of(4.518543727260666383e-91)
77
+ expect(Math.regularized_beta(0.6, 5000.0, 5000.0)).to be_within(1e-10).of(1.0)
78
+ expect(Math.regularized_beta(0.6, 5000.0, 2000.0)).to be_within(1e-10).of(8.445388773903332659e-89)
79
79
  end
80
- it_only_with_gsl "incomplete_beta should return correct values" do
81
-
82
- a=rand()*10+1
83
- b=rand()*10+1
84
- ib = GSL::Function.alloc { |t| t**(a-1)*(1-t)**(b-1)}
80
+ it_only_with_gsl 'incomplete_beta should return correct values' do
81
+ a = rand * 10 + 1
82
+ b = rand * 10 + 1
83
+ ib = GSL::Function.alloc { |t| t**(a - 1) * (1 - t)**(b - 1) }
85
84
  w = GSL::Integration::Workspace.alloc(1000)
86
85
  1.upto(10) {|x|
87
- inte=ib.qag([0,x / 10.0],w)
88
- Math.incomplete_beta(x/10.0, a ,b).should be_within(1e-10).of(inte[0])
86
+ inte = ib.qag([0, x / 10.0], w)
87
+ expect(Math.incomplete_beta(x / 10.0, a, b)).to be_within(1e-10).of(inte[0])
89
88
  }
90
89
  end
91
90
 
92
- it "gammastar should return correct values" do
91
+ it 'gammastar should return correct values' do
93
92
  # Tests from GSL-1.9
94
- Math::Gammastar.evaluate(1.0e-08).should be_within(1e-10).of(3989.423555759890865)
95
- Math::Gammastar.evaluate(1.0e-05).should be_within(1e-10).of(126.17168469882690233)
96
- Math::Gammastar.evaluate(0.001).should be_within(1e-10).of(12.708492464364073506)
97
- Math::Gammastar.evaluate(1.5).should be_within(1e-10).of(1.0563442442685598666)
98
- Math::Gammastar.evaluate(3.0).should be_within(1e-10).of(1.0280645179187893045)
99
- Math::Gammastar.evaluate(9.0).should be_within(1e-10).of(1.0092984264218189715)
100
- Math::Gammastar.evaluate(11.0).should be_within(1e-10).of(1.0076024283104962850)
101
- Math::Gammastar.evaluate(100.0).should be_within(1e-10).of(1.0008336778720121418)
102
- Math::Gammastar.evaluate(1.0e+05).should be_within(1e-10).of(1.0000008333336805529)
103
- Math::Gammastar.evaluate(1.0e+20).should be_within(1e-10).of(1.0)
93
+ expect(Math::Gammastar.evaluate(1.0e-08)).to be_within(1e-10).of(3989.423555759890865)
94
+ expect(Math::Gammastar.evaluate(1.0e-05)).to be_within(1e-10).of(126.17168469882690233)
95
+ expect(Math::Gammastar.evaluate(0.001)).to be_within(1e-10).of(12.708492464364073506)
96
+ expect(Math::Gammastar.evaluate(1.5)).to be_within(1e-10).of(1.0563442442685598666)
97
+ expect(Math::Gammastar.evaluate(3.0)).to be_within(1e-10).of(1.0280645179187893045)
98
+ expect(Math::Gammastar.evaluate(9.0)).to be_within(1e-10).of(1.0092984264218189715)
99
+ expect(Math::Gammastar.evaluate(11.0)).to be_within(1e-10).of(1.0076024283104962850)
100
+ expect(Math::Gammastar.evaluate(100.0)).to be_within(1e-10).of(1.0008336778720121418)
101
+ expect(Math::Gammastar.evaluate(1.0e+05)).to be_within(1e-10).of(1.0000008333336805529)
102
+ expect(Math::Gammastar.evaluate(1.0e+20)).to be_within(1e-10).of(1.0)
104
103
  end
105
104
 
106
- it "erfc_e should return correct values" do
105
+ it 'erfc_e should return correct values' do
107
106
  # From GSL-1.9. For troubleshooting gammq.
108
- Math::erfc_e(-10.0).should be_within(1e-10).of(2.0)
109
- Math::erfc_e(-5.0000002).should be_within(1e-10).of(1.9999999999984625433)
110
- Math::erfc_e(-5.0).should be_within(1e-10).of(1.9999999999984625402)
111
- Math::erfc_e(-1.0).should be_within(1e-10).of(1.8427007929497148693)
112
- Math::erfc_e(-0.5).should be_within(1e-10).of(1.5204998778130465377)
113
- Math::erfc_e(1.0).should be_within(1e-10).of(0.15729920705028513066)
114
- Math::erfc_e(3.0).should be_within(1e-10).of(0.000022090496998585441373)
115
- Math::erfc_e(7.0).should be_within(1e-10).of(4.183825607779414399e-23)
116
- Math::erfc_e(10.0).should be_within(1e-10).of(2.0884875837625447570e-45)
107
+ expect(Math.erfc_e(-10.0)).to be_within(1e-10).of(2.0)
108
+ expect(Math.erfc_e(-5.0000002)).to be_within(1e-10).of(1.9999999999984625433)
109
+ expect(Math.erfc_e(-5.0)).to be_within(1e-10).of(1.9999999999984625402)
110
+ expect(Math.erfc_e(-1.0)).to be_within(1e-10).of(1.8427007929497148693)
111
+ expect(Math.erfc_e(-0.5)).to be_within(1e-10).of(1.5204998778130465377)
112
+ expect(Math.erfc_e(1.0)).to be_within(1e-10).of(0.15729920705028513066)
113
+ expect(Math.erfc_e(3.0)).to be_within(1e-10).of(0.000022090496998585441373)
114
+ expect(Math.erfc_e(7.0)).to be_within(1e-10).of(4.183825607779414399e-23)
115
+ expect(Math.erfc_e(10.0)).to be_within(1e-10).of(2.0884875837625447570e-45)
117
116
  end
118
117
 
118
+ it 'unnormalized_incomplete_gamma with x=0 should return correct values' do
119
+ expect(Math.unnormalized_incomplete_gamma(-1.5, 0)).to be_within(1e-10).of(4.0 * Math.sqrt(Math::PI) / 3.0)
120
+ expect(Math.unnormalized_incomplete_gamma(-0.5, 0)).to be_within(1e-10).of(-2 * Math.sqrt(Math::PI))
121
+ expect(Math.unnormalized_incomplete_gamma(0.5, 0)).to be_within(1e-10).of(Math.sqrt(Math::PI))
122
+ expect(Math.unnormalized_incomplete_gamma(1.0, 0)).to eq 1.0
123
+ expect(Math.unnormalized_incomplete_gamma(1.5, 0)).to be_within(1e-10).of(Math.sqrt(Math::PI) / 2.0)
124
+ expect(Math.unnormalized_incomplete_gamma(2.0, 0)).to eq 1.0
125
+ expect(Math.unnormalized_incomplete_gamma(2.5, 0)).to be_within(1e-10).of(0.75 * Math.sqrt(Math::PI))
126
+
127
+ expect(Math.unnormalized_incomplete_gamma(3.0, 0)).to be_within(1e-12).of(2.0)
119
128
 
120
- it "unnormalized_incomplete_gamma with x=0 should return correct values" do
121
- Math.unnormalized_incomplete_gamma(-1.5, 0).should be_within(1e-10).of(4.0*Math.sqrt(Math::PI) / 3.0)
122
- Math.unnormalized_incomplete_gamma(-0.5, 0).should be_within(1e-10).of(-2*Math.sqrt(Math::PI))
123
- Math.unnormalized_incomplete_gamma(0.5, 0).should be_within(1e-10).of(Math.sqrt(Math::PI))
124
- Math.unnormalized_incomplete_gamma(1.0, 0).should eq 1.0
125
- Math.unnormalized_incomplete_gamma(1.5, 0).should be_within(1e-10).of(Math.sqrt(Math::PI) / 2.0)
126
- Math.unnormalized_incomplete_gamma(2.0, 0).should eq 1.0
127
- Math.unnormalized_incomplete_gamma(2.5, 0).should be_within(1e-10).of(0.75*Math.sqrt(Math::PI))
128
-
129
- Math.unnormalized_incomplete_gamma(3.0, 0).should be_within(1e-12).of(2.0)
130
-
131
- Math.unnormalized_incomplete_gamma(3.5, 0).should be_within(1e-10).of(15.0*Math.sqrt(Math::PI) / 8.0)
132
- Math.unnormalized_incomplete_gamma(4.0, 0).should be_within(1e-12).of(6.0)
129
+ expect(Math.unnormalized_incomplete_gamma(3.5, 0)).to be_within(1e-10).of(15.0 * Math.sqrt(Math::PI) / 8.0)
130
+ expect(Math.unnormalized_incomplete_gamma(4.0, 0)).to be_within(1e-12).of(6.0)
133
131
  end
134
132
 
135
- it "incomplete_gamma should return correct values" do
133
+ it 'incomplete_gamma should return correct values' do
136
134
  # Tests from GSL-1.9
137
- Math.incomplete_gamma(1e-100, 0.001).should be_within(1e-10).of(1.0)
138
- Math.incomplete_gamma(0.001, 0.001).should be_within(1e-10).of(0.9936876467088602902)
139
- Math.incomplete_gamma(0.001, 1.0).should be_within(1e-10).of(0.9997803916424144436)
140
- Math.incomplete_gamma(0.001, 10.0).should be_within(1e-10).of(0.9999999958306921828)
141
- Math.incomplete_gamma(1.0, 0.001).should be_within(1e-10).of(0.0009995001666250083319)
142
- Math.incomplete_gamma(1.0, 1.01).should be_within(1e-10).of(0.6357810204284766802)
143
- Math.incomplete_gamma(1.0, 10.0).should be_within(1e-10).of(0.9999546000702375151)
144
- Math.incomplete_gamma(10.0, 10.01).should be_within(1e-10).of(0.5433207586693410570)
145
- Math.incomplete_gamma(10.0, 20.0).should be_within(1e-10).of(0.9950045876916924128)
146
- Math.incomplete_gamma(1000.0, 1000.1).should be_within(1e-10).of(0.5054666401440661753)
147
- Math.incomplete_gamma(1000.0, 2000.0).should be_within(1e-10).of(1.0)
135
+ expect(Math.incomplete_gamma(1e-100, 0.001)).to be_within(1e-10).of(1.0)
136
+ expect(Math.incomplete_gamma(0.001, 0.001)).to be_within(1e-10).of(0.9936876467088602902)
137
+ expect(Math.incomplete_gamma(0.001, 1.0)).to be_within(1e-10).of(0.9997803916424144436)
138
+ expect(Math.incomplete_gamma(0.001, 10.0)).to be_within(1e-10).of(0.9999999958306921828)
139
+ expect(Math.incomplete_gamma(1.0, 0.001)).to be_within(1e-10).of(0.0009995001666250083319)
140
+ expect(Math.incomplete_gamma(1.0, 1.01)).to be_within(1e-10).of(0.6357810204284766802)
141
+ expect(Math.incomplete_gamma(1.0, 10.0)).to be_within(1e-10).of(0.9999546000702375151)
142
+ expect(Math.incomplete_gamma(10.0, 10.01)).to be_within(1e-10).of(0.5433207586693410570)
143
+ expect(Math.incomplete_gamma(10.0, 20.0)).to be_within(1e-10).of(0.9950045876916924128)
144
+ expect(Math.incomplete_gamma(1000.0, 1000.1)).to be_within(1e-10).of(0.5054666401440661753)
145
+ expect(Math.incomplete_gamma(1000.0, 2000.0)).to be_within(1e-10).of(1.0)
148
146
 
149
147
  # designed to trap the a-x=1 problem
150
148
  # These next two are 1e-7 because they give the same output as GSL, but GSL is apparently not totally accurate here.
151
149
  # It's a problem with log_1plusx_mx (log_1plusx_minusx in my code)
152
- Math.incomplete_gamma(100, 99.0).should be_within(1e-7).of(0.4733043303994607)
153
- Math.incomplete_gamma(200, 199.0).should be_within(1e-7).of(0.4811585880878718)
150
+ expect(Math.incomplete_gamma(100, 99.0)).to be_within(1e-7).of(0.4733043303994607)
151
+ expect(Math.incomplete_gamma(200, 199.0)).to be_within(1e-7).of(0.4811585880878718)
154
152
 
155
153
  # Test for x86 cancellation problems
156
- Math.incomplete_gamma(5670, 4574).should be_within(1e-10).of(3.063972328743934e-55)
154
+ expect(Math.incomplete_gamma(5670, 4574)).to be_within(1e-10).of(3.063972328743934e-55)
157
155
  end
158
156
 
159
- it "gammq should return correct values" do
157
+ it 'gammq should return correct values' do
160
158
  # Tests from GSL-1.9
161
- Math.gammq(0.0, 0.001).should be_within(1e-10).of(0.0)
162
- Math.gammq(0.001, 0.001).should be_within(1e-10).of(0.006312353291139709793)
163
- Math.gammq(0.001, 1.0).should be_within(1e-10).of(0.00021960835758555639171)
164
- Math.gammq(0.001, 2.0).should be_within(1e-10).of(0.00004897691783098147880)
165
- Math.gammq(0.001, 5.0).should be_within(1e-10).of(1.1509813397308608541e-06)
166
- Math.gammq(1.0, 0.001).should be_within(1e-10).of(0.9990004998333749917)
167
- Math.gammq(1.0, 1.01).should be_within(1e-10).of(0.3642189795715233198)
168
- Math.gammq(1.0, 10.0).should be_within(1e-10).of(0.00004539992976248485154)
169
- Math.gammq(10.0, 10.01).should be_within(1e-10).of(0.4566792413306589430)
170
- Math.gammq(10.0, 100.0).should be_within(1e-10).of(1.1253473960842733885e-31)
171
- Math.gammq(1000.0, 1000.1).should be_within(1e-10).of(0.4945333598559338247)
172
- Math.gammq(1000.0, 2000.0).should be_within(1e-10).of(6.847349459614753180e-136)
159
+ expect(Math.gammq(0.0, 0.001)).to be_within(1e-10).of(0.0)
160
+ expect(Math.gammq(0.001, 0.001)).to be_within(1e-10).of(0.006312353291139709793)
161
+ expect(Math.gammq(0.001, 1.0)).to be_within(1e-10).of(0.00021960835758555639171)
162
+ expect(Math.gammq(0.001, 2.0)).to be_within(1e-10).of(0.00004897691783098147880)
163
+ expect(Math.gammq(0.001, 5.0)).to be_within(1e-10).of(1.1509813397308608541e-06)
164
+ expect(Math.gammq(1.0, 0.001)).to be_within(1e-10).of(0.9990004998333749917)
165
+ expect(Math.gammq(1.0, 1.01)).to be_within(1e-10).of(0.3642189795715233198)
166
+ expect(Math.gammq(1.0, 10.0)).to be_within(1e-10).of(0.00004539992976248485154)
167
+ expect(Math.gammq(10.0, 10.01)).to be_within(1e-10).of(0.4566792413306589430)
168
+ expect(Math.gammq(10.0, 100.0)).to be_within(1e-10).of(1.1253473960842733885e-31)
169
+ expect(Math.gammq(1000.0, 1000.1)).to be_within(1e-10).of(0.4945333598559338247)
170
+ expect(Math.gammq(1000.0, 2000.0)).to be_within(1e-10).of(6.847349459614753180e-136)
173
171
 
174
172
  # designed to trap the a-x=1 problem
175
- Math.gammq(100, 99.0).should be_within(1e-10).of(0.5266956696005394)
176
- Math.gammq(200, 199.0).should be_within(1e-10).of(0.5188414119121281)
177
-
178
- # Test for x86 cancellation problems
179
- Math.gammq(5670, 4574).should be_within(1e-10).of(1.0000000000000000)
173
+ expect(Math.gammq(100, 99.0)).to be_within(1e-10).of(0.5266956696005394)
174
+ expect(Math.gammq(200, 199.0)).to be_within(1e-10).of(0.5188414119121281)
180
175
 
176
+ # Test for x86 cancellation problems
177
+ expect(Math.gammq(5670, 4574)).to be_within(1e-10).of(1.0000000000000000)
181
178
 
182
179
  # test suggested by Michel Lespinasse [gsl-discuss Sat, 13 Nov 2004]
183
- Math.gammq(1.0e+06-1.0, 1.0e+06-2.0).should be_within(1e-10).of(0.50026596175224547004)
180
+ expect(Math.gammq(1.0e+06 - 1.0, 1.0e+06 - 2.0)).to be_within(1e-10).of(0.50026596175224547004)
184
181
 
185
182
  # tests in asymptotic regime related to Lespinasse test
186
- Math.gammq(1.0e+06+2.0, 1.0e+06+1.0).should be_within(1e-10).of(0.50026596135330304336)
187
- Math.gammq(1.0e+06, 1.0e+06-2.0).should be_within(1e-10).of(0.50066490399940144811)
188
- Math.gammq(1.0e+07, 1.0e+07-2.0).should be_within(1e-10).of(0.50021026104978614908)
183
+ expect(Math.gammq(1.0e+06 + 2.0, 1.0e+06 + 1.0)).to be_within(1e-10).of(0.50026596135330304336)
184
+ expect(Math.gammq(1.0e+06, 1.0e+06 - 2.0)).to be_within(1e-10).of(0.50066490399940144811)
185
+ expect(Math.gammq(1.0e+07, 1.0e+07 - 2.0)).to be_within(1e-10).of(0.50021026104978614908)
189
186
  end
190
187
 
191
-
192
- it "rising_factorial should return correct values" do
193
-
194
- x=rand(10)+1
195
- Math.rising_factorial(x,0).should eq 1
196
- Math.rising_factorial(x,1).should eq x
197
- Math.rising_factorial(x,2).should eq x**2+x
198
- Math.rising_factorial(x,3).should eq x**3+3*x**2+2*x
199
- Math.rising_factorial(x,4).should eq x**4+6*x**3+11*x**2+6*x
200
-
188
+ it 'rising_factorial should return correct values' do
189
+ x = rand(10) + 1
190
+ expect(Math.rising_factorial(x, 0)).to eq 1
191
+ expect(Math.rising_factorial(x, 1)).to eq x
192
+ expect(Math.rising_factorial(x, 2)).to eq x**2 + x
193
+ expect(Math.rising_factorial(x, 3)).to eq x**3 + 3 * x**2 + 2 * x
194
+ expect(Math.rising_factorial(x, 4)).to eq x**4 + 6 * x**3 + 11 * x**2 + 6 * x
201
195
  end
202
-
203
- it "permutations should return correct values" do
204
- n=rand(50)+50
196
+
197
+ it 'permutations should return correct values' do
198
+ n = rand(50) + 50
205
199
  10.times { |k|
206
- Math.permutations(n,k).should eq(Math.factorial(n) / Math.factorial(n-k))
200
+ expect(Math.permutations(n, k)).to eq(Math.factorial(n) / Math.factorial(n - k))
207
201
  }
208
-
209
-
210
- Math.permutations(n,n).should eq(Math.factorial(n) / Math.factorial(n-n))
202
+
203
+ expect(Math.permutations(n, n)).to eq(Math.factorial(n) / Math.factorial(n - n))
211
204
  end
212
-
213
-
214
- it "exact regularized incomplete beta should behave properly" do
215
-
216
- Math.exact_regularized_beta(0.5,5,5).should be_within(1e-6).of(0.5)
217
- Math.exact_regularized_beta(0.5,5,6).should be_within(1e-6).of(0.6230469)
218
- Math.exact_regularized_beta(0.5,5,7).should be_within(1e-6).of(0.725586)
219
-
220
- a=5
221
- b=5
222
- Math.exact_regularized_beta(0,a,b).should eq 0
223
- Math.exact_regularized_beta(1,a,b).should eq 1
224
- x=rand()
225
-
226
- Math.exact_regularized_beta(x,a,b).should be_within(1e-6). of(1-Math.regularized_beta(1-x,b,a))
227
-
228
-
205
+
206
+ it 'exact regularized incomplete beta should behave properly' do
207
+ expect(Math.exact_regularized_beta(0.5, 5, 5)).to be_within(1e-6).of(0.5)
208
+ expect(Math.exact_regularized_beta(0.5, 5, 6)).to be_within(1e-6).of(0.6230469)
209
+ expect(Math.exact_regularized_beta(0.5, 5, 7)).to be_within(1e-6).of(0.725586)
210
+
211
+ a = 5
212
+ b = 5
213
+ expect(Math.exact_regularized_beta(0, a, b)).to eq 0
214
+ expect(Math.exact_regularized_beta(1, a, b)).to eq 1
215
+ x = rand
216
+
217
+ expect(Math.exact_regularized_beta(x, a, b)).to be_within(1e-6). of(1 - Math.regularized_beta(1 - x, b, a))
229
218
  end
230
-
231
- it "binomial coefficient(gamma) with n<=48 should be correct " do
232
-
233
- [1,5,10,25,48].each {|n|
234
- k=(n/2).to_i
235
- Math.binomial_coefficient_gamma(n,k).round.should eq(Math.binomial_coefficient(n,k))
219
+
220
+ it 'binomial coefficient(gamma) with n<=48 should be correct ' do
221
+ [1, 5, 10, 25, 48].each {|n|
222
+ k = (n / 2).to_i
223
+ expect(Math.binomial_coefficient_gamma(n, k).round).to eq(Math.binomial_coefficient(n, k))
236
224
  }
237
225
  end
238
-
239
- it "binomial coefficient(gamma) with 48<n<1000 should have 11 correct digits" do
240
-
241
- [50,100,200,1000].each {|n|
242
- k=(n/2).to_i
243
- obs=Math.binomial_coefficient_gamma(n, k).to_i.to_s[0,11]
244
- exp=Math.binomial_coefficient(n, k).to_i.to_s[0,11]
245
-
246
- obs.should eq(exp)
226
+
227
+ it 'binomial coefficient(gamma) with 48<n<1000 should have 11 correct digits' do
228
+ [50, 100, 200, 1000].each {|n|
229
+ k = (n / 2).to_i
230
+ obs = Math.binomial_coefficient_gamma(n, k).to_i.to_s[0, 11]
231
+ exp = Math.binomial_coefficient(n, k).to_i.to_s[0, 11]
232
+
233
+ expect(obs).to eq(exp)
247
234
  }
248
235
  end
249
-
250
- describe Distribution::MathExtension::SwingFactorial do
251
236
 
252
- it "Math.factorial should return correct values x<20" do
253
- ac=3628800 # 10!
237
+ describe Distribution::MathExtension::SwingFactorial do
238
+ it 'Math.factorial should return correct values x<20' do
239
+ ac = 3_628_800 # 10!
254
240
  11.upto(19).each do |i|
255
- ac*=i
256
- Math.factorial(i).should eq(ac)
241
+ ac *= i
242
+ expect(Math.factorial(i)).to eq(ac)
257
243
  end
258
244
  end
259
-
260
- it "Math.factorial should return correct values for values 21<x<33" do
261
-
262
- ac=2432902008176640000 # 20!
245
+
246
+ it 'Math.factorial should return correct values for values 21<x<33' do
247
+ ac = 2_432_902_008_176_640_000 # 20!
263
248
  21.upto(33).each do |i|
264
- ac*=i
265
- Math.factorial(i).should eq(ac)
249
+ ac *= i
250
+ expect(Math.factorial(i)).to eq(ac)
266
251
  end
267
-
268
252
  end
269
-
270
- it "Math.factorial should return correct values for values x>33" do
271
-
272
- ac=8683317618811886495518194401280000000 # 33!
273
- Math.factorial(33).should eq ac
253
+
254
+ it 'Math.factorial should return correct values for values x>33' do
255
+ ac = 8_683_317_618_811_886_495_518_194_401_280_000_000 # 33!
256
+ expect(Math.factorial(33)).to eq ac
274
257
  34.upto(40).each do |i|
275
- ac*=i
276
- Math.factorial(i).should eq(ac)
258
+ ac *= i
259
+ expect(Math.factorial(i)).to eq(ac)
277
260
  end
278
-
279
261
  end
280
262
  end
281
263
  end