diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-09-20 20:18:52 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-09-20 20:18:52 +0000 |
commit | 1d15d5f08032acf1b7bceacbb450d617ff6e0931 (patch) | |
tree | a3785a79899302bc149e4a6e72f624ac27dc1f10 /spec/ruby/library/matrix/spec_helper.rb | |
parent | 75bfc6440d595bf339007f4fb280fd4d743e89c1 (diff) |
Move spec/rubyspec to spec/ruby for consistency
* Other ruby implementations use the spec/ruby directory.
[Misc #13792] [ruby-core:82287]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/library/matrix/spec_helper.rb')
-rw-r--r-- | spec/ruby/library/matrix/spec_helper.rb | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/spec/ruby/library/matrix/spec_helper.rb b/spec/ruby/library/matrix/spec_helper.rb new file mode 100644 index 0000000000..d44612981a --- /dev/null +++ b/spec/ruby/library/matrix/spec_helper.rb @@ -0,0 +1,35 @@ +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 |