File: f_spec.rb

package info (click to toggle)
ruby-distribution 0.7.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 572 kB
  • ctags: 370
  • sloc: ruby: 4,270; makefile: 5
file content (107 lines) | stat: -rw-r--r-- 2,444 bytes parent folder | download
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
require File.expand_path(File.dirname(__FILE__)+"/spec_helper.rb")

include ExampleWithGSL

describe Distribution::F do
shared_examples_for "F engine(with rng)" do
  it "should return correct rng" do
  pending()
  end
end

shared_examples_for "F engine(with pdf)" do
  it_only_with_gsl "should return correct pdf" do
    if @engine.respond_to? :pdf
      [0.1,0.5,1,2,10,20,30].each{|f|
      [2,5,10].each{|n2|
      [2,5,10].each{|n1|
      @engine.pdf(f,n1,n2).should be_within(1e-4).of(GSL::Ran.fdist_pdf(f,n1,n2))
      }
      }
      }
    else
      pending("No #{@engine}.pdf")
    end
  end
end

shared_examples_for "F engine" do
  
  it_only_with_gsl "should return correct cdf" do
    if @engine.respond_to? :cdf
      [0.1,0.5,1,2,10,20,30].each{|f|
      [2,5,10].each{|n2|
      [2,5,10].each{|n1|
      @engine.cdf(f,n1,n2).should be_within(1e-4).of(GSL::Cdf.fdist_P(f,n1,n2))
      
      }
      }
      }
    else
      pending("No #{@engine}.cdf")
    end
  
  end
  it_only_with_gsl "should return correct p_value" do
    if @engine.respond_to? :p_value
  
    [0.1,0.5,1,2,10,20,30].each{|f|
    [2,5,10].each{|n2|
    [2,5,10].each{|n1|
    area=@engine.cdf(f,n1,n2)
    @engine.p_value(area,n1,n2).should be_within(1e-4).of(GSL::Cdf.fdist_Pinv(area,n1,n2))
    }
    }
    }
  
    
    else
      pending("No #{@engine}.p_value")
    end
  end
end

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