statsample 1.4.1 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +4 -3
  3. data/History.txt +4 -0
  4. data/README.md +4 -0
  5. data/lib/statsample/converter/csv.rb +41 -54
  6. data/lib/statsample/converters.rb +18 -19
  7. data/lib/statsample/version.rb +1 -1
  8. data/test/fixtures/scientific_notation.csv +4 -0
  9. data/test/helpers_tests.rb +37 -38
  10. data/test/test_analysis.rb +96 -97
  11. data/test/test_anova_contrast.rb +22 -22
  12. data/test/test_anovaoneway.rb +12 -12
  13. data/test/test_anovatwoway.rb +16 -17
  14. data/test/test_anovatwowaywithdataset.rb +22 -24
  15. data/test/test_anovawithvectors.rb +67 -69
  16. data/test/test_awesome_print_bug.rb +9 -9
  17. data/test/test_bartlettsphericity.rb +13 -13
  18. data/test/test_bivariate.rb +122 -126
  19. data/test/test_codification.rb +51 -49
  20. data/test/test_crosstab.rb +44 -40
  21. data/test/test_csv.rb +52 -70
  22. data/test/test_dataset.rb +347 -330
  23. data/test/test_dominance_analysis.rb +22 -24
  24. data/test/test_factor.rb +163 -166
  25. data/test/test_factor_map.rb +25 -30
  26. data/test/test_factor_pa.rb +28 -28
  27. data/test/test_ggobi.rb +19 -18
  28. data/test/test_gsl.rb +13 -15
  29. data/test/test_histogram.rb +74 -77
  30. data/test/test_matrix.rb +29 -31
  31. data/test/test_multiset.rb +132 -126
  32. data/test/test_regression.rb +143 -149
  33. data/test/test_reliability.rb +149 -155
  34. data/test/test_reliability_icc.rb +100 -104
  35. data/test/test_reliability_skillscale.rb +38 -40
  36. data/test/test_resample.rb +14 -12
  37. data/test/test_rserve_extension.rb +33 -33
  38. data/test/test_srs.rb +5 -5
  39. data/test/test_statistics.rb +52 -50
  40. data/test/test_stest.rb +27 -28
  41. data/test/test_stratified.rb +10 -10
  42. data/test/test_test_f.rb +17 -17
  43. data/test/test_test_kolmogorovsmirnov.rb +21 -21
  44. data/test/test_test_t.rb +52 -52
  45. data/test/test_umannwhitney.rb +16 -16
  46. data/test/test_vector.rb +419 -410
  47. data/test/test_wilcoxonsignedrank.rb +60 -63
  48. data/test/test_xls.rb +41 -41
  49. metadata +55 -5
  50. data/web/Rakefile +0 -39
@@ -1,140 +1,138 @@
1
- require(File.expand_path(File.dirname(__FILE__)+'/helpers_tests.rb'))
1
+ require(File.expand_path(File.dirname(__FILE__) + '/helpers_tests.rb'))
2
2
 
3
- $reliability_icc=nil
3
+ $reliability_icc = nil
4
4
 
5
- class StatsampleReliabilityIccTestCase < MiniTest::Test
5
+ class StatsampleReliabilityIccTestCase < Minitest::Test
6
6
  context Statsample::Reliability::ICC do
7
7
  setup do
8
- a=[9,6,8,7,10,6].to_scale
9
- b=[2,1,4,1,5,2].to_scale
10
- c=[5,3,6,2,6,4].to_scale
11
- d=[8,2,8,6,9,7].to_scale
12
- @ds={'a'=>a,'b'=>b,'c'=>c,'d'=>d}.to_dataset
13
- @icc=Statsample::Reliability::ICC.new(@ds)
8
+ a = [9, 6, 8, 7, 10, 6].to_scale
9
+ b = [2, 1, 4, 1, 5, 2].to_scale
10
+ c = [5, 3, 6, 2, 6, 4].to_scale
11
+ d = [8, 2, 8, 6, 9, 7].to_scale
12
+ @ds = { 'a' => a, 'b' => b, 'c' => c, 'd' => d }.to_dataset
13
+ @icc = Statsample::Reliability::ICC.new(@ds)
14
14
  end
15
- should "basic method be correct" do
16
- assert_equal(6,@icc.n)
17
- assert_equal(4,@icc.k)
15
+ should 'basic method be correct' do
16
+ assert_equal(6, @icc.n)
17
+ assert_equal(4, @icc.k)
18
18
  end
