statsample 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/History.txt +7 -0
  2. data/Manifest.txt +15 -9
  3. data/README.txt +6 -0
  4. data/Rakefile +8 -0
  5. data/{demo → examples}/correlation_matrix.rb +0 -0
  6. data/{demo/dominanceanalysis.rb → examples/dominance_analysis.rb} +0 -0
  7. data/{demo → examples}/dominance_analysis_bootstrap.rb +0 -0
  8. data/{demo → examples}/levene.rb +0 -0
  9. data/{demo → examples}/multiple_regression.rb +5 -3
  10. data/{demo → examples}/multivariate_correlation.rb +0 -0
  11. data/{demo → examples}/polychoric.rb +0 -0
  12. data/{demo → examples}/principal_axis.rb +0 -0
  13. data/examples/t_test.rb +11 -0
  14. data/{demo → examples}/tetrachoric.rb +0 -0
  15. data/lib/statistics2.rb +1 -1
  16. data/lib/statsample.rb +57 -6
  17. data/lib/statsample/bivariate/polychoric.rb +12 -25
  18. data/lib/statsample/bivariate/tetrachoric.rb +1 -3
  19. data/lib/statsample/converter/csv.rb +11 -12
  20. data/lib/statsample/dominanceanalysis/bootstrap.rb +2 -3
  21. data/lib/statsample/factor/principalaxis.rb +0 -2
  22. data/lib/statsample/factor/rotation.rb +6 -8
  23. data/lib/statsample/graph.rb +8 -0
  24. data/lib/statsample/graph/svggraph.rb +0 -4
  25. data/lib/statsample/regression/multiple/baseengine.rb +25 -28
  26. data/lib/statsample/regression/multiple/matrixengine.rb +30 -34
  27. data/lib/statsample/test.rb +36 -1
  28. data/lib/statsample/test/levene.rb +11 -7
  29. data/lib/statsample/test/t.rb +189 -0
  30. data/test/test_anova.rb +8 -10
  31. data/test/test_bivariate.rb +40 -37
  32. data/test/test_codification.rb +9 -13
  33. data/test/test_combination.rb +37 -39
  34. data/test/test_crosstab.rb +46 -48
  35. data/test/test_csv.rb +40 -45
  36. data/test/test_dataset.rb +150 -152
  37. data/test/test_distribution.rb +24 -21
  38. data/test/test_dominance_analysis.rb +10 -12
  39. data/test/test_factor.rb +95 -91
  40. data/test/test_ggobi.rb +30 -33
  41. data/test/test_gsl.rb +4 -4
  42. data/test/test_helpers.rb +26 -0
  43. data/test/test_histogram.rb +5 -6
  44. data/test/test_logit.rb +20 -21
  45. data/test/test_matrix.rb +47 -48
  46. data/test/test_mle.rb +130 -131
  47. data/test/test_multiset.rb +95 -96
  48. data/test/test_permutation.rb +35 -36
  49. data/test/test_promise_after.rb +39 -0
  50. data/test/test_regression.rb +49 -51
  51. data/test/test_reliability.rb +29 -30
  52. data/test/test_resample.rb +22 -23
  53. data/test/test_srs.rb +8 -9
  54. data/test/test_statistics.rb +12 -6
  55. data/test/test_stest.rb +18 -10
  56. data/test/test_stratified.rb +15 -16
  57. data/test/test_svg_graph.rb +11 -22
  58. data/test/test_test_t.rb +40 -0
  59. data/test/test_umannwhitney.rb +14 -15
  60. data/test/test_vector.rb +33 -37
  61. data/test/test_xls.rb +34 -41
  62. metadata +22 -11
@@ -1,11 +1,19 @@
1
- $:.unshift(File.dirname(__FILE__)+'/../lib/')
2
- require 'statsample'
3
- require 'test/unit'
4
- class StatsampleStatisicsTestCase < Test::Unit::TestCase
1
+ require(File.dirname(__FILE__)+'/test_helpers.rb')
2
+
3
+ class StatsampleStatisicsTestCase < MiniTest::Unit::TestCase
5
4
 
