Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
164 changed files
with
3,899 additions
and
4,386 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
require_relative '../../spec_helper' | ||
require_relative 'shared/identity' | ||
|
||
ruby_version_is ""..."3.1" do | ||
require_relative 'shared/identity' | ||
|
||
describe "Matrix.I" do | ||
it_behaves_like :matrix_identity, :I | ||
end | ||
describe "Matrix.I" do | ||
it_behaves_like :matrix_identity, :I | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,36 @@ | ||
require_relative '../../spec_helper' | ||
|
||
ruby_version_is ""..."3.1" do | ||
require 'matrix' | ||
require 'matrix' | ||
|
||
describe "Matrix#antisymmetric?" do | ||
it "returns true for an antisymmetric Matrix" do | ||
Matrix[[0, -2, Complex(1, 3)], [2, 0, 5], [-Complex(1, 3), -5, 0]].antisymmetric?.should be_true | ||
end | ||
describe "Matrix#antisymmetric?" do | ||
it "returns true for an antisymmetric Matrix" do | ||
Matrix[[0, -2, Complex(1, 3)], [2, 0, 5], [-Complex(1, 3), -5, 0]].antisymmetric?.should be_true | ||
end | ||
|
||
it "returns true for a 0x0 empty matrix" do | ||
Matrix.empty.antisymmetric?.should be_true | ||
end | ||
it "returns true for a 0x0 empty matrix" do | ||
Matrix.empty.antisymmetric?.should be_true | ||
end | ||
|
||
it "returns false for non-antisymmetric matrices" do | ||
[ | ||
Matrix[[1, 2, 3], [4, 5, 6], [7, 8, 9]], | ||
Matrix[[1, -2, 3], [2, 0, 6], [-3, -6, 0]], # wrong diagonal element | ||
Matrix[[0, 2, -3], [2, 0, 6], [-3, 6, 0]] # only signs wrong | ||
].each do |matrix| | ||
matrix.antisymmetric?.should be_false | ||
end | ||
it "returns false for non-antisymmetric matrices" do | ||
[ | ||
Matrix[[1, 2, 3], [4, 5, 6], [7, 8, 9]], | ||
Matrix[[1, -2, 3], [2, 0, 6], [-3, -6, 0]], # wrong diagonal element | ||
Matrix[[0, 2, -3], [2, 0, 6], [-3, 6, 0]] # only signs wrong | ||
].each do |matrix| | ||
matrix.antisymmetric?.should be_false | ||
end | ||
end | ||
|
||
it "raises an error for rectangular matrices" do | ||
[ | ||
Matrix[[0], [0]], | ||
Matrix[[0, 0]], | ||
Matrix.empty(0, 2), | ||
Matrix.empty(2, 0), | ||
].each do |rectangular_matrix| | ||
-> { | ||
rectangular_matrix.antisymmetric? | ||
}.should raise_error(Matrix::ErrDimensionMismatch) | ||
end | ||
it "raises an error for rectangular matrices" do | ||
[ | ||
Matrix[[0], [0]], | ||
Matrix[[0, 0]], | ||
Matrix.empty(0, 2), | ||
Matrix.empty(2, 0), | ||
].each do |rectangular_matrix| | ||
-> { | ||
rectangular_matrix.antisymmetric? | ||
}.should raise_error(Matrix::ErrDimensionMismatch) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,73 @@ | ||
require_relative '../../spec_helper' | ||
require_relative 'fixtures/classes' | ||
require 'matrix' | ||
|
||
ruby_version_is ""..."3.1" do | ||
require_relative 'fixtures/classes' | ||
require 'matrix' | ||
describe "Matrix.build" do | ||
|
||
describe "Matrix.build" do | ||
|
||
it "returns a Matrix object of the given size" do | ||
m = Matrix.build(3, 4){1} | ||
m.should be_an_instance_of(Matrix) | ||
m.row_size.should == 3 | ||
m.column_size.should == 4 | ||
end | ||
it "returns a Matrix object of the given size" do | ||
m = Matrix.build(3, 4){1} | ||
m.should be_an_instance_of(Matrix) | ||
m.row_size.should == 3 | ||
m.column_size.should == 4 | ||
end | ||
|
||
it "builds the Matrix using the given block" do | ||
Matrix.build(2, 3){|col, row| 10*col - row}.should == | ||
Matrix[[0, -1, -2], [10, 9, 8]] | ||
end | ||
it "builds the Matrix using the given block" do | ||
Matrix.build(2, 3){|col, row| 10*col - row}.should == | ||
Matrix[[0, -1, -2], [10, 9, 8]] | ||
end | ||
|
||
it "iterates through the first row, then the second, ..." do | ||
acc = [] | ||
Matrix.build(2, 3){|*args| acc << args} | ||
acc.should == [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2]] | ||
end | ||
it "iterates through the first row, then the second, ..." do | ||
acc = [] | ||
Matrix.build(2, 3){|*args| acc << args} | ||
acc.should == [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2]] | ||
end | ||
|
||
it "returns an Enumerator is no block is given" do | ||
enum = Matrix.build(2, 1) | ||
enum.should be_an_instance_of(Enumerator) | ||
enum.each{1}.should == Matrix[[1], [1]] | ||
end | ||
it "returns an Enumerator is no block is given" do | ||
enum = Matrix.build(2, 1) | ||
enum.should be_an_instance_of(Enumerator) | ||
enum.each{1}.should == Matrix[[1], [1]] | ||
end | ||
|
||
it "requires integers as parameters" do | ||
-> { Matrix.build("1", "2"){1} }.should raise_error(TypeError) | ||
-> { Matrix.build(nil, nil){1} }.should raise_error(TypeError) | ||
-> { Matrix.build(1..2){1} }.should raise_error(TypeError) | ||
end | ||
it "requires integers as parameters" do | ||
-> { Matrix.build("1", "2"){1} }.should raise_error(TypeError) | ||
-> { Matrix.build(nil, nil){1} }.should raise_error(TypeError) | ||
-> { Matrix.build(1..2){1} }.should raise_error(TypeError) | ||
end | ||
|
||
it "requires non-negative integers" do | ||
-> { Matrix.build(-1, 1){1} }.should raise_error(ArgumentError) | ||
-> { Matrix.build(+1,-1){1} }.should raise_error(ArgumentError) | ||
end | ||
it "requires non-negative integers" do | ||
-> { Matrix.build(-1, 1){1} }.should raise_error(ArgumentError) | ||
-> { Matrix.build(+1,-1){1} }.should raise_error(ArgumentError) | ||
end | ||
|
||
it "returns empty Matrix if one argument is zero" do | ||
m = Matrix.build(0, 3){ | ||
raise "Should not yield" | ||
} | ||
m.should be_empty | ||
m.column_size.should == 3 | ||
it "returns empty Matrix if one argument is zero" do | ||
m = Matrix.build(0, 3){ | ||
raise "Should not yield" | ||
} | ||
m.should be_empty | ||
m.column_size.should == 3 | ||
|
||
m = Matrix.build(3, 0){ | ||
raise "Should not yield" | ||
} | ||
m.should be_empty | ||
m.row_size.should == 3 | ||
end | ||
m = Matrix.build(3, 0){ | ||
raise "Should not yield" | ||
} | ||
m.should be_empty | ||
m.row_size.should == 3 | ||
end | ||
|
||
it "tries to calls :to_int on arguments" do | ||
int = mock('int') | ||
int.should_receive(:to_int).twice.and_return(2) | ||
Matrix.build(int, int){ 1 }.should == Matrix[ [1,1], [1,1] ] | ||
end | ||
it "tries to calls :to_int on arguments" do | ||
int = mock('int') | ||
int.should_receive(:to_int).twice.and_return(2) | ||
Matrix.build(int, int){ 1 }.should == Matrix[ [1,1], [1,1] ] | ||
end | ||
|
||
it "builds an nxn Matrix when given only one argument" do | ||
m = Matrix.build(3){1} | ||
m.row_size.should == 3 | ||
m.column_size.should == 3 | ||
end | ||
it "builds an nxn Matrix when given only one argument" do | ||
m = Matrix.build(3){1} | ||
m.row_size.should == 3 | ||
m.column_size.should == 3 | ||
end | ||
end | ||
|
||
describe "for a subclass of Matrix" do | ||
it "returns an instance of that subclass" do | ||
MatrixSub.build(3){1}.should be_an_instance_of(MatrixSub) | ||
end | ||
describe "for a subclass of Matrix" do | ||
it "returns an instance of that subclass" do | ||
MatrixSub.build(3){1}.should be_an_instance_of(MatrixSub) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,25 @@ | ||
require_relative '../../spec_helper' | ||
require_relative 'fixtures/classes' | ||
require 'matrix' | ||
|
||
ruby_version_is ""..."3.1" do | ||
require_relative 'fixtures/classes' | ||
require 'matrix' | ||
|
||
describe "Matrix#clone" do | ||
before :each do | ||
@a = Matrix[[1, 2], [3, 4], [5, 6]] | ||
end | ||
describe "Matrix#clone" do | ||
before :each do | ||
@a = Matrix[[1, 2], [3, 4], [5, 6]] | ||
end | ||
|
||
it "returns a shallow copy of the matrix" do | ||
b = @a.clone | ||
@a.should_not equal(b) | ||
b.should be_kind_of(Matrix) | ||
b.should == @a | ||
0.upto(@a.row_size - 1) do |i| | ||
@a.row(i).should_not equal(b.row(i)) | ||
end | ||
it "returns a shallow copy of the matrix" do | ||
b = @a.clone | ||
@a.should_not equal(b) | ||
b.should be_kind_of(Matrix) | ||
b.should == @a | ||
0.upto(@a.row_size - 1) do |i| | ||
@a.row(i).should_not equal(b.row(i)) | ||
end | ||
end | ||
|
||
describe "for a subclass of Matrix" do | ||
it "returns an instance of that subclass" do | ||
MatrixSub.ins.clone.should be_an_instance_of(MatrixSub) | ||
end | ||
describe "for a subclass of Matrix" do | ||
it "returns an instance of that subclass" do | ||
MatrixSub.ins.clone.should be_an_instance_of(MatrixSub) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,8 @@ | ||
require_relative '../../spec_helper' | ||
require 'matrix' | ||
|
||
ruby_version_is ""..."3.1" do | ||
require 'matrix' | ||
|
||
describe "Matrix#coerce" do | ||
it "allows the division of integer by a Matrix " do | ||
(1/Matrix[[0,1],[-1,0]]).should == Matrix[[0,-1],[1,0]] | ||
end | ||
describe "Matrix#coerce" do | ||
it "allows the division of integer by a Matrix " do | ||
(1/Matrix[[0,1],[-1,0]]).should == Matrix[[0,-1],[1,0]] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
require_relative '../../spec_helper' | ||
require_relative 'shared/collect' | ||
|
||
ruby_version_is ""..."3.1" do | ||
require_relative 'shared/collect' | ||
|
||
describe "Matrix#collect" do | ||
it_behaves_like :collect, :collect | ||
end | ||
describe "Matrix#collect" do | ||
it_behaves_like :collect, :collect | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,13 @@ | ||
require_relative '../../spec_helper' | ||
require 'matrix' | ||
|
||
ruby_version_is ""..."3.1" do | ||
require 'matrix' | ||
|
||
describe "Matrix#column_size" do | ||
it "returns the number of columns" do | ||
Matrix[ [1,2], [3,4] ].column_size.should == 2 | ||
end | ||
describe "Matrix#column_size" do | ||
it "returns the number of columns" do | ||
Matrix[ [1,2], [3,4] ].column_size.should == 2 | ||
end | ||
|
||
it "returns 0 for empty matrices" do | ||
Matrix[ [], [] ].column_size.should == 0 | ||
Matrix[ ].column_size.should == 0 | ||
end | ||
it "returns 0 for empty matrices" do | ||
Matrix[ [], [] ].column_size.should == 0 | ||
Matrix[ ].column_size.should == 0 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,35 @@ | ||
require_relative '../../spec_helper' | ||
require 'matrix' | ||
|
||
ruby_version_is ""..."3.1" do | ||
require 'matrix' | ||
|
||
describe "Matrix#column" do | ||
before :all do | ||
@m = Matrix[[1,2,3], [2,3,4]] | ||
end | ||
describe "Matrix#column" do | ||
before :all do | ||
@m = Matrix[[1,2,3], [2,3,4]] | ||
end | ||
|
||
it "returns a Vector when called without a block" do | ||
@m.column(1).should == Vector[2,3] | ||
end | ||
it "returns a Vector when called without a block" do | ||
@m.column(1).should == Vector[2,3] | ||
end | ||
|
||
it "yields each element in the column to the block" do | ||
a = [] | ||
@m.column(1) {|n| a << n } | ||
a.should == [2,3] | ||
end | ||
it "yields each element in the column to the block" do | ||
a = [] | ||
@m.column(1) {|n| a << n } | ||
a.should == [2,3] | ||
end | ||
|
||
it "counts backwards for negative argument" do | ||
@m.column(-1).should == Vector[3, 4] | ||
end | ||
it "counts backwards for negative argument" do | ||
@m.column(-1).should == Vector[3, 4] | ||
end | ||
|
||
it "returns self when called with a block" do | ||
@m.column(0) { |x| x }.should equal(@m) | ||
end | ||
it "returns self when called with a block" do | ||
@m.column(0) { |x| x }.should equal(@m) | ||
end | ||
|
||
it "returns nil when out of bounds" do | ||
@m.column(3).should == nil | ||
end | ||
it "returns nil when out of bounds" do | ||
@m.column(3).should == nil | ||
end | ||
|
||
it "never yields when out of bounds" do | ||
-> { @m.column(3){ raise } }.should_not raise_error | ||
-> { @m.column(-4){ raise } }.should_not raise_error | ||
end | ||
it "never yields when out of bounds" do | ||
-> { @m.column(3){ raise } }.should_not raise_error | ||
-> { @m.column(-4){ raise } }.should_not raise_error | ||
end | ||
end |
Oops, something went wrong.