mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
95e8c48dd3
* For easier modifications of ruby/spec by MRI developers. * .gitignore: track changes under spec. * spec/mspec, spec/rubyspec: add in-tree mspec and ruby/spec. These files can therefore be updated like any other file in MRI. Instructions are provided in spec/README. [Feature #13156] [ruby-core:79246] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58595 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
35 lines
998 B
Ruby
35 lines
998 B
Ruby
class BeCloseToMatrixMatcher
|
|
def initialize(expected, tolerance = TOLERANCE)
|
|
SpecExpectation.matcher! rescue "Used with the balance_should_and_match branch of mspec"
|
|
@expected = Matrix[*expected]
|
|
@tolerance = tolerance
|
|
end
|
|
|
|
def matches?(actual)
|
|
@actual = actual
|
|
return false unless @actual.is_a? Matrix
|
|
return false unless @actual.row_size == @expected.row_size
|
|
@actual.row_size.times do |i|
|
|
a, e = @actual.row(i), @expected.row(i)
|
|
return false unless a.size == e.size
|
|
a.size.times do |j|
|
|
return false unless (a[j] - e[j]).abs < @tolerance
|
|
end
|
|
end
|
|
true
|
|
end
|
|
|
|
def failure_message
|
|
["Expected #{@expected}", "to be within +/- #{@tolerance} of #{@actual}"]
|
|
end
|
|
|
|
def negative_failure_message
|
|
["Expected #{@expected}", "not to be within +/- #{@tolerance} of #{@actual}"]
|
|
end
|
|
end
|
|
|
|
class Object
|
|
def be_close_to_matrix(expected, tolerance = TOLERANCE)
|
|
BeCloseToMatrixMatcher.new(expected, tolerance)
|
|
end
|
|
end
|