statsample 1.4.1 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -3
- data/History.txt +4 -0
- data/README.md +4 -0
- data/lib/statsample/converter/csv.rb +41 -54
- data/lib/statsample/converters.rb +18 -19
- data/lib/statsample/version.rb +1 -1
- data/test/fixtures/scientific_notation.csv +4 -0
- data/test/helpers_tests.rb +37 -38
- data/test/test_analysis.rb +96 -97
- data/test/test_anova_contrast.rb +22 -22
- data/test/test_anovaoneway.rb +12 -12
- data/test/test_anovatwoway.rb +16 -17
- data/test/test_anovatwowaywithdataset.rb +22 -24
- data/test/test_anovawithvectors.rb +67 -69
- data/test/test_awesome_print_bug.rb +9 -9
- data/test/test_bartlettsphericity.rb +13 -13
- data/test/test_bivariate.rb +122 -126
- data/test/test_codification.rb +51 -49
- data/test/test_crosstab.rb +44 -40
- data/test/test_csv.rb +52 -70
- data/test/test_dataset.rb +347 -330
- data/test/test_dominance_analysis.rb +22 -24
- data/test/test_factor.rb +163 -166
- data/test/test_factor_map.rb +25 -30
- data/test/test_factor_pa.rb +28 -28
- data/test/test_ggobi.rb +19 -18
- data/test/test_gsl.rb +13 -15
- data/test/test_histogram.rb +74 -77
- data/test/test_matrix.rb +29 -31
- data/test/test_multiset.rb +132 -126
- data/test/test_regression.rb +143 -149
- data/test/test_reliability.rb +149 -155
- data/test/test_reliability_icc.rb +100 -104
- data/test/test_reliability_skillscale.rb +38 -40
- data/test/test_resample.rb +14 -12
- data/test/test_rserve_extension.rb +33 -33
- data/test/test_srs.rb +5 -5
- data/test/test_statistics.rb +52 -50
- data/test/test_stest.rb +27 -28
- data/test/test_stratified.rb +10 -10
- data/test/test_test_f.rb +17 -17
- data/test/test_test_kolmogorovsmirnov.rb +21 -21
- data/test/test_test_t.rb +52 -52
- data/test/test_umannwhitney.rb +16 -16
- data/test/test_vector.rb +419 -410
- data/test/test_wilcoxonsignedrank.rb +60 -63
- data/test/test_xls.rb +41 -41
- metadata +55 -5
- data/web/Rakefile +0 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21623aa3ff95567e88e39a61d2434421986cab0f
|
4
|
+
data.tar.gz: b756a2e887c54074e1bdc00463300986f7550a25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5862455f9174d9567ef9807fb8356d19f8ae9b13e471470da0a60c6703680f9c5da2ede368b62f1dfb59d67f18e2ac63e693f6fae242b015c831b8960d70649
|
7
|
+
data.tar.gz: a4b8cb9ebca8aacc221d1f32b15516c3a3d7944d8601219b88bbb531af5a83164eb957b38e62c0211c80932d80b4df670c065a942194c844a8c7b722e1c06449
|
data/.travis.yml
CHANGED
data/History.txt
CHANGED
data/README.md
CHANGED
@@ -33,6 +33,10 @@ If you need to work on Structural Equation Modeling, you could see +statsample-s
|
|
33
33
|
$ [sudo] gem install statsample-sem
|
34
34
|
```
|
35
35
|
|
36
|
+
# Documentation
|
37
|
+
|
38
|
+
You can see the latest documentation in [rubydoc.info](http://www.rubydoc.info/github/sciruby/statsample/master).
|
39
|
+
|
36
40
|
# Description
|
37
41
|
|
38
42
|
A suite for basic and advanced statistics on Ruby. Tested on CRuby 1.9.3, 2.0.0 and 2.1.1. See `.travis.yml` for more information.
|
@@ -1,77 +1,64 @@
|
|
1
|
+
require 'csv'
|
2
|
+
|
1
3
|
module Statsample
|
2
4
|
class CSV < SpreadsheetBase
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
CSV_klass=::CSV
|
9
|
-
end
|
10
|
-
class << self
|
5
|
+
# Default options for processing CSV files. Accept the same options as
|
6
|
+
# Ruby's `CSV#new`.
|
7
|
+
DEFAULT_OPTIONS = {
|
8
|
+
converters: [:numeric]
|
9
|
+
}
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
csv_opts.merge!(:headers=>true, :header_converters => :symbol)
|
15
|
-
csv = CSV_klass::Table.new(CSV_klass::read(filename,'r',csv_opts))
|
16
|
-
csv_headers = if csv_opts[:headers]
|
17
|
-
csv.headers
|
18
|
-
else
|
19
|
-
#as in R, if no header we name the headers as V1,V2,V3,V4,..
|
20
|
-
1.upto(csv.first.length).collect { |i| "V#{i}" }
|
21
|
-
end
|
22
|
-
#we invert row -> column. It means csv[0] is the first column and not row. Similar to R
|
23
|
-
csv.by_col!
|
24
|
-
thash = {}
|
25
|
-
csv_headers.each_with_index do |header,idx|
|
26
|
-
thash[header] = Statsample::Vector.new(csv[idx].drop(ignore_lines))
|
27
|
-
end
|
28
|
-
Statsample::Dataset.new(thash)
|
29
|
-
end
|
30
|
-
# Returns a Dataset based on a csv file
|
11
|
+
class << self
|
12
|
+
# Return a Dataset created from a csv file.
|
31
13
|
#
|
32
14
|
# USE:
|
33
|
-
# ds=Statsample::CSV.read(
|
34
|
-
def read(filename, empty=[''],ignore_lines=0,
|
35
|
-
first_row=true
|
36
|
-
fields=[]
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
15
|
+
# ds = Statsample::CSV.read('test_csv.csv')
|
16
|
+
def read(filename, empty = [''], ignore_lines = 0, opts = {})
|
17
|
+
first_row = true
|
18
|
+
fields = []
|
19
|
+
ds = nil
|
20
|
+
line_number = 0
|
21
|
+
options = DEFAULT_OPTIONS.merge(opts)
|
22
|
+
|
23
|
+
csv = ::CSV.open(filename, 'rb', options)
|
24
|
+
|
41
25
|
csv.each do |row|
|
42
|
-
line_number+=1
|
43
|
-
|
44
|
-
|
26
|
+
line_number += 1
|
27
|
+
|
28
|
+
if (line_number <= ignore_lines)
|
45
29
|
next
|
46
30
|
end
|
47
|
-
|
31
|
+
|
48
32
|
if first_row
|
49
|
-
fields=extract_fields(row)
|
50
|
-
ds=Statsample::Dataset.new(fields)
|
51
|
-
first_row=false
|
33
|
+
fields = extract_fields(row)
|
34
|
+
ds = Statsample::Dataset.new(fields)
|
35
|
+
first_row = false
|
52
36
|
else
|
53
|
-
rowa=process_row(row,empty)
|
54
|
-
ds.add_case(rowa,false)
|
37
|
+
rowa = process_row(row, empty)
|
38
|
+
ds.add_case(rowa, false)
|
55
39
|
end
|
56
40
|
end
|
57
|
-
|
41
|
+
|
42
|
+
convert_to_scale_and_date(ds, fields)
|
58
43
|
ds.update_valid_data
|
59
44
|
ds
|
60
45
|
end
|
61
|
-
|
46
|
+
|
47
|
+
# Save a Dataset on a csv file.
|
62
48
|
#
|
63
49
|
# USE:
|
64
|
-
# Statsample::CSV.write(ds,
|
65
|
-
def write(dataset,filename, convert_comma=false
|
66
|
-
|
67
|
-
|
50
|
+
# Statsample::CSV.write(ds, 'test_csv.csv')
|
51
|
+
def write(dataset, filename, convert_comma = false, opts = {})
|
52
|
+
options = DEFAULT_OPTIONS.merge(opts)
|
53
|
+
|
54
|
+
writer = ::CSV.open(filename, 'w', options)
|
68
55
|
writer << dataset.fields
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
end
|
56
|
+
|
57
|
+
dataset.each_array do |row|
|
58
|
+
row.collect! { |v| v.to_s.gsub('.', ',') } if convert_comma
|
73
59
|
writer << row
|
74
60
|
end
|
61
|
+
|
75
62
|
writer.close
|
76
63
|
end
|
77
64
|
end
|
@@ -31,13 +31,13 @@ module Statsample
|
|
31
31
|
# Insert each case of the Dataset on the selected table
|
32
32
|
#
|
33
33
|
# USE:
|
34
|
-
#
|
34
|
+
#
|
35
35
|
# ds={'id'=>[1,2,3].to_vector, 'name'=>["a","b","c"].to_vector}.to_dataset
|
36
36
|
# dbh = DBI.connect("DBI:Mysql:database:localhost", "user", "password")
|
37
37
|
# Statsample::Database.insert(ds,dbh,"test")
|
38
38
|
#
|
39
39
|
def insert(ds, dbh, table)
|
40
|
-
require 'dbi'
|
40
|
+
require 'dbi'
|
41
41
|
query="INSERT INTO #{table} ("+ds.fields.join(",")+") VALUES ("+((["?"]*ds.fields.size).join(","))+")"
|
42
42
|
sth=dbh.prepare(query)
|
43
43
|
ds.each_array{|c| sth.execute(*c) }
|
@@ -46,11 +46,11 @@ module Statsample
|
|
46
46
|
# Create a sql, basen on a given Dataset
|
47
47
|
#
|
48
48
|
# USE:
|
49
|
-
#
|
49
|
+
#
|
50
50
|
# ds={'id'=>[1,2,3,4,5].to_vector,'name'=>%w{Alex Peter Susan Mary John}.to_vector}.to_dataset
|
51
51
|
# Statsample::Database.create_sql(ds,'names')
|
52
52
|
# ==>"CREATE TABLE names (id INTEGER,\n name VARCHAR (255)) CHARACTER SET=UTF8;"
|
53
|
-
#
|
53
|
+
#
|
54
54
|
def create_sql(ds,table,charset="UTF8")
|
55
55
|
sql="CREATE TABLE #{table} ("
|
56
56
|
fields=ds.fields.collect{|f|
|
@@ -81,14 +81,14 @@ module Statsample
|
|
81
81
|
fields=row.to_a.collect{|c|
|
82
82
|
if c.nil?
|
83
83
|
i+=1
|
84
|
-
"var%05d" % i
|
84
|
+
"var%05d" % i
|
85
85
|
else
|
86
86
|
c.to_s.downcase
|
87
|
-
end
|
87
|
+
end
|
88
88
|
}
|
89
89
|
fields.recode_repeated
|
90
90
|
end
|
91
|
-
|
91
|
+
|
92
92
|
def process_row(row,empty)
|
93
93
|
row.to_a.map do |c|
|
94
94
|
if empty.include?(c)
|
@@ -115,7 +115,7 @@ module Statsample
|
|
115
115
|
end
|
116
116
|
end
|
117
117
|
end
|
118
|
-
|
118
|
+
|
119
119
|
end
|
120
120
|
end
|
121
121
|
class PlainText < SpreadsheetBase
|
@@ -137,7 +137,7 @@ module Statsample
|
|
137
137
|
end
|
138
138
|
end
|
139
139
|
end
|
140
|
-
class Excel < SpreadsheetBase
|
140
|
+
class Excel < SpreadsheetBase
|
141
141
|
class << self
|
142
142
|
# Write a Excel spreadsheet based on a dataset
|
143
143
|
# * TODO: Format nicely date values
|
@@ -177,7 +177,7 @@ module Statsample
|
|
177
177
|
}
|
178
178
|
end
|
179
179
|
private :process_row, :preprocess_row
|
180
|
-
|
180
|
+
|
181
181
|
# Returns a dataset based on a xls file
|
182
182
|
# USE:
|
183
183
|
# ds = Statsample::Excel.read("test.xls")
|
@@ -186,20 +186,19 @@ module Statsample
|
|
186
186
|
require 'spreadsheet'
|
187
187
|
raise "options should be Hash" unless opts.is_a? Hash
|
188
188
|
opts_default={
|
189
|
-
:worksheet_id=>0,
|
190
|
-
:ignore_lines=>0,
|
189
|
+
:worksheet_id=>0,
|
190
|
+
:ignore_lines=>0,
|
191
191
|
:empty=>['']
|
192
192
|
}
|
193
|
-
|
193
|
+
|
194
194
|
opts=opts_default.merge opts
|
195
|
-
|
195
|
+
|
196
196
|
worksheet_id=opts[:worksheet_id]
|
197
197
|
ignore_lines=opts[:ignore_lines]
|
198
198
|
empty=opts[:empty]
|
199
|
-
|
199
|
+
|
200
200
|
first_row=true
|
201
201
|
fields=[]
|
202
|
-
fields_data={}
|
203
202
|
ds=nil
|
204
203
|
line_number=0
|
205
204
|
book = Spreadsheet.open filename
|
@@ -214,7 +213,7 @@ module Statsample
|
|
214
213
|
}
|
215
214
|
line_number+=1
|
216
215
|
next if(line_number<=ignore_lines)
|
217
|
-
|
216
|
+
|
218
217
|
preprocess_row(row,dates)
|
219
218
|
if first_row
|
220
219
|
fields=extract_fields(row)
|
@@ -296,7 +295,7 @@ module Statsample
|
|
296
295
|
variables_def=dataset.fields.collect{|k|
|
297
296
|
variable_definition(carrier,dataset[k],k)
|
298
297
|
}.join("\n")
|
299
|
-
|
298
|
+
|
300
299
|
indexes=carrier.categorials.inject({}) {|s,c|
|
301
300
|
s[dataset.fields.index(c)]=c
|
302
301
|
s
|
@@ -308,7 +307,7 @@ module Statsample
|
|
308
307
|
}
|
309
308
|
records << "<record>#{values_definition(c, default_opt[:missing])}</record>\n"
|
310
309
|
}
|
311
|
-
|
310
|
+
|
312
311
|
out=<<EOC
|
313
312
|
<?xml version="1.0"?>
|
314
313
|
<!DOCTYPE ggobidata SYSTEM "ggobi.dtd">
|
data/lib/statsample/version.rb
CHANGED
data/test/helpers_tests.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib/'))
|
2
|
+
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/'))
|
3
|
+
|
3
4
|
require 'minitest'
|
4
5
|
require 'minitest/unit'
|
5
6
|
require 'mocha/setup'
|
@@ -11,67 +12,65 @@ require 'fixtures/correlation_matrix'
|
|
11
12
|
|
12
13
|
require 'statsample'
|
13
14
|
|
14
|
-
|
15
|
-
module MiniTest
|
15
|
+
module Minitest
|
16
16
|
class Test
|
17
17
|
include Shoulda::Context::Assertions
|
18
18
|
include Shoulda::Context::InstanceMethods
|
19
19
|
extend Shoulda::Context::ClassMethods
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
20
|
+
|
21
|
+
def self.should_with_gsl(name, &block)
|
22
|
+
should(name) do
|
23
|
+
if Statsample.has_gsl?
|
24
|
+
instance_eval(&block)
|
25
|
+
else
|
26
|
+
skip('Requires GSL')
|
28
27
|
end
|
29
|
-
|
30
|
-
|
28
|
+
end
|
31
29
|
end
|
32
30
|
end
|
33
31
|
|
34
32
|
module Assertions
|
35
|
-
def assert_similar_vector(exp, obs, delta=1e-10,msg=nil)
|
36
|
-
msg||="Different vectors #{exp} - #{obs}"
|
33
|
+
def assert_similar_vector(exp, obs, delta = 1e-10, msg = nil)
|
34
|
+
msg ||= "Different vectors #{exp} - #{obs}"
|
37
35
|
assert_equal(exp.size, obs.size)
|
38
|
-
exp.data_with_nils.each_with_index {|v,i|
|
39
|
-
assert_in_delta(v,obs[i],delta)
|
36
|
+
exp.data_with_nils.each_with_index {|v, i|
|
37
|
+
assert_in_delta(v, obs[i], delta)
|
40
38
|
}
|
41
39
|
end
|
42
|
-
|
40
|
+
|
41
|
+
def assert_equal_vector(exp, obs, delta = 1e-10, msg = nil)
|
43
42
|
assert_equal(exp.size, obs.size, "Different size.#{msg}")
|
44
43
|
exp.size.times {|i|
|
45
|
-
assert_in_delta(exp[i],obs[i],delta, "Different element #{i}. \nExpected:\n#{exp}\nObserved:\n#{obs}.#{msg}")
|
44
|
+
assert_in_delta(exp[i], obs[i], delta, "Different element #{i}. \nExpected:\n#{exp}\nObserved:\n#{obs}.#{msg}")
|
46
45
|
}
|
47
46
|
end
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
47
|
+
|
48
|
+
def assert_equal_matrix(exp, obs, delta = 1e-10, msg = nil)
|
49
|
+
assert_equal(exp.row_size, obs.row_size, "Different row size.#{msg}")
|
50
|
+
assert_equal(exp.column_size, obs.column_size, "Different column size.#{msg}")
|
51
|
+
exp.row_size.times {|i|
|
52
|
+
exp.column_size.times {|j|
|
53
|
+
assert_in_delta(exp[i, j], obs[i, j], delta, "Different element #{i},#{j}\nExpected:\n#{exp}\nObserved:\n#{obs}.#{msg}")
|
54
|
+
}
|
55
|
+
}
|
56
56
|
end
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
alias_method :assert_raise, :assert_raises unless method_defined? :assert_raise
|
58
|
+
alias_method :assert_not_equal, :refute_equal unless method_defined? :assert_not_equal
|
59
|
+
alias_method :assert_not_same, :refute_same unless method_defined? :assert_not_same
|
60
60
|
unless method_defined? :assert_nothing_raised
|
61
|
-
def assert_nothing_raised(msg=nil)
|
62
|
-
msg||=
|
61
|
+
def assert_nothing_raised(msg = nil)
|
62
|
+
msg ||= 'Nothing should be raised, but raised %s'
|
63
63
|
begin
|
64
64
|
yield
|
65
|
-
not_raised=true
|
65
|
+
not_raised = true
|
66
66
|
rescue Exception => e
|
67
|
-
not_raised=false
|
68
|
-
msg=sprintf(msg,e)
|
67
|
+
not_raised = false
|
68
|
+
msg = sprintf(msg, e)
|
69
69
|
end
|
70
|
-
assert(not_raised,msg)
|
70
|
+
assert(not_raised, msg)
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
76
|
MiniTest.autorun
|
77
|
-
|
data/test/test_analysis.rb
CHANGED
@@ -1,77 +1,77 @@
|
|
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 StatsampleAnalysisTestCase <
|
3
|
+
class StatsampleAnalysisTestCase < Minitest::Test
|
4
4
|
context(Statsample::Analysis) do
|
5
5
|
setup do
|
6
6
|
Statsample::Analysis.clear_analysis
|
7
7
|
end
|
8
|
-
should
|
8
|
+
should 'store() should create and store Statsample::Analysis::Suite' do
|
9
9
|
Statsample::Analysis.store(:first) do
|
10
|
-
a=1
|
10
|
+
a = 1
|
11
11
|
end
|
12
12
|
assert(Statsample::Analysis.stored_analysis[:first])
|
13
13
|
assert(Statsample::Analysis.stored_analysis[:first].is_a? Statsample::Analysis::Suite)
|
14
14
|
end
|
15
|
-
|
16
|
-
should
|
17
|
-
ss_analysis(:first) {a=1}
|
15
|
+
|
16
|
+
should 'ss_analysis should create an Statsample::Analysis' do
|
17
|
+
ss_analysis(:first) { a = 1 }
|
18
18
|
end
|
19
|
-
should
|
20
|
-
an=Statsample::Analysis.store(:first) do
|
21
|
-
a=1
|
19
|
+
should 'store last created analysis' do
|
20
|
+
an = Statsample::Analysis.store(:first) do
|
21
|
+
a = 1
|
22
22
|
end
|
23
|
-
assert_equal(an,Statsample::Analysis.last)
|
23
|
+
assert_equal(an, Statsample::Analysis.last)
|
24
24
|
end
|
25
|
-
|
26
|
-
should
|
27
|
-
rb=mock
|
28
|
-
rb.expects(:add).with {|value| value.is_a? ReportBuilder::Section and value.name
|
29
|
-
rb.expects(:add).with {|value| value.is_a? ReportBuilder::Section and value.name
|
30
|
-
|
25
|
+
|
26
|
+
should 'add_to_reportbuilder() add sections to reportbuilder object' do
|
27
|
+
rb = mock
|
28
|
+
rb.expects(:add).with { |value| value.is_a? ReportBuilder::Section and value.name == :first }
|
29
|
+
rb.expects(:add).with { |value| value.is_a? ReportBuilder::Section and value.name == :second }
|
30
|
+
|
31
31
|
Statsample::Analysis.store(:first) do
|
32
|
-
echo
|
32
|
+
echo 'first', 'second'
|
33
33
|
end
|
34
34
|
Statsample::Analysis.store(:second) do
|
35
|
-
echo
|
35
|
+
echo 'third'
|
36
36
|
end
|
37
|
-
Statsample::Analysis.add_to_reportbuilder(rb
|
37
|
+
Statsample::Analysis.add_to_reportbuilder(rb, :first, :second)
|
38
38
|
end
|
39
|
-
should
|
40
|
-
rb=ReportBuilder.new(:
|
41
|
-
section=ReportBuilder::Section.new(:
|
42
|
-
a=[1,2,3].to_scale
|
43
|
-
section.add(
|
39
|
+
should 'to_text returns the same as a normal ReportBuilder object' do
|
40
|
+
rb = ReportBuilder.new(name: :test)
|
41
|
+
section = ReportBuilder::Section.new(name: 'first')
|
42
|
+
a = [1, 2, 3].to_scale
|
43
|
+
section.add('first')
|
44
44
|
section.add(a)
|
45
45
|
rb.add(section)
|
46
|
-
exp=rb.to_text
|
47
|
-
an=ss_analysis(:first) {
|
46
|
+
exp = rb.to_text
|
47
|
+
an = ss_analysis(:first) {
|
48
48
|
echo 'first'
|
49
49
|
summary(a)
|
50
50
|
}
|
51
|
-
obs=Statsample::Analysis.to_text(:first)
|
52
|
-
|
53
|
-
assert_equal(exp.split("\n")[1,exp.size], obs.split("\n")[1,obs.size])
|
51
|
+
obs = Statsample::Analysis.to_text(:first)
|
52
|
+
|
53
|
+
assert_equal(exp.split("\n")[1, exp.size], obs.split("\n")[1, obs.size])
|
54
54
|
end
|
55
|
-
|
56
|
-
should
|
57
|
-
m1=mock
|
55
|
+
|
56
|
+
should 'run() execute all analysis by default' do
|
57
|
+
m1 = mock
|
58
58
|
m1.expects(:run).once
|
59
59
|
m1.expects(:hide).once
|
60
|
-
|
60
|
+
|
61
61
|
Statsample::Analysis.store(:first) do
|
62
62
|
m1.run
|
63
63
|
end
|
64
64
|
Statsample::Analysis.store(:second) do
|
65
65
|
m1.hide
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
# Should run all test
|
69
69
|
Statsample::Analysis.run
|
70
70
|
end
|
71
|
-
|
72
|
-
should
|
73
|
-
m1=mock
|
74
|
-
m1.expects(:run).once
|
71
|
+
|
72
|
+
should 'run() execute blocks specificed on parameters' do
|
73
|
+
m1 = mock
|
74
|
+
m1.expects(:run).once
|
75
75
|
m1.expects(:hide).never
|
76
76
|
Statsample::Analysis.store(:first) do
|
77
77
|
m1.run
|
@@ -82,78 +82,78 @@ class StatsampleAnalysisTestCase < MiniTest::Unit::TestCase
|
|
82
82
|
# Should run all test
|
83
83
|
Statsample::Analysis.run(:first)
|
84
84
|
end
|
85
|
-
|
85
|
+
|
86
86
|
context(Statsample::Analysis::Suite) do
|
87
|
-
should
|
88
|
-
an=Statsample::Analysis::Suite.new(:output)
|
89
|
-
obj=mock
|
90
|
-
obj.expects(:puts).with(:first
|
91
|
-
an.output=obj
|
92
|
-
an.echo(:first
|
93
|
-
end
|
94
|
-
should
|
95
|
-
an=Statsample::Analysis::Suite.new(:summary)
|
96
|
-
obj=stub('summarizable'
|
97
|
-
assert_equal(obj.summary,an.summary(obj))
|
98
|
-
end
|
99
|
-
should
|
100
|
-
an=Statsample::Analysis::Suite.new(:summary)
|
101
|
-
ds={'x'=>stub(:
|
102
|
-
ds.expects(:fields).returns(%w
|
87
|
+
should 'echo() uses output#puts with same arguments' do
|
88
|
+
an = Statsample::Analysis::Suite.new(:output)
|
89
|
+
obj = mock
|
90
|
+
obj.expects(:puts).with(:first, :second).once
|
91
|
+
an.output = obj
|
92
|
+
an.echo(:first, :second)
|
93
|
+
end
|
94
|
+
should 'summary() should call object.summary' do
|
95
|
+
an = Statsample::Analysis::Suite.new(:summary)
|
96
|
+
obj = stub('summarizable', summary: 'summary')
|
97
|
+
assert_equal(obj.summary, an.summary(obj))
|
98
|
+
end
|
99
|
+
should 'attach() allows to call objects on objects which respond to fields' do
|
100
|
+
an = Statsample::Analysis::Suite.new(:summary)
|
101
|
+
ds = { 'x' => stub(mean: 10), 'y' => stub(mean: 12) }
|
102
|
+
ds.expects(:fields).returns(%w(x y)).at_least_once
|
103
103
|
an.attach(ds)
|
104
|
-
assert_equal(10,an.x.mean)
|
105
|
-
assert_equal(12,an.y.mean)
|
104
|
+
assert_equal(10, an.x.mean)
|
105
|
+
assert_equal(12, an.y.mean)
|
106
106
|
assert_raise(RuntimeError) {
|
107
107
|
an.z
|
108
108
|
}
|
109
109
|
end
|
110
|
-
should
|
111
|
-
an=Statsample::Analysis::Suite.new(:summary)
|
112
|
-
ds1={'x'=>stub(:
|
113
|
-
ds1.expects(:fields).returns(%w
|
114
|
-
ds2={'x'=>stub(:
|
115
|
-
ds2.expects(:fields).returns(%w
|
110
|
+
should 'attached objects should be called LIFO' do
|
111
|
+
an = Statsample::Analysis::Suite.new(:summary)
|
112
|
+
ds1 = { 'x' => stub(mean: 100), 'y' => stub(mean: 120), 'z' => stub(mean: 13) }
|
113
|
+
ds1.expects(:fields).returns(%w(x y z)).at_least_once
|
114
|
+
ds2 = { 'x' => stub(mean: 10), 'y' => stub(mean: 12) }
|
115
|
+
ds2.expects(:fields).returns(%w(x y)).at_least_once
|
116
116
|
an.attach(ds1)
|
117
117
|
an.attach(ds2)
|
118
|
-
assert_equal(10,an.x.mean)
|
119
|
-
assert_equal(12,an.y.mean)
|
120
|
-
assert_equal(13,an.z.mean)
|
121
|
-
end
|
122
|
-
|
123
|
-
should
|
124
|
-
an=Statsample::Analysis::Suite.new(:summary)
|
125
|
-
ds1={'x'=>stub(:
|
126
|
-
ds1.expects(:fields).returns(%w
|
127
|
-
ds2={'x'=>stub(:
|
128
|
-
ds2.expects(:fields).returns(%w
|
118
|
+
assert_equal(10, an.x.mean)
|
119
|
+
assert_equal(12, an.y.mean)
|
120
|
+
assert_equal(13, an.z.mean)
|
121
|
+
end
|
122
|
+
|
123
|
+
should 'detach() without arguments drop latest object' do
|
124
|
+
an = Statsample::Analysis::Suite.new(:summary)
|
125
|
+
ds1 = { 'x' => stub(mean: 100), 'y' => stub(mean: 120), 'z' => stub(mean: 13) }
|
126
|
+
ds1.expects(:fields).returns(%w(x y z)).at_least_once
|
127
|
+
ds2 = { 'x' => stub(mean: 10), 'y' => stub(mean: 12) }
|
128
|
+
ds2.expects(:fields).returns(%w(x y)).at_least_once
|
129
129
|
an.attach(ds1)
|
130
130
|
an.attach(ds2)
|
131
|
-
assert_equal(10,an.x.mean)
|
131
|
+
assert_equal(10, an.x.mean)
|
132
132
|
an.detach
|
133
133
|
assert_equal(100, an.x.mean)
|
134
134
|
end
|
135
|
-
should
|
136
|
-
an=Statsample::Analysis::Suite.new(:summary)
|
137
|
-
ds1={'x'=>1}
|
138
|
-
ds1.expects(:fields).returns(%w
|
139
|
-
ds2={'x'=>2,'y'=>3}
|
140
|
-
ds2.expects(:fields).returns(%w
|
141
|
-
ds3={'y'=>4}
|
142
|
-
ds3.expects(:fields).returns(%w
|
143
|
-
|
135
|
+
should 'detach() with argument drop select object' do
|
136
|
+
an = Statsample::Analysis::Suite.new(:summary)
|
137
|
+
ds1 = { 'x' => 1 }
|
138
|
+
ds1.expects(:fields).returns(%w(x)).at_least_once
|
139
|
+
ds2 = { 'x' => 2, 'y' => 3 }
|
140
|
+
ds2.expects(:fields).returns(%w(x y)).at_least_once
|
141
|
+
ds3 = { 'y' => 4 }
|
142
|
+
ds3.expects(:fields).returns(%w(y)).at_least_once
|
143
|
+
|
144
144
|
an.attach(ds3)
|
145
145
|
an.attach(ds2)
|
146
146
|
an.attach(ds1)
|
147
|
-
assert_equal(1,an.x)
|
148
|
-
assert_equal(3,an.y)
|
147
|
+
assert_equal(1, an.x)
|
148
|
+
assert_equal(3, an.y)
|
149
149
|
an.detach(ds2)
|
150
|
-
assert_equal(4,an.y)
|
150
|
+
assert_equal(4, an.y)
|
151
151
|
end
|
152
|
-
should
|
153
|
-
output=mock
|
152
|
+
should 'perform a simple analysis' do
|
153
|
+
output = mock
|
154
154
|
output.expects(:puts).with(5.5)
|
155
|
-
an=Statsample::Analysis.store(:simple, :output
|
156
|
-
ds=data_frame(:
|
155
|
+
an = Statsample::Analysis.store(:simple, output: output) do
|
156
|
+
ds = data_frame(x: vector(1..10), y: vector(1..10))
|
157
157
|
attach(ds)
|
158
158
|
echo x.mean
|
159
159
|
end
|
@@ -161,17 +161,16 @@ class StatsampleAnalysisTestCase < MiniTest::Unit::TestCase
|
|
161
161
|
end
|
162
162
|
end
|
163
163
|
context(Statsample::Analysis::SuiteReportBuilder) do
|
164
|
-
should
|
165
|
-
an=Statsample::Analysis::SuiteReportBuilder.new(:puts_to_add)
|
164
|
+
should 'echo() use add on rb object' do
|
165
|
+
an = Statsample::Analysis::SuiteReportBuilder.new(:puts_to_add)
|
166
166
|
an.rb.expects(:add).with(:first).twice
|
167
167
|
an.echo(:first, :first)
|
168
168
|
end
|
169
|
-
should
|
170
|
-
an=Statsample::Analysis::SuiteReportBuilder.new(:summary_to_add)
|
169
|
+
should 'summary() uses add on rb object' do
|
170
|
+
an = Statsample::Analysis::SuiteReportBuilder.new(:summary_to_add)
|
171
171
|
an.rb.expects(:add).with(:first).once
|
172
172
|
an.summary(:first)
|
173
173
|
end
|
174
174
|
end
|
175
|
-
|
176
175
|
end
|
177
176
|
end
|