Sha256: b5a6c91d755927a70c75da2f6e4fd387395742943ef36805b854a682cd5d0e80

Contents?: true

Size: 1.42 KB

Versions: 6

Compression:

Stored size: 1.42 KB

Contents

require(File.expand_path(File.dirname(__FILE__)+'/helpers_tests.rb'))
class StatsampleTestKolmogorovSmirnovTestCase < MiniTest::Unit::TestCase
  context(Statsample::Test::KolmogorovSmirnov) do 
    should "calculate correctly D for two given samples" do
      a=[1.1,2.5,5.6,9]
      b=[1,2.3,5.8,10]
      ks=Statsample::Test::KolmogorovSmirnov.new(a,b)
      assert_equal(0.25,ks.d)
    end
    should "calculate correctly D for a normal sample and Normal Distribution" do
      a=[0.30022510,-0.36664035,0.08593404,1.29881130,-0.49878633,-0.63056010, 0.28397638, -0.04913700,0.03566644,-1.33414346]
      ks=Statsample::Test::KolmogorovSmirnov.new(a,Distribution::Normal)
      assert_in_delta(0.282, ks.d,0.001)
    end
    should "calculate correctly D for a variable normal and Normal Distribution" do
      rng=Distribution::Normal.rng
      a=100.times.map {rng.call}
      ks=Statsample::Test::KolmogorovSmirnov.new(a,Distribution::Normal)
      assert(ks.d<0.15)
    end
    
    context(Statsample::Test::KolmogorovSmirnov::EmpiricDistribution) do
      should "Create a correct empirical distribution for an array" do
        a=[10,9,8,7,6,5,4,3,2,1]
        ed=Statsample::Test::KolmogorovSmirnov::EmpiricDistribution.new(a)
        assert_equal(0, ed.cdf(-2))
        assert_equal(0.5, ed.cdf(5))
        assert_equal(0.5, ed.cdf(5.5))
        assert_equal(0.9, ed.cdf(9))
        assert_equal(1, ed.cdf(11))
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
statsample-1.4.1 test/test_test_kolmogorovsmirnov.rb
statsample-1.4.0 test/test_test_kolmogorovsmirnov.rb
statsample-1.3.1 test/test_test_kolmogorovsmirnov.rb
statsample-1.3.0 test/test_test_kolmogorovsmirnov.rb
statsample-1.2.0 test/test_test_kolmogorovsmirnov.rb
statsample-1.1.0 test/test_test_kolmogorovsmirnov.rb