19
- should "total mean be correct" do
19
+ should 'total mean be correct' do
20
20
  assert_in_delta(5.291, @icc.total_mean, 0.001)
21
21
  end
22
- should "df methods be correct" do
22
+ should 'df methods be correct' do
23
23
  assert_equal(5, @icc.df_bt)
24
24
  assert_equal(18, @icc.df_wt)
25
25
  assert_equal(3, @icc.df_bj)
26
26
  assert_equal(15, @icc.df_residual)
27
27
  end
28
- should "ms between targets be correct" do
28
+ should 'ms between targets be correct' do
29
29
  assert_in_delta(11.24, @icc.ms_bt, 0.01)
30
30
  end
31
- should "ms within targets be correct" do
31
+ should 'ms within targets be correct' do
32
32
  assert_in_delta(6.26, @icc.ms_wt, 0.01)
33
33
  end
34
- should "ms between judges be correct" do
34
+ should 'ms between judges be correct' do
35
35
  assert_in_delta(32.49, @icc.ms_bj, 0.01)
36
36
  end
37
- should "ms residual be correct" do
37
+ should 'ms residual be correct' do
38
38
  assert_in_delta(1.02, @icc.ms_residual, 0.01)
39
39
  end
40
- context "with McGraw and Wong denominations," do
41
-
40
+ context 'with McGraw and Wong denominations,' do
42
41
  end
43
- context "with Shrout & Fleiss denominations, " do
44
- should "icc(1,1) method be correct" do
42
+ context 'with Shrout & Fleiss denominations, ' do
43
+ should 'icc(1,1) method be correct' do
45
44
  assert_in_delta(0.17, @icc.icc_1_1, 0.01)
46
45
  end
47
46
  # Verified on SPSS and R
48
- should "icc(2,1) method be correct" do
47
+ should 'icc(2,1) method be correct' do
49
48
  assert_in_delta(0.29, @icc.icc_2_1, 0.01)
50
49
  end
51
- should "icc(3,1) method be correct" do
50
+ should 'icc(3,1) method be correct' do
52
51
  assert_in_delta(0.71, @icc.icc_3_1, 0.01)
53
52
  end
54
- should "icc(1,k) method be correct" do
53
+ should 'icc(1,k) method be correct' do
55
54
  assert_in_delta(0.44, @icc.icc_1_k, 0.01)
56
55
  end
57
56
  # Verified on SPSS and R
58
- should "icc(2,k) method be correct" do
57
+ should 'icc(2,k) method be correct' do
59
58
  assert_in_delta(0.62, @icc.icc_2_k, 0.01)
60
- end
61
- should "icc(3,k) method be correct" do
59
+ end
60
+ should 'icc(3,k) method be correct' do
62
61
  assert_in_delta(0.91, @icc.icc_3_k, 0.01)
63
62
  end
64
-
65
- should "icc(1,1) F be correct" do
63
+
64
+ should 'icc(1,1) F be correct' do
66
65
  assert_in_delta(1.795, @icc.icc_1_f.f)
67
66
  end
68
- should "icc(1,1) confidence interval should be correct" do
67
+ should 'icc(1,1) confidence interval should be correct' do
69
68
  assert_in_delta(-0.133, @icc.icc_1_1_ci[0], 0.001)
70
69
  assert_in_delta(0.723, @icc.icc_1_1_ci[1], 0.001)
71
70
  end
72
- should "icc(1,k) confidence interval should be correct" do
71
+ should 'icc(1,k) confidence interval should be correct' do
73
72
  assert_in_delta(-0.884, @icc.icc_1_k_ci[0], 0.001)
74
73
  assert_in_delta(0.912, @icc.icc_1_k_ci[1], 0.001)
75
74
  end
76
-
77
- should "icc(2,1) F be correct" do
75
+
76
+ should 'icc(2,1) F be correct' do
78
77
  assert_in_delta(11.027, @icc.icc_2_f.f)
79
78
  end
80
- should "icc(2,1) confidence interval should be correct" do
81
- #skip("Not yet operational")
79
+ should 'icc(2,1) confidence interval should be correct' do
80
+ # skip("Not yet operational")
82
81
  assert_in_delta(0.019, @icc.icc_2_1_ci[0], 0.001)
83
82
  assert_in_delta(0.761, @icc.icc_2_1_ci[1], 0.001)
84
83
  end