6
5
  def initialize(*args)
7
6
  super
8
7
  end
8
+ def test_p_using_cdf
9
+ assert_equal(0.25, Statsample::Test.p_using_cdf(0.25, tails=:left))
10
+ assert_equal(0.75, Statsample::Test.p_using_cdf(0.25, tails=:right))
11
+ assert_equal(0.50, Statsample::Test.p_using_cdf(0.25, tails=:both))
12
+ assert_equal(1, Statsample::Test.p_using_cdf(0.50, tails=:both))
13
+ assert_equal(0.05, Statsample::Test.p_using_cdf(0.025, tails=:both))
14
+ assert_in_delta(0.05, Statsample::Test.p_using_cdf(0.975, tails=:both),0.0001)
15
+
16
+ end
9
17
  def test_recode_repeated
10
18
  a=%w{a b c c d d d e}
11
19
  exp=["a","b","c_1","c_2","d_1","d_2","d_3","e"]
@@ -23,8 +31,6 @@ class StatsampleStatisicsTestCase < Test::Unit::TestCase
23
31
  assert(!"".is_number?)
24
32
 
25
33
  end
26
-
27
-
28
34
  def test_estimation_mean
29
35
  v=([42]*23+[41]*4+[36]*1+[32]*1+[29]*1+[27]*2+[23]*1+[19]*1+[16]*2+[15]*2+[14,11,10,9,7]+ [6]*3+[5]*2+[4,3]).to_vector(:scale)
30
36
  assert_equal(50,v.size)
data/test/test_stest.rb CHANGED
@@ -1,9 +1,7 @@
1
- $:.unshift(File.dirname(__FILE__)+'/../lib/')
2
- require 'statsample'
3
- require "tempfile"
4
- require 'test/unit'
1
+ require(File.dirname(__FILE__)+'/test_helpers.rb')
5
2
 
6
- class StatsampleStatisticalTestCase < Test::Unit::TestCase
3
+
4
+ class StatsampleTestTestCase < MiniTest::Unit::TestCase
7
5
  def test_chi_square
8
6
  real=Matrix[[95,95],[45,155]]
9
7
  expected=Matrix[[68,122],[72,128]]
@@ -22,14 +20,24 @@ class StatsampleStatisticalTestCase < Test::Unit::TestCase
22
20
  b=[2,3,4,5,6,12].to_scale
23
21
  assert_equal(11, Statsample::Test.u_mannwhitney(a,b).u)
24
22
  end
25
-
26
-
23
+
24
+
27
25
  def test_levene
28
-
29
26
  a=[1,2,3,4,5,6,7,8,100,10].to_scale
30
- b=[30,40,50,60,70,80,90,100,110,120].to_scale
27
+ b=[30,40,50,60,70,80,90,100,110,120].to_scale
31
28
  levene=Statsample::Test::Levene.new([a,b])
29
+ assert_levene(levene)
30
+ end
31
+ def test_levene_dataset
32
+ a=[1,2,3,4,5,6,7,8,100,10].to_scale
33
+ b=[30,40,50,60,70,80,90,100,110,120].to_scale
34
+ ds={'a'=>a,'b'=>b}.to_dataset
35
+ levene=Statsample::Test::Levene.new(ds)
36
+ assert_levene(levene)
37
+ end
38
+ def assert_levene(levene)
32
39
  assert_in_delta(0.778, levene.f, 0.001)
33
40
  assert_in_delta(0.389, levene.probability, 0.001)
34
41
  end
35
- end
42
+
43
+ end
@@ -1,19 +1,18 @@
1
- $:.unshift(File.dirname(__FILE__)+'/../lib/')
2
- require 'statsample'
3
- require 'test/unit'
1
+ require(File.dirname(__FILE__)+'/test_helpers.rb')
4
2
 
5
- class StatsampleStratifiedTestCase < Test::Unit::TestCase
6
3
 
