Sha256: 1bdaf89502938cd8836e40c0d61b0d1f0d27c100f43d944be749a5db28aff145

Contents?: true

Size: 1.84 KB

Versions: 13

Compression:

Stored size: 1.84 KB

Contents

require(File.dirname(__FILE__)+'/helpers_tests.rb')

class StatsampleCrosstabTestCase < MiniTest::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_summary
    @ct.percentage_row=true
    @ct.percentage_column=true
    @ct.percentage_total=true
    assert(@ct.summary.size>0)
  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

13 entries across 13 versions & 1 rubygems

Version Path
statsample-0.18.0 test/test_crosstab.rb
statsample-0.17.0 test/test_crosstab.rb
statsample-0.16.0 test/test_crosstab.rb
statsample-0.15.1 test/test_crosstab.rb
statsample-0.15.0 test/test_crosstab.rb
statsample-0.14.1 test/test_crosstab.rb
statsample-0.14.0 test/test_crosstab.rb
statsample-0.13.1 test/test_crosstab.rb
statsample-0.13.0 test/test_crosstab.rb
statsample-0.12.0 test/test_crosstab.rb
statsample-0.11.2 test/test_crosstab.rb
statsample-0.11.1 test/test_crosstab.rb
statsample-0.11.0 test/test_crosstab.rb