Sha256: 63ba4c80c86294791e5dd9ec1de0aa87be47fa8d83e9d65fa616a044120e0d6a

Contents?: true

Size: 1.4 KB

Versions: 8

Compression:

Stored size: 1.4 KB

Contents

require(File.expand_path(File.dirname(__FILE__)+'/helpers_tests.rb'))
begin
  require 'rserve'
  require 'statsample/rserve_extension'

class StatsampleRserveExtensionTestCase < MiniTest::Unit::TestCase
  context "Statsample Rserve extensions" do
    setup do
      @r=Rserve::Connection.new
    end
    teardown do
      @r.close
    end
    should "return a valid rexp for numeric vector" do
      a=100.times.map {|i| rand()>0.9 ? nil : i+rand() }.to_scale
      rexp=a.to_REXP
      assert(rexp.is_a? Rserve::REXP::Double)
      assert_equal(rexp.to_ruby,a.data_with_nils)
      @r.assign 'a',rexp
      assert_equal(a.data_with_nils, @r.eval('a').to_ruby)
    end
    should "return a valid rserve dataframe for statsample datasets" do
      a=100.times.map {|i| rand()>0.9 ? nil : i+rand() }.to_scale
      b=100.times.map {|i| rand()>0.9 ? nil : i+rand() }.to_scale
      c=100.times.map {|i| rand()>0.9 ? nil : i+rand() }.to_scale
      ds={'a'=>a,'b'=>b,'c'=>c}.to_dataset
      rexp=ds.to_REXP
      assert(rexp.is_a? Rserve::REXP::GenericVector)
      ret=rexp.to_ruby
      assert_equal(a.data_with_nils, ret['a']) 
      @r.assign 'df', rexp
      out_df=@r.eval('df').to_ruby
      assert_equal('data.frame', out_df.attributes['class'])
      assert_equal(['a','b','c'], out_df.attributes['names'])
      assert_equal(a.data_with_nils, out_df['a'])
    end
  end
end

rescue LoadError
  puts "Require rserve extension"
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
statsample-1.4.1 test/test_rserve_extension.rb
statsample-1.4.0 test/test_rserve_extension.rb
statsample-1.3.1 test/test_rserve_extension.rb
statsample-1.3.0 test/test_rserve_extension.rb
statsample-1.2.0 test/test_rserve_extension.rb
statsample-1.1.0 test/test_rserve_extension.rb
statsample-1.0.1 test/test_rserve_extension.rb
statsample-1.0.0 test/test_rserve_extension.rb