7
- def initialize(*args)
8
- super
9
- end
10
- def test_mean
11
- a=[10,20,30,40,50]
12
- b=[110,120,130,140]
13
- pop=a+b
14
- av=a.to_vector(:scale)
15
- bv=b.to_vector(:scale)
16
- popv=pop.to_vector(:scale)
17
- assert_equal(popv.mean,Statsample::StratifiedSample.mean(av,bv))
18
- end
4
+ class StatsampleStratifiedTestCase < MiniTest::Unit::TestCase
5
+
6
+ def initialize(*args)
7
+ super
8
+ end
9
+ def test_mean
10
+ a=[10,20,30,40,50]
11
+ b=[110,120,130,140]
12
+ pop=a+b
13
+ av=a.to_vector(:scale)
14
+ bv=b.to_vector(:scale)
15
+ popv=pop.to_vector(:scale)
16
+ assert_equal(popv.mean,Statsample::StratifiedSample.mean(av,bv))
17
+ end
19
18
  end
@@ -1,36 +1,28 @@
1
- $:.unshift(File.dirname(__FILE__)+'/../lib/')
2
- require 'statsample'
3
- require 'tmpdir'
4
- require 'tempfile'
5
- require 'tempfile'
6
- require 'fileutils'
7
- require 'test/unit'
8
- begin
9
- require 'statsample/graph/svggraph'
10
- class StatsampleSvgGraphTestCase < Test::Unit::TestCase
1
+ require(File.dirname(__FILE__)+'/test_helpers.rb')
2
+ require('statsample/graph')
3
+ class StatsampleSvgGraphTestCase < MiniTest::Unit::TestCase
11
4
 
12
- def initialize(*args)
13
- @image_path=Dir::tmpdir+"/images"
14
- FileUtils.mkdir(@image_path) if !File.exists? @image_path
15
- super
5
+ def setup
6
+ @image_path=Dir::tmpdir+"/images"
7
+ FileUtils.mkdir(@image_path) if !File.exists? @image_path
16
8
  end
17
9
  def test_histogram
18
10
  if Statsample.has_gsl?
19
11
  ar=(1..1000).to_a.collect {|a|
20
- rand(10)
21
- }.to_vector(:scale)
12
+ rand(10)
13
+ }.to_vector(:scale)
22
14
  h=ar.histogram([0,2,5,11])
23
15
  file=Tempfile.new("svg_histogram_only.svg")
24
16
  graph = Statsample::Graph::SvgHistogram.new({})
25
17
  graph.histogram=h
26
18
  file.puts(graph.burn)
27
19
  else
28
- puts "Statsample::Graph::SvgHistogram.new not tested (no ruby-gsl)"
20
+ puts "Statsample::Graph::SvgHistogram.new not tested (no ruby-gsl)"
29
21
  end
30
22
  end
31
23
  def assert_svg(msg=nil)
32
24
  msg||="%s isn't a svg file"
33
- Tempfile.open("svg") do |fp|
25
+ Tempfile.open("svg") do |fp|
34
26
  yield fp
35
27
  fp.close
36
28
  fp.open
@@ -49,7 +41,7 @@ class StatsampleSvgGraphTestCase < Test::Unit::TestCase
49
41
  assert_svg {|file| vector.svggraph_frequencies(file,800,600, SVG::Graph::PieNoOp, :graph_title=>'Pie') }
50
42
  vector.type=:scale
51
43
  if Statsample.has_gsl?
52
- file=Tempfile.new("svg_histogram.svg").path
44
+ file=Tempfile.new("svg_histogram.svg").path
53
45
  hist=vector.svggraph_histogram(5)