85
-
86
- # Verified on SPSS and R
87
- should "icc(2,k) confidence interval should be correct" do
88
- #skip("Not yet operational")
89
- #p @icc.icc_2_k_ci
84
+
85
+ # Verified on SPSS and R
86
+ should 'icc(2,k) confidence interval should be correct' do
87
+ # skip("Not yet operational")
88
+ # p @icc.icc_2_k_ci
90
89
  assert_in_delta(0.039, @icc.icc_2_k_ci[0], 0.001)
91
90
  assert_in_delta(0.929, @icc.icc_2_k_ci[1], 0.001)
92
-
93
91
  end
94
- #should "Shrout icc(2,k) and McGraw icc(a,k) ci be equal" do
92
+ # should "Shrout icc(2,k) and McGraw icc(a,k) ci be equal" do
95
93
  # assert_in_delta(@icc.icc_2_k_ci_shrout[0], @icc.icc_2_k_ci_mcgraw[0], 10e-5)
96
- #end
97
-
98
- should "icc(3,1) F be correct" do
94
+ # end
95
+
96
+ should 'icc(3,1) F be correct' do
99
97
  assert_in_delta(11.027, @icc.icc_3_f.f)
100
98
  end
101
-
102
- should "icc(3,1) confidence interval should be correct" do
99
+
100
+ should 'icc(3,1) confidence interval should be correct' do
103
101
  assert_in_delta(0.342, @icc.icc_3_1_ci[0], 0.001)
104
102
  assert_in_delta(0.946, @icc.icc_3_1_ci[1], 0.001)
105
103
  end
106
- should "icc(3,k) confidence interval should be correct" do
104
+ should 'icc(3,k) confidence interval should be correct' do
107
105
  assert_in_delta(0.676, @icc.icc_3_k_ci[0], 0.001)
108
106
  assert_in_delta(0.986, @icc.icc_3_k_ci[1], 0.001)
109
107
  end
110
- should "incorrect type raises an error" do
111
- assert_raise(::RuntimeError) do
112
- @icc.type=:nonexistant_type
108
+ should 'incorrect type raises an error' do
109
+ assert_raise(::RuntimeError) do
110
+ @icc.type = :nonexistant_type
113
111
  end
114
112
  end
115
113
  end
116
-
114
+
117
115
  begin
118
116
  require 'rserve'
119
117
  require 'statsample/rserve_extension'
120
- context "McGraw and Wong" do
118
+ context 'McGraw and Wong' do
121
119
  teardown do
122
- @r=$reliability_icc[:r].close unless $reliability_icc[:r].nil?
120
+ @r = $reliability_icc[:r].close unless $reliability_icc[:r].nil?
123
121
  end
124
122
  setup do
