diff options
Diffstat (limited to 'spec/ruby/library/matrix')
28 files changed, 215 insertions, 250 deletions
diff --git a/spec/ruby/library/matrix/I_spec.rb b/spec/ruby/library/matrix/I_spec.rb index 6eeffe8e98..ca5e79279a 100644 --- a/spec/ruby/library/matrix/I_spec.rb +++ b/spec/ruby/library/matrix/I_spec.rb @@ -1,6 +1,8 @@ require_relative '../../spec_helper' -require_relative 'shared/identity' +require 'matrix' describe "Matrix.I" do - it_behaves_like :matrix_identity, :I + it "is an alias of Matrix.identity" do + Matrix.method(:I).should == Matrix.method(:identity) + end end diff --git a/spec/ruby/library/matrix/collect_spec.rb b/spec/ruby/library/matrix/collect_spec.rb index bba640213b..664c3f3038 100644 --- a/spec/ruby/library/matrix/collect_spec.rb +++ b/spec/ruby/library/matrix/collect_spec.rb @@ -1,6 +1,8 @@ require_relative '../../spec_helper' -require_relative 'shared/collect' +require 'matrix' describe "Matrix#collect" do - it_behaves_like :collect, :collect + it "is an alias of Matrix#map" do + Matrix.instance_method(:collect).should == Matrix.instance_method(:map) + end end diff --git a/spec/ruby/library/matrix/conj_spec.rb b/spec/ruby/library/matrix/conj_spec.rb index ecee95c255..eff5986fc4 100644 --- a/spec/ruby/library/matrix/conj_spec.rb +++ b/spec/ruby/library/matrix/conj_spec.rb @@ -1,6 +1,8 @@ require_relative '../../spec_helper' -require_relative 'shared/conjugate' +require 'matrix' describe "Matrix#conj" do - it_behaves_like :matrix_conjugate, :conj + it "is an alias of Matrix#conjugate" do + Matrix.instance_method(:conj).should == Matrix.instance_method(:conjugate) + end end diff --git a/spec/ruby/library/matrix/conjugate_spec.rb b/spec/ruby/library/matrix/conjugate_spec.rb index 682bd41d94..46077d4fa9 100644 --- a/spec/ruby/library/matrix/conjugate_spec.rb +++ b/spec/ruby/library/matrix/conjugate_spec.rb @@ -1,6 +1,20 @@ require_relative '../../spec_helper' -require_relative 'shared/conjugate' +require_relative 'fixtures/classes' describe "Matrix#conjugate" do - it_behaves_like :matrix_conjugate, :conjugate + it "returns a matrix with all entries 'conjugated'" do + Matrix[ [1, 2], [3, 4] ].conjugate.should == Matrix[ [1, 2], [3, 4] ] + Matrix[ [1.9, Complex(1,1)], [3, 4] ].conjugate.should == Matrix[ [1.9, Complex(1,-1)], [3, 4] ] + end + + it "returns empty matrices on the same size if empty" do + Matrix.empty(0, 3).conjugate.should == Matrix.empty(0, 3) + Matrix.empty(3, 0).conjugate.should == Matrix.empty(3, 0) + end + + describe "for a subclass of Matrix" do + it "returns an instance of that subclass" do + MatrixSub.ins.conjugate.should.instance_of?(MatrixSub) + end + end end diff --git a/spec/ruby/library/matrix/det_spec.rb b/spec/ruby/library/matrix/det_spec.rb index aa7086cacf..fc4b1c252a 100644 --- a/spec/ruby/library/matrix/det_spec.rb +++ b/spec/ruby/library/matrix/det_spec.rb @@ -1,7 +1,8 @@ require_relative '../../spec_helper' -require_relative 'shared/determinant' require 'matrix' describe "Matrix#det" do - it_behaves_like :determinant, :det + it "is an alias of Matrix#determinant" do + Matrix.instance_method(:det).should == Matrix.instance_method(:determinant) + end end diff --git a/spec/ruby/library/matrix/determinant_spec.rb b/spec/ruby/library/matrix/determinant_spec.rb index 825c9907b1..603e13ba28 100644 --- a/spec/ruby/library/matrix/determinant_spec.rb +++ b/spec/ruby/library/matrix/determinant_spec.rb @@ -1,7 +1,39 @@ require_relative '../../spec_helper' -require_relative 'shared/determinant' require 'matrix' describe "Matrix#determinant" do - it_behaves_like :determinant, :determinant + it "returns the determinant of a square Matrix" do + m = Matrix[ [7,6], [3,9] ] + m.determinant.should == 45 + + m = Matrix[ [9, 8], [6,5] ] + m.determinant.should == -3 + + m = Matrix[ [9,8,3], [4,20,5], [1,1,1] ] + m.determinant.should == 95 + end + + it "returns the determinant of a single-element Matrix" do + m = Matrix[ [2] ] + m.determinant.should == 2 + end + + it "returns 1 for an empty Matrix" do + m = Matrix[ ] + m.determinant.should == 1 + end + + it "returns the determinant even for Matrices containing 0 as first entry" do + Matrix[[0,1],[1,0]].determinant.should == -1 + end + + it "raises an error for rectangular matrices" do + -> { + Matrix[[1], [2], [3]].determinant + }.should.raise(Matrix::ErrDimensionMismatch) + + -> { + Matrix.empty(3,0).determinant + }.should.raise(Matrix::ErrDimensionMismatch) + end end diff --git a/spec/ruby/library/matrix/identity_spec.rb b/spec/ruby/library/matrix/identity_spec.rb index 646462bc47..afefd27565 100644 --- a/spec/ruby/library/matrix/identity_spec.rb +++ b/spec/ruby/library/matrix/identity_spec.rb @@ -1,6 +1,20 @@ require_relative '../../spec_helper' -require_relative 'shared/identity' +require_relative 'fixtures/classes' +require 'matrix' describe "Matrix.identity" do - it_behaves_like :matrix_identity, :identity + it "returns a Matrix" do + Matrix.identity(2).should.is_a?(Matrix) + end + + it "returns a n x n identity matrix" do + Matrix.identity(3).should == Matrix.scalar(3, 1) + Matrix.identity(100).should == Matrix.scalar(100, 1) + end + + describe "for a subclass of Matrix" do + it "returns an instance of that subclass" do + MatrixSub.identity(2).should.instance_of?(MatrixSub) + end + end end diff --git a/spec/ruby/library/matrix/imag_spec.rb b/spec/ruby/library/matrix/imag_spec.rb index 1c988753d8..9d6cc2e953 100644 --- a/spec/ruby/library/matrix/imag_spec.rb +++ b/spec/ruby/library/matrix/imag_spec.rb @@ -1,6 +1,8 @@ require_relative '../../spec_helper' -require_relative 'shared/imaginary' +require 'matrix' describe "Matrix#imag" do - it_behaves_like :matrix_imaginary, :imag + it "is an alias of Matrix#imaginary" do + Matrix.instance_method(:imag).should == Matrix.instance_method(:imaginary) + end end diff --git a/spec/ruby/library/matrix/imaginary_spec.rb b/spec/ruby/library/matrix/imaginary_spec.rb index ceae4bbe8d..bbd06677b7 100644 --- a/spec/ruby/library/matrix/imaginary_spec.rb +++ b/spec/ruby/library/matrix/imaginary_spec.rb @@ -1,6 +1,21 @@ require_relative '../../spec_helper' -require_relative 'shared/imaginary' +require_relative 'fixtures/classes' +require 'matrix' describe "Matrix#imaginary" do - it_behaves_like :matrix_imaginary, :imaginary + it "returns a matrix with the imaginary part of the elements of the receiver" do + Matrix[ [1, 2], [3, 4] ].imaginary.should == Matrix[ [0, 0], [0, 0] ] + Matrix[ [1.9, Complex(1,1)], [Complex(-2,0.42), 4] ].imaginary.should == Matrix[ [0, 1], [0.42, 0] ] + end + + it "returns empty matrices on the same size if empty" do + Matrix.empty(0, 3).imaginary.should == Matrix.empty(0, 3) + Matrix.empty(3, 0).imaginary.should == Matrix.empty(3, 0) + end + + describe "for a subclass of Matrix" do + it "returns an instance of that subclass" do + MatrixSub.ins.imaginary.should.instance_of?(MatrixSub) + end + end end diff --git a/spec/ruby/library/matrix/inv_spec.rb b/spec/ruby/library/matrix/inv_spec.rb index 82879a6d82..02684030d2 100644 --- a/spec/ruby/library/matrix/inv_spec.rb +++ b/spec/ruby/library/matrix/inv_spec.rb @@ -1,7 +1,8 @@ require_relative '../../spec_helper' -require_relative 'spec_helper' -require_relative 'shared/inverse' +require 'matrix' describe "Matrix#inv" do - it_behaves_like :inverse, :inv + it "is an alias of Matrix#inverse" do + Matrix.instance_method(:inv).should == Matrix.instance_method(:inverse) + end end diff --git a/spec/ruby/library/matrix/inverse_spec.rb b/spec/ruby/library/matrix/inverse_spec.rb index fa3fa7de8a..38b01b28fb 100644 --- a/spec/ruby/library/matrix/inverse_spec.rb +++ b/spec/ruby/library/matrix/inverse_spec.rb @@ -1,7 +1,39 @@ require_relative '../../spec_helper' require_relative 'spec_helper' -require_relative 'shared/inverse' +require_relative 'fixtures/classes' +require 'matrix' describe "Matrix#inverse" do - it_behaves_like :inverse, :inverse + it "returns a Matrix" do + Matrix[ [1,2], [2,1] ].inverse.should.instance_of?(Matrix) + end + + it "returns the inverse of the Matrix" do + Matrix[ + [1, 3, 3], [1, 4, 3], [1, 3, 4] + ].inverse.should == + Matrix[ + [7, -3, -3], [-1, 1, 0], [-1, 0, 1] + ] + end + + it "returns the inverse of the Matrix (other case)" do + Matrix[ + [1, 2, 3], [0, 1, 4], [5, 6, 0] + ].inverse.should be_close_to_matrix([ + [-24, 18, 5], [20, -15, -4], [-5, 4, 1] + ]) + end + + it "raises a ErrDimensionMismatch if the Matrix is not square" do + ->{ + Matrix[ [1,2,3], [1,2,3] ].inverse + }.should.raise(Matrix::ErrDimensionMismatch) + end + + describe "for a subclass of Matrix" do + it "returns an instance of that subclass" do + MatrixSub.ins.inverse.should.instance_of?(MatrixSub) + end + end end diff --git a/spec/ruby/library/matrix/map_spec.rb b/spec/ruby/library/matrix/map_spec.rb index bc07c48cda..bae96db381 100644 --- a/spec/ruby/library/matrix/map_spec.rb +++ b/spec/ruby/library/matrix/map_spec.rb @@ -1,6 +1,26 @@ require_relative '../../spec_helper' -require_relative 'shared/collect' +require_relative 'fixtures/classes' describe "Matrix#map" do - it_behaves_like :collect, :map + before :all do + @m = Matrix[ [1, 2], [1, 2] ] + end + + it "returns an instance of Matrix" do + @m.map{|n| n * 2 }.should.is_a?(Matrix) + end + + it "returns a Matrix where each element is the result of the block" do + @m.map { |n| n * 2 }.should == Matrix[ [2, 4], [2, 4] ] + end + + it "returns an enumerator if no block is given" do + @m.map.should.instance_of?(Enumerator) + end + + describe "for a subclass of Matrix" do + it "returns an instance of that subclass" do + MatrixSub.ins.map{1}.should.instance_of?(MatrixSub) + end + end end diff --git a/spec/ruby/library/matrix/rect_spec.rb b/spec/ruby/library/matrix/rect_spec.rb index 83a0404e47..b0ca3f0421 100644 --- a/spec/ruby/library/matrix/rect_spec.rb +++ b/spec/ruby/library/matrix/rect_spec.rb @@ -1,6 +1,8 @@ require_relative '../../spec_helper' -require_relative 'shared/rectangular' +require 'matrix' describe "Matrix#rect" do - it_behaves_like :matrix_rectangular, :rect + it "is an alias of Matrix#rectangular" do + Matrix.instance_method(:rect).should == Matrix.instance_method(:rectangular) + end end diff --git a/spec/ruby/library/matrix/rectangular_spec.rb b/spec/ruby/library/matrix/rectangular_spec.rb index a235fac640..c0732f96bc 100644 --- a/spec/ruby/library/matrix/rectangular_spec.rb +++ b/spec/ruby/library/matrix/rectangular_spec.rb @@ -1,6 +1,19 @@ require_relative '../../spec_helper' -require_relative 'shared/rectangular' +require_relative 'fixtures/classes' +require 'matrix' describe "Matrix#rectangular" do - it_behaves_like :matrix_rectangular, :rectangular + it "returns [receiver.real, receiver.imag]" do + m = Matrix[ [1.2, Complex(1,2)], [Complex(-2,0.42), 4] ] + m.rectangular.should == [m.real, m.imag] + + m = Matrix.empty(3, 0) + m.rectangular.should == [m.real, m.imag] + end + + describe "for a subclass of Matrix" do + it "returns instances of that subclass" do + MatrixSub.ins.rectangular.each{|m| m.should.instance_of?(MatrixSub) } + end + end end diff --git a/spec/ruby/library/matrix/shared/collect.rb b/spec/ruby/library/matrix/shared/collect.rb deleted file mode 100644 index 3a4dbe3a36..0000000000 --- a/spec/ruby/library/matrix/shared/collect.rb +++ /dev/null @@ -1,26 +0,0 @@ -require_relative '../fixtures/classes' -require 'matrix' - -describe :collect, shared: true do - before :all do - @m = Matrix[ [1, 2], [1, 2] ] - end - - it "returns an instance of Matrix" do - @m.send(@method){|n| n * 2 }.should.is_a?(Matrix) - end - - it "returns a Matrix where each element is the result of the block" do - @m.send(@method) { |n| n * 2 }.should == Matrix[ [2, 4], [2, 4] ] - end - - it "returns an enumerator if no block is given" do - @m.send(@method).should.instance_of?(Enumerator) - end - - describe "for a subclass of Matrix" do - it "returns an instance of that subclass" do - MatrixSub.ins.send(@method){1}.should.instance_of?(MatrixSub) - end - end -end diff --git a/spec/ruby/library/matrix/shared/conjugate.rb b/spec/ruby/library/matrix/shared/conjugate.rb deleted file mode 100644 index ffdf5ebca1..0000000000 --- a/spec/ruby/library/matrix/shared/conjugate.rb +++ /dev/null @@ -1,20 +0,0 @@ -require_relative '../fixtures/classes' -require 'matrix' - -describe :matrix_conjugate, shared: true do - it "returns a matrix with all entries 'conjugated'" do - Matrix[ [1, 2], [3, 4] ].send(@method).should == Matrix[ [1, 2], [3, 4] ] - Matrix[ [1.9, Complex(1,1)], [3, 4] ].send(@method).should == Matrix[ [1.9, Complex(1,-1)], [3, 4] ] - end - - it "returns empty matrices on the same size if empty" do - Matrix.empty(0, 3).send(@method).should == Matrix.empty(0, 3) - Matrix.empty(3, 0).send(@method).should == Matrix.empty(3, 0) - end - - describe "for a subclass of Matrix" do - it "returns an instance of that subclass" do - MatrixSub.ins.send(@method).should.instance_of?(MatrixSub) - end - end -end diff --git a/spec/ruby/library/matrix/shared/determinant.rb b/spec/ruby/library/matrix/shared/determinant.rb deleted file mode 100644 index b7c86393ba..0000000000 --- a/spec/ruby/library/matrix/shared/determinant.rb +++ /dev/null @@ -1,38 +0,0 @@ -require 'matrix' - -describe :determinant, shared: true do - it "returns the determinant of a square Matrix" do - m = Matrix[ [7,6], [3,9] ] - m.send(@method).should == 45 - - m = Matrix[ [9, 8], [6,5] ] - m.send(@method).should == -3 - - m = Matrix[ [9,8,3], [4,20,5], [1,1,1] ] - m.send(@method).should == 95 - end - - it "returns the determinant of a single-element Matrix" do - m = Matrix[ [2] ] - m.send(@method).should == 2 - end - - it "returns 1 for an empty Matrix" do - m = Matrix[ ] - m.send(@method).should == 1 - end - - it "returns the determinant even for Matrices containing 0 as first entry" do - Matrix[[0,1],[1,0]].send(@method).should == -1 - end - - it "raises an error for rectangular matrices" do - -> { - Matrix[[1], [2], [3]].send(@method) - }.should.raise(Matrix::ErrDimensionMismatch) - - -> { - Matrix.empty(3,0).send(@method) - }.should.raise(Matrix::ErrDimensionMismatch) - end -end diff --git a/spec/ruby/library/matrix/shared/identity.rb b/spec/ruby/library/matrix/shared/identity.rb deleted file mode 100644 index df957b5a75..0000000000 --- a/spec/ruby/library/matrix/shared/identity.rb +++ /dev/null @@ -1,19 +0,0 @@ -require_relative '../fixtures/classes' -require 'matrix' - -describe :matrix_identity, shared: true do - it "returns a Matrix" do - Matrix.send(@method, 2).should.is_a?(Matrix) - end - - it "returns a n x n identity matrix" do - Matrix.send(@method, 3).should == Matrix.scalar(3, 1) - Matrix.send(@method, 100).should == Matrix.scalar(100, 1) - end - - describe "for a subclass of Matrix" do - it "returns an instance of that subclass" do - MatrixSub.send(@method, 2).should.instance_of?(MatrixSub) - end - end -end diff --git a/spec/ruby/library/matrix/shared/imaginary.rb b/spec/ruby/library/matrix/shared/imaginary.rb deleted file mode 100644 index 16615213a2..0000000000 --- a/spec/ruby/library/matrix/shared/imaginary.rb +++ /dev/null @@ -1,20 +0,0 @@ -require_relative '../fixtures/classes' -require 'matrix' - -describe :matrix_imaginary, shared: true do - it "returns a matrix with the imaginary part of the elements of the receiver" do - Matrix[ [1, 2], [3, 4] ].send(@method).should == Matrix[ [0, 0], [0, 0] ] - Matrix[ [1.9, Complex(1,1)], [Complex(-2,0.42), 4] ].send(@method).should == Matrix[ [0, 1], [0.42, 0] ] - end - - it "returns empty matrices on the same size if empty" do - Matrix.empty(0, 3).send(@method).should == Matrix.empty(0, 3) - Matrix.empty(3, 0).send(@method).should == Matrix.empty(3, 0) - end - - describe "for a subclass of Matrix" do - it "returns an instance of that subclass" do - MatrixSub.ins.send(@method).should.instance_of?(MatrixSub) - end - end -end diff --git a/spec/ruby/library/matrix/shared/inverse.rb b/spec/ruby/library/matrix/shared/inverse.rb deleted file mode 100644 index ac463cf680..0000000000 --- a/spec/ruby/library/matrix/shared/inverse.rb +++ /dev/null @@ -1,38 +0,0 @@ -require_relative '../fixtures/classes' -require 'matrix' - -describe :inverse, shared: true do - - it "returns a Matrix" do - Matrix[ [1,2], [2,1] ].send(@method).should.instance_of?(Matrix) - end - - it "returns the inverse of the Matrix" do - Matrix[ - [1, 3, 3], [1, 4, 3], [1, 3, 4] - ].send(@method).should == - Matrix[ - [7, -3, -3], [-1, 1, 0], [-1, 0, 1] - ] - end - - it "returns the inverse of the Matrix (other case)" do - Matrix[ - [1, 2, 3], [0, 1, 4], [5, 6, 0] - ].send(@method).should be_close_to_matrix([ - [-24, 18, 5], [20, -15, -4], [-5, 4, 1] - ]) - end - - it "raises a ErrDimensionMismatch if the Matrix is not square" do - ->{ - Matrix[ [1,2,3], [1,2,3] ].send(@method) - }.should.raise(Matrix::ErrDimensionMismatch) - end - - describe "for a subclass of Matrix" do - it "returns an instance of that subclass" do - MatrixSub.ins.send(@method).should.instance_of?(MatrixSub) - end - end -end diff --git a/spec/ruby/library/matrix/shared/rectangular.rb b/spec/ruby/library/matrix/shared/rectangular.rb deleted file mode 100644 index 0229e614c6..0000000000 --- a/spec/ruby/library/matrix/shared/rectangular.rb +++ /dev/null @@ -1,18 +0,0 @@ -require_relative '../fixtures/classes' -require 'matrix' - -describe :matrix_rectangular, shared: true do - it "returns [receiver.real, receiver.imag]" do - m = Matrix[ [1.2, Complex(1,2)], [Complex(-2,0.42), 4] ] - m.send(@method).should == [m.real, m.imag] - - m = Matrix.empty(3, 0) - m.send(@method).should == [m.real, m.imag] - end - - describe "for a subclass of Matrix" do - it "returns instances of that subclass" do - MatrixSub.ins.send(@method).each{|m| m.should.instance_of?(MatrixSub) } - end - end -end diff --git a/spec/ruby/library/matrix/shared/trace.rb b/spec/ruby/library/matrix/shared/trace.rb deleted file mode 100644 index c4a5491b22..0000000000 --- a/spec/ruby/library/matrix/shared/trace.rb +++ /dev/null @@ -1,12 +0,0 @@ -require 'matrix' - -describe :trace, shared: true do - it "returns the sum of diagonal elements in a square Matrix" do - Matrix[[7,6], [3,9]].trace.should == 16 - end - - it "returns the sum of diagonal elements in a rectangular Matrix" do - ->{ Matrix[[1,2,3], [4,5,6]].trace}.should.raise(Matrix::ErrDimensionMismatch) - end - -end diff --git a/spec/ruby/library/matrix/shared/transpose.rb b/spec/ruby/library/matrix/shared/transpose.rb deleted file mode 100644 index a0b495359b..0000000000 --- a/spec/ruby/library/matrix/shared/transpose.rb +++ /dev/null @@ -1,19 +0,0 @@ -require_relative '../fixtures/classes' -require 'matrix' - -describe :matrix_transpose, shared: true do - it "returns a transposed matrix" do - Matrix[[1, 2], [3, 4], [5, 6]].send(@method).should == Matrix[[1, 3, 5], [2, 4, 6]] - end - - it "can transpose empty matrices" do - m = Matrix[[], [], []] - m.send(@method).send(@method).should == m - end - - describe "for a subclass of Matrix" do - it "returns an instance of that subclass" do - MatrixSub.ins.send(@method).should.instance_of?(MatrixSub) - end - end -end diff --git a/spec/ruby/library/matrix/t_spec.rb b/spec/ruby/library/matrix/t_spec.rb index 6f1a5178e0..9411597e7c 100644 --- a/spec/ruby/library/matrix/t_spec.rb +++ b/spec/ruby/library/matrix/t_spec.rb @@ -1,6 +1,8 @@ require_relative '../../spec_helper' -require_relative 'shared/transpose' +require 'matrix' -describe "Matrix#transpose" do - it_behaves_like :matrix_transpose, :t +describe "Matrix#t" do + it "is an alias of Matrix#transpose" do + Matrix.instance_method(:t).should == Matrix.instance_method(:transpose) + end end diff --git a/spec/ruby/library/matrix/tr_spec.rb b/spec/ruby/library/matrix/tr_spec.rb index e17bd790d7..04d237d483 100644 --- a/spec/ruby/library/matrix/tr_spec.rb +++ b/spec/ruby/library/matrix/tr_spec.rb @@ -1,7 +1,8 @@ require_relative '../../spec_helper' -require_relative 'shared/trace' require 'matrix' describe "Matrix#tr" do - it_behaves_like :trace, :tr + it "is an alias of Matrix#trace" do + Matrix.instance_method(:tr).should == Matrix.instance_method(:trace) + end end diff --git a/spec/ruby/library/matrix/trace_spec.rb b/spec/ruby/library/matrix/trace_spec.rb index 290e7cb1f7..831278c838 100644 --- a/spec/ruby/library/matrix/trace_spec.rb +++ b/spec/ruby/library/matrix/trace_spec.rb @@ -1,7 +1,12 @@ require_relative '../../spec_helper' -require_relative 'shared/trace' require 'matrix' describe "Matrix#trace" do - it_behaves_like :trace, :trace + it "returns the sum of diagonal elements in a square Matrix" do + Matrix[[7,6], [3,9]].trace.should == 16 + end + + it "returns the sum of diagonal elements in a rectangular Matrix" do + ->{ Matrix[[1,2,3], [4,5,6]].trace}.should.raise(Matrix::ErrDimensionMismatch) + end end diff --git a/spec/ruby/library/matrix/transpose_spec.rb b/spec/ruby/library/matrix/transpose_spec.rb index 79600dd439..0b24ab32a7 100644 --- a/spec/ruby/library/matrix/transpose_spec.rb +++ b/spec/ruby/library/matrix/transpose_spec.rb @@ -1,6 +1,19 @@ require_relative '../../spec_helper' -require_relative 'shared/transpose' +require_relative 'fixtures/classes' describe "Matrix#transpose" do - it_behaves_like :matrix_transpose, :transpose + it "returns a transposed matrix" do + Matrix[[1, 2], [3, 4], [5, 6]].transpose.should == Matrix[[1, 3, 5], [2, 4, 6]] + end + + it "can transpose empty matrices" do + m = Matrix[[], [], []] + m.transpose.transpose.should == m + end + + describe "for a subclass of Matrix" do + it "returns an instance of that subclass" do + MatrixSub.ins.transpose.should.instance_of?(MatrixSub) + end + end end diff --git a/spec/ruby/library/matrix/unit_spec.rb b/spec/ruby/library/matrix/unit_spec.rb index 6a41d729c7..1121996122 100644 --- a/spec/ruby/library/matrix/unit_spec.rb +++ b/spec/ruby/library/matrix/unit_spec.rb @@ -1,6 +1,8 @@ require_relative '../../spec_helper' -require_relative 'shared/identity' +require 'matrix' describe "Matrix.unit" do - it_behaves_like :matrix_identity, :unit + it "is an alias of Matrix.identity" do + Matrix.method(:unit).should == Matrix.method(:identity) + end end |
