diff options
Diffstat (limited to 'spec/ruby/library/matrix/shared')
| -rw-r--r-- | spec/ruby/library/matrix/shared/collect.rb | 26 | ||||
| -rw-r--r-- | spec/ruby/library/matrix/shared/conjugate.rb | 20 | ||||
| -rw-r--r-- | spec/ruby/library/matrix/shared/determinant.rb | 38 | ||||
| -rw-r--r-- | spec/ruby/library/matrix/shared/equal_value.rb | 20 | ||||
| -rw-r--r-- | spec/ruby/library/matrix/shared/identity.rb | 19 | ||||
| -rw-r--r-- | spec/ruby/library/matrix/shared/imaginary.rb | 20 | ||||
| -rw-r--r-- | spec/ruby/library/matrix/shared/inverse.rb | 38 | ||||
| -rw-r--r-- | spec/ruby/library/matrix/shared/rectangular.rb | 18 | ||||
| -rw-r--r-- | spec/ruby/library/matrix/shared/trace.rb | 12 | ||||
| -rw-r--r-- | spec/ruby/library/matrix/shared/transpose.rb | 19 |
10 files changed, 10 insertions, 220 deletions
diff --git a/spec/ruby/library/matrix/shared/collect.rb b/spec/ruby/library/matrix/shared/collect.rb deleted file mode 100644 index 852f7fd6cf..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 be_kind_of(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 be_an_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 be_an_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 d87658f855..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 be_an_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 47a58c62a6..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 - lambda { - Matrix[[1], [2], [3]].send(@method) - }.should raise_error(Matrix::ErrDimensionMismatch) - - lambda { - Matrix.empty(3,0).send(@method) - }.should raise_error(Matrix::ErrDimensionMismatch) - end -end diff --git a/spec/ruby/library/matrix/shared/equal_value.rb b/spec/ruby/library/matrix/shared/equal_value.rb index 2b2311d49e..9bc6ed908b 100644 --- a/spec/ruby/library/matrix/shared/equal_value.rb +++ b/spec/ruby/library/matrix/shared/equal_value.rb @@ -7,27 +7,27 @@ describe :equal, shared: true do end it "returns true for self" do - @matrix.send(@method, @matrix).should be_true + @matrix.send(@method, @matrix).should == true end it "returns true for equal matrices" do - @matrix.send(@method, Matrix[ [1, 2, 3, 4, 5], [2, 3, 4, 5, 6] ]).should be_true + @matrix.send(@method, Matrix[ [1, 2, 3, 4, 5], [2, 3, 4, 5, 6] ]).should == true end it "returns false for different matrices" do - @matrix.send(@method, Matrix[ [42, 2, 3, 4, 5], [2, 3, 4, 5, 6] ]).should be_false - @matrix.send(@method, Matrix[ [1, 2, 3, 4, 5, 6], [2, 3, 4, 5, 6, 7] ]).should be_false - @matrix.send(@method, Matrix[ [1, 2, 3], [2, 3, 4] ]).should be_false + @matrix.send(@method, Matrix[ [42, 2, 3, 4, 5], [2, 3, 4, 5, 6] ]).should == false + @matrix.send(@method, Matrix[ [1, 2, 3, 4, 5, 6], [2, 3, 4, 5, 6, 7] ]).should == false + @matrix.send(@method, Matrix[ [1, 2, 3], [2, 3, 4] ]).should == false end it "returns false for different empty matrices" do - Matrix.empty(42, 0).send(@method, Matrix.empty(6, 0)).should be_false - Matrix.empty(0, 42).send(@method, Matrix.empty(0, 6)).should be_false - Matrix.empty(0, 0).send(@method, Matrix.empty(6, 0)).should be_false - Matrix.empty(0, 0).send(@method, Matrix.empty(0, 6)).should be_false + Matrix.empty(42, 0).send(@method, Matrix.empty(6, 0)).should == false + Matrix.empty(0, 42).send(@method, Matrix.empty(0, 6)).should == false + Matrix.empty(0, 0).send(@method, Matrix.empty(6, 0)).should == false + Matrix.empty(0, 0).send(@method, Matrix.empty(0, 6)).should == false end it "doesn't distinguish on subclasses" do - MatrixSub.ins.send(@method, Matrix.I(2)).should be_true + MatrixSub.ins.send(@method, Matrix.I(2)).should == true 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 114f86e7b0..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 be_kind_of(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 be_an_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 d28ecc69f1..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 be_an_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 e1e5ae5758..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 be_an_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 - lambda{ - Matrix[ [1,2,3], [1,2,3] ].send(@method) - }.should raise_error(Matrix::ErrDimensionMismatch) - end - - describe "for a subclass of Matrix" do - it "returns an instance of that subclass" do - MatrixSub.ins.send(@method).should be_an_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 3d9a0dfe8a..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 be_an_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 2a42839f5d..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 - lambda{ Matrix[[1,2,3], [4,5,6]].trace}.should raise_error(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 89b1d025be..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 be_an_instance_of(MatrixSub) - end - end -end |