125
- if($reliability_icc.nil?)
126
- size=100
127
- a=size.times.map {rand(10)}.to_scale
128
- b=a.recode{|i|i+rand(4)-2}
129
- c=a.recode{|i|i+rand(4)-2}
130
- d=a.recode{|i|i+rand(4)-2}
131
- @ds={'a'=>a,'b'=>b,'c'=>c,'d'=>d}.to_dataset
132
-
133
- @icc=Statsample::Reliability::ICC.new(@ds)
134
- @r=Rserve::Connection.new
135
-
136
- @r.assign('ds',@ds)
137
-
123
+ if $reliability_icc.nil?
124
+ size = 100
125
+ a = size.times.map { rand(10) }.to_scale
126
+ b = a.recode { |i| i + rand(4) - 2 }
127
+ c = a.recode { |i| i + rand(4) - 2 }
128
+ d = a.recode { |i| i + rand(4) - 2 }
129
+ @ds = { 'a' => a, 'b' => b, 'c' => c, 'd' => d }.to_dataset
130
+
131
+ @icc = Statsample::Reliability::ICC.new(@ds)
132
+ @r = Rserve::Connection.new
133
+
134
+ @r.assign('ds', @ds)
135
+
138
136
  @r.void_eval("library(irr);
139
137
  iccs=list(
140
138
  icc_1=icc(ds,'o','c','s'),
@@ -144,59 +142,57 @@ class StatsampleReliabilityIccTestCase < MiniTest::Test
144
142
  icc_a_1=icc(ds,'t','a','s'),
145
143
  icc_a_k=icc(ds,'t','a','a'))
146
144
  ")
147
- @iccs=@r.eval('iccs').to_ruby
148
- $reliability_icc={ :icc=>@icc, :iccs=>@iccs, :r=>@r
145
+ @iccs = @r.eval('iccs').to_ruby
146
+ $reliability_icc = { icc: @icc, iccs: @iccs, r: @r
149
147
  }
150
-
151
- end
152
- @icc=$reliability_icc[:icc]
153
- @iccs=$reliability_icc[:iccs]
154
- @r=$reliability_icc[:r]
155
148
 
149
+ end
150
+ @icc = $reliability_icc[:icc]
151
+ @iccs = $reliability_icc[:iccs]
152
+ @r = $reliability_icc[:r]
156
153
  end
157
154
  [:icc_1, :icc_k, :icc_c_1, :icc_c_k, :icc_a_1, :icc_a_k].each do |t|
158
155
  context "ICC Type #{t} " do
159
- should "value be correct" do
160
- @icc.type=t
161
- @r_icc=@iccs[t.to_s]
162
- assert_in_delta(@r_icc['value'],@icc.r)
156
+ should 'value be correct' do
157
+ @icc.type = t
158
+ @r_icc = @iccs[t.to_s]
159
+ assert_in_delta(@r_icc['value'], @icc.r)
163
160
  end
164
- should "fvalue be correct" do
165
- @icc.type=t
166
- @r_icc=@iccs[t.to_s]
167
- assert_in_delta(@r_icc['Fvalue'],@icc.f.f)
161
+ should 'fvalue be correct' do
162
+ @icc.type = t
163
+ @r_icc = @iccs[t.to_s]
164
+ assert_in_delta(@r_icc['Fvalue'], @icc.f.f)
168
165
  end
169
- should "num df be correct" do
170
- @icc.type=t
171
- @r_icc=@iccs[t.to_s]
172
- assert_in_delta(@r_icc['df1'],@icc.f.df_num)
166
+ should 'num df be correct' do
167
+ @icc.type = t
168
+ @r_icc = @iccs[t.to_s]
169
+ assert_in_delta(@r_icc['df1'], @icc.f.df_num)
173
170
  end
174
- should "den df be correct" do
175
- @icc.type=t
176
- @r_icc=@iccs[t.to_s]
177
- assert_in_delta(@r_icc['df2'],@icc.f.df_den)
171
+ should 'den df be correct' do
172
+ @icc.type = t
173
+ @r_icc = @iccs[t.to_s]
174
+ assert_in_delta(@r_icc['df2'], @icc.f.df_den)
178
175
  end
179
176
 
180
- should "f probability be correct" do
181
- @icc.type=t
182
- @r_icc=@iccs[t.to_s]
183
- assert_in_delta(@r_icc['p.value'],@icc.f.probability)
177
+ should 'f probability be correct' do
178
+ @icc.type = t
179
+ @r_icc = @iccs[t.to_s]
180
+ assert_in_delta(@r_icc['p.value'], @icc.f.probability)
184
181
  end
185
- should "bounds be equal" do
186
- @icc.type=t
187
- @r_icc=@iccs[t.to_s]
188
- assert_in_delta(@r_icc['lbound'],@icc.lbound)
189
- assert_in_delta(@r_icc['ubound'],@icc.ubound)
182
+ should 'bounds be equal' do
183
+ @icc.type = t
184
+ @r_icc = @iccs[t.to_s]
185
+ assert_in_delta(@r_icc['lbound'], @icc.lbound)
186
+ assert_in_delta(@r_icc['ubound'], @icc.ubound)
190
187
  end
191
- should "summary generated" do
192
- assert(@icc.summary.size>0)
188
+ should 'summary generated' do
189
+ assert(@icc.summary.size > 0)
193
190
  end
194
191
  end
195
192
  end
196
193
  end
197
194
  rescue
198
- puts "requires rserve"
195
+ puts 'requires rserve'
199
196
  end
200
-
201
197
  end
202
198
  end
@@ -1,57 +1,55 @@
1
- require(File.expand_path(File.dirname(__FILE__)+'/helpers_tests.rb'))
1
+ require(File.expand_path(File.dirname(__FILE__) + '/helpers_tests.rb'))
2
2
 
3
-
4
- class StatsampleReliabilitySkillScaleTestCase < MiniTest::Unit::TestCase
3
+ class StatsampleReliabilitySkillScaleTestCase < Minitest::Test
5
4
  context Statsample::Reliability::SkillScaleAnalysis do
6
5
  setup do
7
- options=%w{a b c d e}
8
- cases=20
9
- @id=cases.times.map {|v| v}.to_scale
10
- @a=cases.times.map {options[rand(5)]}.to_vector
11
- @b=cases.times.map {options[rand(5)]}.to_vector
12
- @c=cases.times.map {options[rand(5)]}.to_vector
13
- @d=cases.times.map {options[rand(5)]}.to_vector
14
- @e=cases.times.map {|i|
15
- i==0 ? options[rand(0)] :
16
- rand()>0.8 ? nil : options[rand(5)]
6
+ options = %w(a b c d e)
7
+ cases = 20
8
+ @id = cases.times.map { |v| v }.to_scale
9
+ @a = cases.times.map { options[rand(5)] }.to_vector
10
+ @b = cases.times.map { options[rand(5)] }.to_vector
11
+ @c = cases.times.map { options[rand(5)] }.to_vector
12
+ @d = cases.times.map { options[rand(5)] }.to_vector
13
+ @e = cases.times.map {|i|
14
+ i == 0 ? options[rand(0)] :
15
+ rand > 0.8 ? nil : options[rand(5)]
17
16
  }.to_vector
18
- @ds={'id'=>@id,'a'=>@a,'b'=>@b,'c'=>@c,'d'=>@d,'e'=>@e}.to_dataset
19
- @key={'a'=>"a", 'b'=>options[rand(5)], 'c'=>options[rand(5)], 'd'=>options[rand(5)],'e'=>options[rand(5)]}
20
- @ssa=Statsample::Reliability::SkillScaleAnalysis.new(@ds, @key)
21
- @ac=@a.map {|v| v==@key['a'] ? 1 : 0}.to_scale
22
- @bc=@b.map {|v| v==@key['b'] ? 1 : 0}.to_scale
23
- @cc=@c.map {|v| v==@key['c'] ? 1 : 0}.to_scale
24
- @dc=@d.map {|v| v==@key['d'] ? 1 : 0}.to_scale
25
- @ec=@e.map {|v| v.nil? ? nil : (v==@key['e'] ? 1 : 0)}.to_scale
26
-
17
+ @ds = { 'id' => @id, 'a' => @a, 'b' => @b, 'c' => @c, 'd' => @d, 'e' => @e }.to_dataset
18
+ @key = { 'a' => 'a', 'b' => options[rand(5)], 'c' => options[rand(5)], 'd' => options[rand(5)], 'e' => options[rand(5)] }
19
+ @ssa = Statsample::Reliability::SkillScaleAnalysis.new(@ds, @key)
20
+ @ac = @a.map { |v| v == @key['a'] ? 1 : 0 }.to_scale
21
+ @bc = @b.map { |v| v == @key['b'] ? 1 : 0 }.to_scale
22
+ @cc = @c.map { |v| v == @key['c'] ? 1 : 0 }.to_scale
23
+ @dc = @d.map { |v| v == @key['d'] ? 1 : 0 }.to_scale
24
+ @ec = @e.map { |v| v.nil? ? nil : (v == @key['e'] ? 1 : 0) }.to_scale
27
25
  end
28
- should "return proper corrected dataset" do
29
- cds={'id'=>@id, 'a'=>@ac,'b'=>@bc,'c'=>@cc,'d'=>@dc, 'e'=>@ec}.to_dataset
26
+ should 'return proper corrected dataset' do
27
+ cds = { 'id' => @id, 'a' => @ac, 'b' => @bc, 'c' => @cc, 'd' => @dc, 'e' => @ec }.to_dataset
30
28
  assert_equal(cds, @ssa.corrected_dataset)
31
29
  end
32
- should "return proper corrected minimal dataset" do
33
- cdsm={'a'=>@ac,'b'=>@bc,'c'=>@cc,'d'=>@dc, 'e'=>@ec}.to_dataset
30
+ should 'return proper corrected minimal dataset' do
31
+ cdsm = { 'a' => @ac, 'b' => @bc, 'c' => @cc, 'd' => @dc, 'e' => @ec }.to_dataset
34
32
  assert_equal(cdsm, @ssa.corrected_dataset_minimal)
35
33
  end
36
- should "return correct vector_sum and vector_sum" do
37
- cdsm=@ssa.corrected_dataset_minimal
34
+ should 'return correct vector_sum and vector_sum' do
35
+ cdsm = @ssa.corrected_dataset_minimal
38
36
  assert_equal(cdsm.vector_sum, @ssa.vector_sum)
39
37
  assert_equal(cdsm.vector_mean, @ssa.vector_mean)
40
38
  end
41
- should "not crash on rare case" do
42
- a=Statsample::Vector["c","c","a","a","c","a","b","c","c","b","a","d","a","d","a","a","d","e","c","d"]
43
- b=Statsample::Vector["e","b","e","b","c","d","a","e","e","c","b","e","e","b","d","c","e","b","b","d"]
44
- c=Statsample::Vector["e","b","e","c","e","c","b","d","e","c","a","a","b","d","e","c","b","a","a","e"]
45
- d=Statsample::Vector["a","b","d","d","e","b","e","b","d","c","e","a","c","d","c","c","e","d","d","b"]
46
- e=Statsample::Vector["a","b",nil,"d","c","c","d",nil,"d","d","e","e",nil,nil,nil,"d","c",nil,"e","d"]
47
- key={"a"=>"a", "b"=>"e", "c"=>"d", "d"=>"c", "e"=>"d"}
48
- ds=Statsample::Dataset.new("a"=>a,"b"=>b,"c"=>c,"d"=>d,"e"=>e)
49
- ssa=Statsample::Reliability::SkillScaleAnalysis.new(ds, key)
39
+ should 'not crash on rare case' do
40
+ a = Statsample::Vector['c', 'c', 'a', 'a', 'c', 'a', 'b', 'c', 'c', 'b', 'a', 'd', 'a', 'd', 'a', 'a', 'd', 'e', 'c', 'd']
41
+ b = Statsample::Vector['e', 'b', 'e', 'b', 'c', 'd', 'a', 'e', 'e', 'c', 'b', 'e', 'e', 'b', 'd', 'c', 'e', 'b', 'b', 'd']
42
+ c = Statsample::Vector['e', 'b', 'e', 'c', 'e', 'c', 'b', 'd', 'e', 'c', 'a', 'a', 'b', 'd', 'e', 'c', 'b', 'a', 'a', 'e']
43
+ d = Statsample::Vector['a', 'b', 'd', 'd', 'e', 'b', 'e', 'b', 'd', 'c', 'e', 'a', 'c', 'd', 'c', 'c', 'e', 'd', 'd', 'b']
44
+ e = Statsample::Vector['a', 'b', nil, 'd', 'c', 'c', 'd', nil, 'd', 'd', 'e', 'e', nil, nil, nil, 'd', 'c', nil, 'e', 'd']
45
+ key = { 'a' => 'a', 'b' => 'e', 'c' => 'd', 'd' => 'c', 'e' => 'd' }
46
+ ds = Statsample::Dataset.new('a' => a, 'b' => b, 'c' => c, 'd' => d, 'e' => e)
47
+ ssa = Statsample::Reliability::SkillScaleAnalysis.new(ds, key)
50
48
  assert(ssa.summary)
51
49
  end
52
-
53
- should "return valid summary" do
54
- assert(@ssa.summary.size>0)
50
+
51
+ should 'return valid summary' do
52
+ assert(@ssa.summary.size > 0)
55
53
  end
56
54
  end
57
55
  end
@@ -1,22 +1,24 @@
1
- require(File.expand_path(File.dirname(__FILE__)+'/helpers_tests.rb'))
1
+ require(File.expand_path(File.dirname(__FILE__) + '/helpers_tests.rb'))
2
2
 
3
- class StatsampleResampleTestCase < MiniTest::Unit::TestCase
3
+ class StatsampleResampleTestCase < Minitest::Test
4
4
  def initialize(*args)
5
5
  super
6
6
  end
7
+
7
8
  def test_basic
8
- r=Statsample::Resample.generate(20,1,10)
9
- assert_equal(20,r.size)
10
- assert(r.min>=1)
11
- assert(r.max<=10)
9
+ r = Statsample::Resample.generate(20, 1, 10)
10
+ assert_equal(20, r.size)
11
+ assert(r.min >= 1)
12
+ assert(r.max <= 10)
12
13
  end
14
+
13
15
  def test_repeat_and_save
14
- r=Statsample::Resample.repeat_and_save(400) {
15
- Statsample::Resample.generate(20,1,10).count(1)
16
+ r = Statsample::Resample.repeat_and_save(400) {
17
+ Statsample::Resample.generate(20, 1, 10).count(1)
16
18
  }
17
- assert_equal(400,r.size)
18
- v=Statsample::Vector.new(r,:scale)
19
- a=v.count {|x| x > 3}
20
- assert(a>=30 && a<=70)
19
+ assert_equal(400, r.size)
20
+ v = Statsample::Vector.new(r, :scale)
21
+ a = v.count { |x| x > 3 }
22
+ assert(a >= 30 && a <= 70)
21
23
  end
22
24
  end
@@ -1,42 +1,42 @@
1
- require(File.expand_path(File.dirname(__FILE__)+'/helpers_tests.rb'))
1
+ require(File.expand_path(File.dirname(__FILE__) + '/helpers_tests.rb'))
2
2
  begin
3
3
  require 'rserve'
4
4
  require 'statsample/rserve_extension'
5
5
 
6
- class StatsampleRserveExtensionTestCase < MiniTest::Unit::TestCase
7
- context "Statsample Rserve extensions" do
8
- setup do
9
- @r=Rserve::Connection.new
10
- end
11
- teardown do
12
- @r.close
13
- end
14
- should "return a valid rexp for numeric vector" do
15
- a=100.times.map {|i| rand()>0.9 ? nil : i+rand() }.to_scale
16
- rexp=a.to_REXP
17
- assert(rexp.is_a? Rserve::REXP::Double)
18
- assert_equal(rexp.to_ruby,a.data_with_nils)
19
- @r.assign 'a',rexp
20
- assert_equal(a.data_with_nils, @r.eval('a').to_ruby)
21
- end
22
- should "return a valid rserve dataframe for statsample datasets" do
23
- a=100.times.map {|i| rand()>0.9 ? nil : i+rand() }.to_scale
24
- b=100.times.map {|i| rand()>0.9 ? nil : i+rand() }.to_scale
25
- c=100.times.map {|i| rand()>0.9 ? nil : i+rand() }.to_scale
26
- ds={'a'=>a,'b'=>b,'c'=>c}.to_dataset
27
- rexp=ds.to_REXP
28
- assert(rexp.is_a? Rserve::REXP::GenericVector)
29
- ret=rexp.to_ruby
30
- assert_equal(a.data_with_nils, ret['a'])
31
- @r.assign 'df', rexp
32
- out_df=@r.eval('df').to_ruby
33
- assert_equal('data.frame', out_df.attributes['class'])
34
- assert_equal(['a','b','c'], out_df.attributes['names'])
35
- assert_equal(a.data_with_nils, out_df['a'])
6
+ class StatsampleRserveExtensionTestCase < Minitest::Test
7
+ context 'Statsample Rserve extensions' do
8
+ setup do
9
+ @r = Rserve::Connection.new
10
+ end
11
+ teardown do
12
+ @r.close
13
+ end
14
+ should 'return a valid rexp for numeric vector' do
15
+ a = 100.times.map { |i| rand > 0.9 ? nil : i + rand }.to_scale
16
+ rexp = a.to_REXP
17
+ assert(rexp.is_a? Rserve::REXP::Double)
18
+ assert_equal(rexp.to_ruby, a.data_with_nils)
19
+ @r.assign 'a', rexp
20
+ assert_equal(a.data_with_nils, @r.eval('a').to_ruby)
21
+ end
22
+ should 'return a valid rserve dataframe for statsample datasets' do
23
+ a = 100.times.map { |i| rand > 0.9 ? nil : i + rand }.to_scale
24
+ b = 100.times.map { |i| rand > 0.9 ? nil : i + rand }.to_scale
25
+ c = 100.times.map { |i| rand > 0.9 ? nil : i + rand }.to_scale
26
+ ds = { 'a' => a, 'b' => b, 'c' => c }.to_dataset
27
+ rexp = ds.to_REXP
28
+ assert(rexp.is_a? Rserve::REXP::GenericVector)
29
+ ret = rexp.to_ruby
30
+ assert_equal(a.data_with_nils, ret['a'])
31
+ @r.assign 'df', rexp
32
+ out_df = @r.eval('df').to_ruby
33
+ assert_equal('data.frame', out_df.attributes['class'])
34
+ assert_equal(%w(a b c), out_df.attributes['names'])
35
+ assert_equal(a.data_with_nils, out_df['a'])
36
+ end
36
37
  end
37
38
  end
38
- end
39
39
 
40
40
  rescue LoadError
41
- puts "Require rserve extension"
41
+ puts 'Require rserve extension'
42
42
  end