summaryrefslogtreecommitdiff
path: root/spec/ruby/library/matrix/determinant_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/library/matrix/determinant_spec.rb')
-rw-r--r--spec/ruby/library/matrix/determinant_spec.rb36
1 files changed, 34 insertions, 2 deletions
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