diff options
Diffstat (limited to 'spec/ruby/library/matrix/exponent_spec.rb')
| -rw-r--r-- | spec/ruby/library/matrix/exponent_spec.rb | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/spec/ruby/library/matrix/exponent_spec.rb b/spec/ruby/library/matrix/exponent_spec.rb index 188a1b34d2..4cbe63587d 100644 --- a/spec/ruby/library/matrix/exponent_spec.rb +++ b/spec/ruby/library/matrix/exponent_spec.rb @@ -1,5 +1,5 @@ -require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../fixtures/classes', __FILE__) +require_relative '../../spec_helper' +require_relative 'fixtures/classes' require 'matrix' describe "Matrix#**" do @@ -17,21 +17,32 @@ describe "Matrix#**" do it "raises a ErrDimensionMismatch for non square matrices" do m = Matrix[ [1, 1], [1, 2], [2, 3]] - lambda { m ** 3 }.should raise_error(Matrix::ErrDimensionMismatch) - lambda { m ** 0 }.should raise_error(Matrix::ErrDimensionMismatch) + -> { m ** 3 }.should.raise(Matrix::ErrDimensionMismatch) + -> { m ** 0 }.should.raise(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] ] - lambda { m ** -2 }.should raise_error(Matrix::ErrNotRegular) - lambda { m ** 0 }.should raise_error(Matrix::ErrNotRegular) + -> { m ** -2 }.should.raise(Matrix::ErrNotRegular) + end + end + + 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(Matrix::ErrDimensionMismatch) end end end @@ -45,7 +56,7 @@ describe "Matrix#**" do describe "for a subclass of Matrix" do it "returns an instance of that subclass" do - (MatrixSub.ins ** 1).should be_an_instance_of(MatrixSub) + (MatrixSub.ins ** 1).should.instance_of?(MatrixSub) end end end |
