File: chisquare_spec.rb

package info (click to toggle)
ruby-distribution 0.7.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 624 kB
  • ctags: 379
  • sloc: ruby: 4,283; makefile: 7
file content (90 lines) | stat: -rw-r--r-- 2,328 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
require File.expand_path(File.dirname(__FILE__)+"/spec_helper.rb")
include ExampleWithGSL
describe Distribution::ChiSquare do

shared_examples_for "Chi-square engine(with pdf)" do
    it_only_with_gsl "should return correct pdf" do
      if @engine.respond_to? :pdf
        1.upto(10) do |k|
          v=1+rand(5)
          chi=GSL::Ran.chisq_pdf(v,k)
          @engine.pdf(v,k).should be_within(10e-10).of(chi)
        end
      else
        skip("No #{@engine}.pdf")
      end
    end

end
  
shared_examples_for "Chi-square engine" do

  it_only_with_gsl "should return correct cdf" do
    if @engine.respond_to? :cdf
      1.upto(10) do |k|
        v=1+rand(5)
        chi=GSL::Cdf::chisq_P(v,k)
        @engine.cdf(v,k).should be_within(10e-10).of(chi)
      end
    else
      skip("No #{@engine}.cdf")
    end  
  end

  it "should return correct p_value" do
    if @engine.respond_to? :p_value
      1.upto(10) do |k|
        v=1+rand(5)
        pr=@engine.cdf(v,k)
        @engine.p_value(pr,k).should be_within(10e-4).of(v)
       end
    else
      skip("No #{@engine}.p_value")
    end
  end
end

  describe "singleton" do
    before do
      @engine=Distribution::ChiSquare
    end
    it_should_behave_like "Chi-square engine"
    it_should_behave_like "Chi-square engine(with pdf)"    
  end
  
  describe Distribution::ChiSquare::Ruby_ do
    before do
      @engine=Distribution::ChiSquare::Ruby_
    end
    it_should_behave_like "Chi-square engine"    
    it_should_behave_like "Chi-square engine(with pdf)"    
  end
  if Distribution.has_gsl?
    describe Distribution::ChiSquare::GSL_ do
      before do
        @engine=Distribution::ChiSquare::GSL_
      end
    it_should_behave_like "Chi-square engine"    
    it_should_behave_like "Chi-square engine(with pdf)"    
    end
  end  
  if Distribution.has_statistics2?
    describe Distribution::ChiSquare::Statistics2_ do
      before do
        @engine=Distribution::ChiSquare::Statistics2_
      end
    it_should_behave_like "Chi-square engine"    
    end  
  end
  
  if Distribution.has_java?
    describe Distribution::ChiSquare::Java_ do
      before do
        @engine=Distribution::ChiSquare::Java_
      end
    it_should_behave_like "Chi-square engine"    
    it_should_behave_like "Chi-square engine(with pdf)"    
    end  
  end
  
end