test/test_rserve_extension.rb in statsample-1.4.1 vs test/test_rserve_extension.rb in statsample-1.4.2

- old
+ new

@@ -1,42 +1,42 @@ -require(File.expand_path(File.dirname(__FILE__)+'/helpers_tests.rb')) +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 + class StatsampleRserveExtensionTestCase < Minitest::Test + 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(%w(a b c), out_df.attributes['names']) + assert_equal(a.data_with_nils, out_df['a']) + end 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" + puts 'Require rserve extension' end