/
helpers_tests.rb
77 lines (68 loc) · 2.29 KB
/
helpers_tests.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
$:.unshift(File.expand_path(File.dirname(__FILE__)+'/../lib/'))
$:.unshift(File.expand_path(File.dirname(__FILE__)+'/'))
require 'minitest'
require 'minitest/unit'
require 'mocha/setup'
require 'tempfile'
require 'tmpdir'
require 'shoulda'
require 'shoulda-context'
require 'fixtures/correlation_matrix'
require 'statsample'
module MiniTest
class Test
include Shoulda::Context::Assertions
include Shoulda::Context::InstanceMethods
extend Shoulda::Context::ClassMethods
def self.should_with_gsl(name,&block)
should(name) do
if Statsample.has_gsl?
instance_eval(&block)
else
skip("Requires GSL")
end
end
end
end
module Assertions
def assert_similar_vector(exp, obs, delta=1e-10,msg=nil)
msg||="Different vectors #{exp} - #{obs}"
assert_equal(exp.size, obs.size)
exp.data_with_nils.each_with_index {|v,i|
assert_in_delta(v,obs[i],delta)
}
end
def assert_equal_vector(exp,obs,delta=1e-10,msg=nil)
assert_equal(exp.size, obs.size, "Different size.#{msg}")
exp.size.times {|i|
assert_in_delta(exp[i],obs[i],delta, "Different element #{i}. \nExpected:\n#{exp}\nObserved:\n#{obs}.#{msg}")
}
end
def assert_equal_matrix(exp,obs,delta=1e-10,msg=nil)
assert_equal(exp.row_size, obs.row_size, "Different row size.#{msg}")
assert_equal(exp.column_size, obs.column_size, "Different column size.#{msg}")
exp.row_size.times {|i|
exp.column_size.times {|j|
assert_in_delta(exp[i,j],obs[i,j], delta, "Different element #{i},#{j}\nExpected:\n#{exp}\nObserved:\n#{obs}.#{msg}")
}
}
end
alias :assert_raise :assert_raises unless method_defined? :assert_raise
alias :assert_not_equal :refute_equal unless method_defined? :assert_not_equal
alias :assert_not_same :refute_same unless method_defined? :assert_not_same
unless method_defined? :assert_nothing_raised
def assert_nothing_raised(msg=nil)
msg||="Nothing should be raised, but raised %s"
begin
yield
not_raised=true
rescue Exception => e
not_raised=false
msg=sprintf(msg,e)
end
assert(not_raised,msg)
end
end
end
end
MiniTest.autorun