54
46
  File.open(file,"wb") {|fp|
55
47
  fp.write(hist.burn)
@@ -60,6 +52,3 @@ class StatsampleSvgGraphTestCase < Test::Unit::TestCase
60
52
  end
61
53
  end
62
54
  end
63
- rescue LoadError
64
- puts "You should install SVG::Graph"
65
- end
@@ -0,0 +1,40 @@
1
+ require(File.dirname(__FILE__)+'/test_helpers.rb')
2
+
3
+ class StatsampleTestTTestCase < MiniTest::Unit::TestCase
4
+ def setup
5
+ @a=[30.02, 29.99, 30.11, 29.97, 30.01, 29.99].to_scale
6
+ @b=[29.89, 29.93, 29.72, 29.98, 30.02, 29.98].to_scale
7
+ @x1=@a.mean
8
+ @x2=@b.mean
9
+ @s1=@a.sd
10
+ @s2=@b.sd
11
+ @n1=@a.n
12
+ @n2=@b.n
13
+ end
14
+ def test_t_sample_independent_t
15
+ assert_in_delta(1.959, Statsample::Test::T.two_sample_independent(@x1, @x2, @s1, @s2, @n1, @n2))
16
+ assert_in_delta(1.959, Statsample::Test::T.two_sample_independent(@x1, @x2, @s1, @s2, @n1, @n2,true))
17
+ end
18
+ def test_t_sample_independent_df
19
+ assert_equal(10, Statsample::Test::T.df_equal_variance(@n1,@n2))
20
+ assert_in_delta(7.03, Statsample::Test::T.df_not_equal_variance(@s1,@s2,@n1,@n2))
21
+ end
22
+ def test_t_sample_independent_object
23
+ t=Statsample::Test.t_two_samples_independent(@a,@b)
24
+ assert(t.summary.size>0)
25
+ assert_in_delta(1.959, t.t_equal_variance)
26
+ assert_in_delta(1.959, t.t_not_equal_variance)
27
+ assert_in_delta(10, t.df_equal_variance)
28
+ assert_in_delta(7.03, t.df_not_equal_variance)
29
+ assert_in_delta(0.07856, t.probability_equal_variance)
30
+ assert_in_delta(0.09095, t.probability_not_equal_variance)
31
+
32
+ end
33
+ def test_t_one_sample
34
+ u=@a.mean+(1-rand*2)
35
+ tos=Statsample::Test::T::OneSample.new(@a,{:u=>u})
36
+ assert_equal((@a.mean-u).quo(@a.sd.quo(Math::sqrt(@a.n))), tos.t)
37
+ assert_equal(@a.n-1, tos.df)
38
+ assert(tos.summary.size>0)
39
+ end
40
+ end
@@ -1,17 +1,16 @@
1
- $:.unshift(File.dirname(__FILE__)+'/../lib/')
2
- require 'statsample'
3
- require 'test/unit'
1
+ require(File.dirname(__FILE__)+'/test_helpers.rb')
4
2
 
5
- class StatsampleSrsTestCase < Test::Unit::TestCase
6
- def test_u_mannwhitney
7
- v1=[1,2,3,4,7,8,9,10,14,15].to_scale
8
- v2=[5,6,11,12,13,16,17,18,19].to_scale
9
- u=Statsample::Test::UMannWhitney.new(v1,v2)
10
- assert_equal(73,u.r1)
11
- assert_equal(117,u.r2)
12
- assert_equal(18,u.u)
13
- assert_in_delta(-2.205,u.z,0.001)
14
- assert_in_delta(0.027,u.z_probability,0.001)
15
- assert_in_delta(0.028,u.exact_probability,0.001)
16
- end
3
+
4
+ class StatsampleUMannWhitneyTestCase < MiniTest::Unit::TestCase
5
+ def test_u_mannwhitney
6
+ v1=[1,2,3,4,7,8,9,10,14,15].to_scale
7
+ v2=[5,6,11,12,13,16,17,18,19].to_scale
8
+ u=Statsample::Test::UMannWhitney.new(v1,v2)
9
+ assert_equal(73,u.r1)
10
+ assert_equal(117,u.r2)
11
+ assert_equal(18,u.u)
12
+ assert_in_delta(-2.205,u.z,0.001)
13
+ assert_in_delta(0.027,u.z_probability,0.001)
14
+ assert_in_delta(0.028,u.exact_probability,0.001)
15
+ end
17
16
  end
data/test/test_vector.rb CHANGED
@@ -1,22 +1,18 @@
1
- $:.unshift(File.dirname(__FILE__)+'/../lib/')
2
- require 'statsample'
3
- require 'test/unit'
4
- require 'tempfile'
5
- class TestStatsample
6
- end
7
- class TestStatsample::TestVector < Test::Unit::TestCase
8
-
1
+ require(File.dirname(__FILE__)+'/test_helpers.rb')
2
+
3
+ class StatsampleTestVector < MiniTest::Unit::TestCase
4
+
9
5
  def setup
10
- @c = Statsample::Vector.new([5,5,5,5,5,6,6,7,8,9,10,1,2,3,4,nil,-99,-99], :nominal)
11
- @c.missing_values=[-99]
12
-
6
+ @c = Statsample::Vector.new([5,5,5,5,5,6,6,7,8,9,10,1,2,3,4,nil,-99,-99], :nominal)
7
+ @c.missing_values=[-99]
8
+
13
9
  end
14
10
  def test_save_load
15
11
  outfile=Tempfile.new("vector.vec")
16
12
  @c.save(outfile.path)
17
13
  a=Statsample.load(outfile.path)
18
14
  assert_equal(@c,a)
19
-
15
+
20
16
  end
21
17
  def test_lazy_methods
22
18
  data=[1,2,3,4,5,nil]
@@ -41,19 +37,19 @@ class TestStatsample::TestVector < Test::Unit::TestCase
41
37
  assert_equal(exp2,exp)
42
38
  end
43
39
  def test_product
44
- a=[1,2,3,4,5].to_vector(:scale)
45
- assert_equal(120,a.product)
40
+ a=[1,2,3,4,5].to_vector(:scale)
41
+ assert_equal(120,a.product)
46
42
  end
47
43
  def test_matrix
48
- a=[1,2,3,4,5].to_vector(:scale)
49
- mh=Matrix[[1,2,3,4,5]]
50
- mv=Matrix.columns([[1,2,3,4,5]])
51
- assert_equal(mh,a.to_matrix)
52
- assert_equal(mv,a.to_matrix(:vertical))
53
- # 3*4 + 2*5 = 22
54
- a=[3,2].to_vector(:scale)
55
- b=[4,5].to_vector(:scale)
56
- assert_equal(22,(a.to_matrix*b.to_matrix(:vertical))[0,0])
44
+ a=[1,2,3,4,5].to_vector(:scale)
45
+ mh=Matrix[[1,2,3,4,5]]
46
+ mv=Matrix.columns([[1,2,3,4,5]])
47
+ assert_equal(mh,a.to_matrix)
48
+ assert_equal(mv,a.to_matrix(:vertical))
49
+ # 3*4 + 2*5 = 22
50
+ a=[3,2].to_vector(:scale)
51
+ b=[4,5].to_vector(:scale)
52
+ assert_equal(22,(a.to_matrix*b.to_matrix(:vertical))[0,0])
57
53
  end
58
54
  def test_missing_values
59
55
  @c.missing_values=[10]
@@ -149,10 +145,10 @@ class TestStatsample::TestVector < Test::Unit::TestCase
149
145
  assert_equal(5,@c.median)
150
146
  assert_equal(4,@c.percentil(25))
151
147
  assert_equal(7,@c.percentil(75))
152
-
148
+
153
149
  v=[200000, 200000, 210000, 220000, 230000, 250000, 250000, 250000, 270000, 300000, 450000, 130000, 140000, 140000, 140000, 145000, 148000, 165000, 170000, 180000, 180000, 180000, 180000, 180000, 180000 ].to_scale
154
150
  assert_equal(180000,v.median)
155
-
151
+
156
152
  end
157
153
  def test_ranked
158
154
  v1=[0.8,1.2,1.2,2.3,18].to_vector(:ordinal)
@@ -165,9 +161,9 @@ class TestStatsample::TestVector < Test::Unit::TestCase
165
161
  i=0
166
162
  factors=a.factors.sort
167
163
  [0,1,2,3,4].each{|v|
168
- assert(v==factors[i])
169
- assert(v.class==factors[i].class,"#{v} - #{v.class} != #{factors[i]} - #{factors[i].class}")
170
- i+=1
164
+ assert(v==factors[i])
165
+ assert(v.class==factors[i].class,"#{v} - #{v.class} != #{factors[i]} - #{factors[i].class}")
166
+ i+=1
171
167
  }
172
168
  end
173
169
  def test_vector_standarized
@@ -234,7 +230,7 @@ class TestStatsample::TestVector < Test::Unit::TestCase
234
230
  srand(1)
235
231
  assert_equal(100, @c.sample_with_replacement(100).size)
236
232
  assert_equal(@c.valid_data.to_a.sort, @c.sample_without_replacement(15).sort)
237
-
233
+
238
234
  end
239
235
  def test_valid_data
240
236
  a=Statsample::Vector.new([1,2,3,4,"STRING"])
@@ -273,7 +269,7 @@ class TestStatsample::TestVector < Test::Unit::TestCase
273
269
  a.set_valid_data
274
270
  assert_equal(3,a.sum)
275
271
  b=[1,2,nil,3,4,5,nil,6].to_vector(:scale)
276
- assert_equal(21, b.sum)
272
+ assert_equal(21, b.sum)
277
273
  assert_equal(3.5, b.mean)
278
274
  assert_equal(6,b.gsl.size)
279
275
  c=[10,20,30,40,50,100,1000,2000,5000].to_scale
@@ -281,7 +277,7 @@ class TestStatsample::TestVector < Test::Unit::TestCase
281
277
  assert_in_delta(c.kurtosis, c.kurtosis_slow ,0.0001)
282
278
  end
283
279
  end
284
- def test_vector_matrix
280
+ def test_vector_matrix
285
281
  v1=%w{a a a b b b c c}.to_vector
286
282
  v2=%w{1 3 4 5 6 4 3 2}.to_vector
287
283
  v3=%w{1 0 0 0 1 1 1 0}.to_vector
@@ -299,14 +295,14 @@ class TestStatsample::TestVector < Test::Unit::TestCase
299
295
  assert_equal(v1.data,v2.data)
300
296
  assert_not_same(v1.data,v2.data)
301
297
  assert_equal(v1.type,v2.type)
302
-
298
+
303
299
  v1.type=:ordinal
304
300
  assert_not_equal(v1.type,v2.type)
305
301
  assert_equal(v1.missing_values,v2.missing_values)
306
302
  assert_not_same(v1.missing_values,v2.missing_values)
307
303
  assert_equal(v1.labels,v2.labels)
308
304
  assert_not_same(v1.labels,v2.labels)
309
-
305
+
310
306
  v3=v1.dup_empty
311
307
  assert_equal([],v3.data)
312
308
  assert_not_equal(v1.data,v3.data)
@@ -331,7 +327,7 @@ class TestStatsample::TestVector < Test::Unit::TestCase
331
327
  assert_equal(exp,a.dichotomize)
332
328
  a= [1,1,1,2,2,2,3].to_vector
333
329
  exp=[0,0,0,1,1,1,1].to_scale
334
- assert_equal(exp,a.dichotomize)
330
+ assert_equal(exp,a.dichotomize)
335
331
  a= [0,0,0,1,2,3,nil].to_vector
336
332
  exp=[0,0,0,0,1,1,nil].to_scale
337
333
  assert_equal(exp,a.dichotomize(1))
@@ -346,15 +342,15 @@ class TestStatsample::TestVector < Test::Unit::TestCase
346
342
  assert(!a.can_be_scale?)
347
343
  a.missing_values=["s"]
348
344
  assert(a.can_be_scale?)
349
-
345
+
350
346
  a=[Date.new(2009,10,10), Date.today(), "2009-10-10", "2009-1-1", nil, "NOW"].to_vector
351
347
  assert(a.can_be_date?)
352
348
  a=[Date.new(2009,10,10), Date.today(),nil,"sss"].to_vector
353
- assert(!a.can_be_date?)
349
+ assert(!a.can_be_date?)
354
350
  end
355
351
  def test_date_vector
356
352
  a=[Date.new(2009,10,10), :NOW, "2009-10-10", "2009-1-1", nil, "NOW","MISSING"].to_vector(:date, :missing_values=>["MISSING"])
357
-
353
+
358
354
  assert(a.type==:date)
359
355
  expected=[Date.new(2009,10,10), Date.today(), Date.new(2009,10,10), Date.new(2009,1,1), nil, Date.today(), nil ]
360
356
  assert_equal(expected, a.date_data_with_nils)
data/test/test_xls.rb CHANGED
@@ -1,42 +1,35 @@
1
- $:.unshift(File.dirname(__FILE__)+'/../lib/')
2
- require 'statsample'
3
- require 'test/unit'
4
- require 'tempfile'
5
- begin
6
- require 'spreadsheet'
7
- rescue LoadError
8
- puts "You should install spreadsheet (gem install spreadsheet)"
9
- end
10
- class StatsampleExcelTestCase < Test::Unit::TestCase
11
- def setup
12
- @ds=Statsample::Excel.read(File.dirname(__FILE__)+"/test_xls.xls")
13
- end
14
- def test_read
15
- assert_equal(6,@ds.cases)
16
- assert_equal(%w{id name age city a1},@ds.fields)
17
- id=[1,2,3,4,5,6].to_vector(:scale)
18
- name=["Alex","Claude","Peter","Franz","George","Fernand"].to_vector(:nominal)
19
- age=[20,23,25,nil,5.5,nil].to_vector(:scale)
20
- city=["New York","London","London","Paris","Tome",nil].to_vector(:nominal)
21
- a1=["a,b","b,c","a",nil,"a,b,c",nil].to_vector(:nominal)
22
- ds_exp=Statsample::Dataset.new({'id'=>id,'name'=>name,'age'=>age,'city'=>city,'a1'=>a1}, %w{id name age city a1})
23
- ds_exp.fields.each{|f|
24
- assert_equal(ds_exp[f],@ds[f])
25
- }
26
- assert_equal(ds_exp,@ds)
27
-
28
- end
29
- def test_nil
30
- assert_equal(nil,@ds['age'][5])
1
+ require(File.dirname(__FILE__)+'/test_helpers.rb')
2
+
3
+ class StatsampleExcelTestCase < MiniTest::Unit::TestCase
4
+ def setup
5
+ @ds=Statsample::Excel.read(File.dirname(__FILE__)+"/test_xls.xls")
6
+ end
7
+ def test_read
8
+ assert_equal(6,@ds.cases)
9
+ assert_equal(%w{id name age city a1},@ds.fields)
10
+ id=[1,2,3,4,5,6].to_vector(:scale)
11
+ name=["Alex","Claude","Peter","Franz","George","Fernand"].to_vector(:nominal)
12
+ age=[20,23,25,nil,5.5,nil].to_vector(:scale)
13
+ city=["New York","London","London","Paris","Tome",nil].to_vector(:nominal)
14
+ a1=["a,b","b,c","a",nil,"a,b,c",nil].to_vector(:nominal)
15
+ ds_exp=Statsample::Dataset.new({'id'=>id,'name'=>name,'age'=>age,'city'=>city,'a1'=>a1}, %w{id name age city a1})
16
+ ds_exp.fields.each{|f|
17
+ assert_equal(ds_exp[f],@ds[f])
18
+ }
19
+ assert_equal(ds_exp,@ds)
20
+
21
+ end
22
+ def test_nil
23
+ assert_equal(nil,@ds['age'][5])
24
+ end
25
+ def test_write
26
+ tempfile=Tempfile.new("test_write.xls")
27
+ Statsample::Excel.write(@ds,tempfile.path)
28
+ ds2=Statsample::Excel.read(tempfile.path)
29
+ i=0
30
+ ds2.each_array do |row|
31
+ assert_equal(@ds.case_as_array(i),row)
32
+ i+=1
31
33
  end
32
- def test_write
33
- tempfile=Tempfile.new("test_write.xls")
34
- Statsample::Excel.write(@ds,tempfile.path)
35
- ds2=Statsample::Excel.read(tempfile.path)
36
- i=0
37
- ds2.each_array{|row|
38
- assert_equal(@ds.case_as_array(i),row)
39
- i+=1
40
- }
41
- end
42
- end
34
+ end
35
+ end