require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') include Fathom::Distributions describe Gaussian do before do @opts = {:mean => 0, :sd => 0.1, :confidence_interval => 0.05} end it "should provide a GSL::Rng through rng" do Gaussian.rng.should be_a(GSL::Rng) end it "should be able to generate a random variable through GSL::Rng#gaussian" do Gaussian.rng.should_receive(:gaussian).and_return(0.5) Gaussian.rand(1) end it "should be able to generate an inverse CDF" do Gaussian.inverse_cdf(@opts).should be_within(0.00001).of(-0.16448) end it "should require mean as an option for an inverse CDF" do @opts.delete(:mean) lambda{Gaussian.inverse_cdf(@opts)}.should raise_error end it "should require a Gaussian deviation for an inverse CDF" do @opts.delete(:sd) lambda{Gaussian.inverse_cdf(@opts)}.should raise_error end it "should take std as an alias for sd when creating an inverse CDF" do @opts.delete(:sd) Gaussian.inverse_cdf(@opts.merge(:std => 0.1)).should be_within(0.00001).of(-0.16448) end it "should take standard_deviation as an alias for sd when creating an inverse CDF" do @opts.delete(:sd) Gaussian.inverse_cdf(@opts.merge(:standard_deviation => 0.1)).should be_within(0.00001).of(-0.16448) end it "should be able to set upper to true and get Q instead of P" do Gaussian.inverse_cdf(@opts.merge(:upper =>true)).should be_within(0.00001).of(0.16448) end it "should be able to take a different confidence interval" do Gaussian.inverse_cdf(@opts.merge(:confidence_interval => 0.1)).should be_within(0.00001).of(-0.12815) end it "should have a lower_bound alias for inverse_cdf" do Gaussian.lower_bound(@opts).should eql(Gaussian.inverse_cdf(@opts)) end it "should have an upper_bound shortcut for inverse_cdf(:upper => true, ...)" do Gaussian.upper_bound(@opts).should eql(Gaussian.inverse_cdf(@opts.merge(:upper => true))) end it "should provide interval values, an array of the lower and upper bounds" do Gaussian.interval_values(@opts.merge(:confidence_interval => 0.9)).should eql([Gaussian.lower_bound(@opts), Gaussian.upper_bound(@opts)]) end end