Sha256: 651ebe8751ec47dbf1bcb665dd468ac05d64452b1dd3965b403957508cee57e4
Contents?: true
Size: 1.74 KB
Versions: 4
Compression:
Stored size: 1.74 KB
Contents
$:.unshift(File.dirname(__FILE__)+'/../lib/') require 'statsample' require 'test/unit' class StatsampleCrosstabTestCase < Test::Unit::TestCase def initialize(*args) @v1=%w{black blonde black black red black brown black blonde black red black blonde}.to_vector @v2=%w{woman man man woman man man man woman man woman woman man man}.to_vector @ct=Statsample::Crosstab.new(@v1,@v2) super end def test_crosstab_errors e1=%w{black blonde black black red black brown black blonde black} assert_raise ArgumentError do Statsample::Crosstab.new(e1,@v2) end e2=%w{black blonde black black red black brown black blonde black black}.to_vector assert_raise ArgumentError do Statsample::Crosstab.new(e2,@v2) end assert_nothing_raised do Statsample::Crosstab.new(@v1,@v2) end end def test_crosstab_basic assert_equal(%w{black blonde brown red}, @ct.rows_names) assert_equal(%w{man woman}, @ct.cols_names) assert_equal({'black'=>7,'blonde'=>3,'red'=>2,'brown'=>1}, @ct.rows_total) assert_equal({'man'=>8,'woman'=>5}, @ct.cols_total) end def test_crosstab_frequencies fq=@ct.frequencies assert_equal(8,fq.size) sum=fq.inject(0) {|s,x| s+x[1]} assert_equal(13,sum) fr=@ct.frequencies_by_row assert_equal(4,fr.size) assert_equal(%w{black blonde brown red},fr.keys.sort) fc=@ct.frequencies_by_col assert_equal(2,fc.size) assert_equal(%w{man woman},fc.keys.sort) assert_equal(Matrix.rows([[3,4],[3,0],[1,0],[1,1]]),@ct.to_matrix) end def test_expected v1=%w{1 1 1 1 1 0 0 0 0 0}.to_vector v2=%w{0 0 0 0 0 1 1 1 1 1}.to_vector ct=Statsample::Crosstab.new(v1,v2) assert_equal(Matrix[[2.5,2.5],[2.5,2.5]],ct.matrix_expected) end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
statsample-0.7.0 | test/test_crosstab.rb |
statsample-0.6.7 | test/test_crosstab.rb |
statsample-0.6.5 | test/test_crosstab.rb |
statsample-0.6.4 | test/test_crosstab.rb |