diff options
author | Marc-André Lafortune <[email protected]> | 2021-01-10 16:21:10 -0500 |
---|---|---|
committer | GitHub <[email protected]> | 2021-01-10 16:21:10 -0500 |
commit | d8c8b79d24bf0f3177535501ad9b801e552fb2ad (patch) | |
tree | 7ec8bca59d51ebacdba899fbbf733736772f76ae /spec/ruby/library/matrix | |
parent | 8187228de0142d3ac7950b7d977c2849e934c637 (diff) |
[ruby/matrix] Fix 0-th power [Bug #17521] (#4047)
Notes
Notes:
Merged-By: marcandre <[email protected]>
Diffstat (limited to 'spec/ruby/library/matrix')
-rw-r--r-- | spec/ruby/library/matrix/exponent_spec.rb | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/spec/ruby/library/matrix/exponent_spec.rb b/spec/ruby/library/matrix/exponent_spec.rb index 447c962967..7eb478e1a7 100644 --- a/spec/ruby/library/matrix/exponent_spec.rb +++ b/spec/ruby/library/matrix/exponent_spec.rb @@ -21,17 +21,30 @@ describe "Matrix#**" do -> { m ** 0 }.should raise_error(Matrix::ErrDimensionMismatch) end - describe "that is <= 0" do + describe "that is < 0" do it "returns the inverse of **(-n)" do m = Matrix[ [1, 1], [1, 2] ] (m ** -2).should == Matrix[ [5, -3], [-3, 2]] (m ** -4).should == (m.inverse ** 4) end - it "raises a ErrDimensionMismatch for irregular matrices" do + it "raises a ErrNotRegular for irregular matrices" do m = Matrix[ [1, 1], [1, 1] ] -> { m ** -2 }.should raise_error(Matrix::ErrNotRegular) - -> { m ** 0 }.should raise_error(Matrix::ErrNotRegular) + end + end + + ruby_bug '#17521', ''..'3.0.0' do + describe "that is 0" do + it "returns the identity for square matrices" do + m = Matrix[ [1, 1], [1, 1] ] + (m ** 0).should == Matrix.identity(2) + end + + it "raises an ErrDimensionMismatch for non-square matrices" do + m = Matrix[ [1, 1] ] + -> { m ** 0 }.should raise_error(Matrix::ErrDimensionMismatch) + end end end end |