File: exponential_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 (80 lines) | stat: -rw-r--r-- 1,855 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
require File.expand_path(File.dirname(__FILE__)+"/spec_helper.rb")
  
describe Distribution::Exponential do
    
  shared_examples_for "exponential engine" do
    it "should return correct pdf" do
      if @engine.respond_to? :pdf
        [0.5,1,1.5].each {|l|
          1.upto(5) {|x|
            @engine.pdf(x,l).should be_within(1e-10).of(l*Math.exp(-l*x))
          }
        }
      else
        pending("No #{@engine}.pdf")
      end
    end
    
    it "should return correct cdf" do
      if @engine.respond_to? :cdf
        [0.5,1,1.5].each {|l|
          1.upto(5) {|x|
            @engine.cdf(x,l).should be_within(1e-10).of(1-Math.exp(-l*x))
          }
        }
      else
        pending("No #{@engine}.cdf")
      end
    end
  
    
    it "should return correct p_value" do
      if @engine.respond_to? :p_value
        [0.5,1,1.5].each {|l|
          1.upto(5) {|x|
            pr=@engine.cdf(x,l)
            @engine.p_value(pr,l).should be_within(1e-10).of(x)
          }
        }
      else
        pending("No #{@engine}.p_value")
      end
    end
  end
  

  describe "singleton" do
    before do
      @engine=Distribution::Exponential
    end
    it_should_behave_like "exponential engine"
  end
  
  describe Distribution::Exponential::Ruby_ do
    before do
      @engine=Distribution::Exponential::Ruby_
    end
    it_should_behave_like "exponential engine"
    
  end
    
  if Distribution.has_gsl?
    describe Distribution::Exponential::GSL_ do
      before do
        @engine=Distribution::Exponential::GSL_
      end
    it_should_behave_like "exponential engine"
    end
  end
  
#  if Distribution.has_java?
#    describe Distribution::Exponential::Java_ do
#      before do
#        @engine=Distribution::Exponential::Java_
#      end
#    it_should_behave_like "exponential engine"
#    
#    end  
#  end
  
end