1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
This commit is contained in:
Benoit Daloze 2019-07-27 12:40:09 +02:00
parent a06301b103
commit 5c276e1cc9
1247 changed files with 5316 additions and 5028 deletions

View file

@ -28,7 +28,7 @@ ruby_version_is "2.6" do
Matrix.empty(0, 2),
Matrix.empty(2, 0),
].each do |rectangular_matrix|
lambda {
-> {
rectangular_matrix.antisymmetric?
}.should raise_error(Matrix::ErrDimensionMismatch)
end

View file

@ -29,14 +29,14 @@ describe "Matrix.build" do
end
it "requires integers as parameters" do
lambda { Matrix.build("1", "2"){1} }.should raise_error(TypeError)
lambda { Matrix.build(nil, nil){1} }.should raise_error(TypeError)
lambda { Matrix.build(1..2){1} }.should raise_error(TypeError)
-> { 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
lambda { Matrix.build(-1, 1){1} }.should raise_error(ArgumentError)
lambda { Matrix.build(+1,-1){1} }.should raise_error(ArgumentError)
-> { 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

View file

@ -29,7 +29,7 @@ describe "Matrix#column" do
end
it "never yields when out of bounds" do
lambda { @m.column(3){ raise } }.should_not raise_error
lambda { @m.column(-4){ raise } }.should_not raise_error
-> { @m.column(3){ raise } }.should_not raise_error
-> { @m.column(-4){ raise } }.should_not raise_error
end
end

View file

@ -5,10 +5,10 @@ require 'matrix'
describe "Matrix.[]" do
it "requires arrays as parameters" do
lambda { Matrix[5] }.should raise_error(TypeError)
lambda { Matrix[nil] }.should raise_error(TypeError)
lambda { Matrix[1..2] }.should raise_error(TypeError)
lambda { Matrix[[1, 2], 3] }.should raise_error(TypeError)
-> { Matrix[5] }.should raise_error(TypeError)
-> { Matrix[nil] }.should raise_error(TypeError)
-> { Matrix[1..2] }.should raise_error(TypeError)
-> { Matrix[[1, 2], 3] }.should raise_error(TypeError)
end
it "creates an empty Matrix with no arguments" do
@ -18,9 +18,9 @@ describe "Matrix.[]" do
end
it "raises for non-rectangular matrices" do
lambda{ Matrix[ [0], [0,1] ] }.should \
->{ Matrix[ [0], [0,1] ] }.should \
raise_error(Matrix::ErrDimensionMismatch)
lambda{ Matrix[ [0,1], [0,1,2], [0,1] ]}.should \
->{ Matrix[ [0,1], [0,1,2], [0,1] ]}.should \
raise_error(Matrix::ErrDimensionMismatch)
end

View file

@ -64,7 +64,7 @@ describe "Matrix.diagonal?" do
Matrix.empty(0, 2),
Matrix.empty(2, 0),
].each do |rectangular_matrix|
lambda {
-> {
rectangular_matrix.diagonal?
}.should raise_error(Matrix::ErrDimensionMismatch)
end

View file

@ -30,7 +30,7 @@ describe "Matrix#/" do
end
it "raises a Matrix::ErrDimensionMismatch if the matrices are different sizes" do
lambda { @a / Matrix[ [1] ] }.should raise_error(Matrix::ErrDimensionMismatch)
-> { @a / Matrix[ [1] ] }.should raise_error(Matrix::ErrDimensionMismatch)
end
it "returns an instance of Matrix" do
@ -46,9 +46,9 @@ describe "Matrix#/" do
end
it "raises a TypeError if other is of wrong type" do
lambda { @a / nil }.should raise_error(TypeError)
lambda { @a / "a" }.should raise_error(TypeError)
lambda { @a / [ [1, 2] ] }.should raise_error(TypeError)
lambda { @a / Object.new }.should raise_error(TypeError)
-> { @a / nil }.should raise_error(TypeError)
-> { @a / "a" }.should raise_error(TypeError)
-> { @a / [ [1, 2] ] }.should raise_error(TypeError)
-> { @a / Object.new }.should raise_error(TypeError)
end
end

View file

@ -31,13 +31,13 @@ describe "Matrix#each with an argument" do
end
it "raises an ArgumentError for unrecognized argument" do
lambda {
-> {
@m.each("all"){}
}.should raise_error(ArgumentError)
lambda {
-> {
@m.each(nil){}
}.should raise_error(ArgumentError)
lambda {
-> {
@m.each(:left){}
}.should raise_error(ArgumentError)
end

View file

@ -38,13 +38,13 @@ describe "Matrix#each_with_index with an argument" do
end
it "raises an ArgumentError for unrecognized argument" do
lambda {
-> {
@m.each_with_index("all"){}
}.should raise_error(ArgumentError)
lambda {
-> {
@m.each_with_index(nil){}
}.should raise_error(ArgumentError)
lambda {
-> {
@m.each_with_index(:left){}
}.should raise_error(ArgumentError)
end

View file

@ -3,16 +3,16 @@ require 'matrix'
describe "Matrix::EigenvalueDecomposition#initialize" do
it "raises an error if argument is not a matrix" do
lambda {
-> {
Matrix::EigenvalueDecomposition.new([[]])
}.should raise_error(TypeError)
lambda {
-> {
Matrix::EigenvalueDecomposition.new(42)
}.should raise_error(TypeError)
end
it "raises an error if matrix is not square" do
lambda {
-> {
Matrix::EigenvalueDecomposition.new(Matrix[[1, 2]])
}.should raise_error(Matrix::ErrDimensionMismatch)
end

View file

@ -15,7 +15,7 @@ describe "Matrix#empty?" do
end
it "doesn't accept any parameter" do
lambda{
->{
Matrix[ [1, 2] ].empty?(42)
}.should raise_error(ArgumentError)
end
@ -38,23 +38,23 @@ describe "Matrix.empty" do
end
it "does not accept more than two parameters" do
lambda{
->{
Matrix.empty(1, 2, 3)
}.should raise_error(ArgumentError)
end
it "raises an error if both dimensions are > 0" do
lambda{
->{
Matrix.empty(1, 2)
}.should raise_error(ArgumentError)
end
it "raises an error if any dimension is < 0" do
lambda{
->{
Matrix.empty(-2, 0)
}.should raise_error(ArgumentError)
lambda{
->{
Matrix.empty(0, -2)
}.should raise_error(ArgumentError)
end

View file

@ -17,8 +17,8 @@ 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_error(Matrix::ErrDimensionMismatch)
-> { m ** 0 }.should raise_error(Matrix::ErrDimensionMismatch)
end
describe "that is <= 0" do
@ -30,8 +30,8 @@ describe "Matrix#**" do
it "raises a ErrDimensionMismatch 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_error(Matrix::ErrNotRegular)
-> { m ** 0 }.should raise_error(Matrix::ErrNotRegular)
end
end
end

View file

@ -130,16 +130,16 @@ end
describe "Matrix#find_index with two arguments" do
it "raises an ArgumentError for an unrecognized last argument" do
lambda {
-> {
@m.find_index(1, "all"){}
}.should raise_error(ArgumentError)
lambda {
-> {
@m.find_index(1, nil){}
}.should raise_error(ArgumentError)
lambda {
-> {
@m.find_index(1, :left){}
}.should raise_error(ArgumentError)
lambda {
-> {
@m.find_index(:diagonal, 1){}
}.should raise_error(ArgumentError)
end

View file

@ -21,7 +21,7 @@ describe "Matrix.hermitian?" do
Matrix.empty(0, 2),
Matrix.empty(2, 0),
].each do |rectangular_matrix|
lambda {
-> {
rectangular_matrix.hermitian?
}.should raise_error(Matrix::ErrDimensionMismatch)
end

View file

@ -13,7 +13,7 @@ describe "Matrix::LUPDecomposition#determinant" do
Matrix[[7, 8], [14, 46], [28, 82]],
].each do |m|
lup = m.lup
lambda {
-> {
lup.determinant
}.should raise_error(Matrix::ErrDimensionMismatch)
end

View file

@ -3,10 +3,10 @@ require 'matrix'
describe "Matrix::LUPDecomposition#initialize" do
it "raises an error if argument is not a matrix" do
lambda {
-> {
Matrix::LUPDecomposition.new([[]])
}.should raise_error(TypeError)
lambda {
-> {
Matrix::LUPDecomposition.new(42)
}.should raise_error(TypeError)
end

View file

@ -6,7 +6,7 @@ describe "Matrix::LUPDecomposition#solve" do
it "raises an error for singular matrices" do
a = Matrix[[1, 2, 3], [1, 3, 5], [2, 5, 8]]
lu = Matrix::LUPDecomposition.new(a)
lambda {
-> {
lu.solve(a)
}.should raise_error(Matrix::ErrNotRegular)
end
@ -31,7 +31,7 @@ describe "Matrix::LUPDecomposition#solve" do
it "raises an error when given a matrix of the wrong size" do
values = Matrix[[1, 2, 3, 4], [0, 1, 2, 3]]
lambda {
-> {
@lu.solve(values)
}.should raise_error(Matrix::ErrDimensionMismatch)
end
@ -44,7 +44,7 @@ describe "Matrix::LUPDecomposition#solve" do
it "raises an error when given a vector of the wrong size" do
values = Vector[14, 55]
lambda {
-> {
@lu.solve(values)
}.should raise_error(Matrix::ErrDimensionMismatch)
end

View file

@ -17,20 +17,20 @@ describe "Matrix#-" do
end
it "raises a Matrix::ErrDimensionMismatch if the matrices are different sizes" do
lambda { @a - Matrix[ [1] ] }.should raise_error(Matrix::ErrDimensionMismatch)
-> { @a - Matrix[ [1] ] }.should raise_error(Matrix::ErrDimensionMismatch)
end
it "raises a ExceptionForMatrix::ErrOperationNotDefined if other is a Numeric Type" do
lambda { @a - 2 }.should raise_error(Matrix::ErrOperationNotDefined)
lambda { @a - 1.2 }.should raise_error(Matrix::ErrOperationNotDefined)
lambda { @a - bignum_value }.should raise_error(Matrix::ErrOperationNotDefined)
-> { @a - 2 }.should raise_error(Matrix::ErrOperationNotDefined)
-> { @a - 1.2 }.should raise_error(Matrix::ErrOperationNotDefined)
-> { @a - bignum_value }.should raise_error(Matrix::ErrOperationNotDefined)
end
it "raises a TypeError if other is of wrong type" do
lambda { @a - nil }.should raise_error(TypeError)
lambda { @a - "a" }.should raise_error(TypeError)
lambda { @a - [ [1, 2] ] }.should raise_error(TypeError)
lambda { @a - Object.new }.should raise_error(TypeError)
-> { @a - nil }.should raise_error(TypeError)
-> { @a - "a" }.should raise_error(TypeError)
-> { @a - [ [1, 2] ] }.should raise_error(TypeError)
-> { @a - Object.new }.should raise_error(TypeError)
end
describe "for a subclass of Matrix" do

View file

@ -32,7 +32,7 @@ describe "Matrix#*" do
end
it "raises a Matrix::ErrDimensionMismatch if the matrices are different sizes" do
lambda { @a * Matrix[ [1] ] }.should raise_error(Matrix::ErrDimensionMismatch)
-> { @a * Matrix[ [1] ] }.should raise_error(Matrix::ErrDimensionMismatch)
end
it "returns a zero matrix if (nx0) * (0xn)" do
@ -52,10 +52,10 @@ describe "Matrix#*" do
end
it "raises a TypeError if other is of wrong type" do
lambda { @a * nil }.should raise_error(TypeError)
lambda { @a * "a" }.should raise_error(TypeError)
lambda { @a * [ [1, 2] ] }.should raise_error(TypeError)
lambda { @a * Object.new }.should raise_error(TypeError)
-> { @a * nil }.should raise_error(TypeError)
-> { @a * "a" }.should raise_error(TypeError)
-> { @a * [ [1, 2] ] }.should raise_error(TypeError)
-> { @a * Object.new }.should raise_error(TypeError)
end
describe "for a subclass of Matrix" do

View file

@ -18,7 +18,7 @@ describe "Matrix.normal?" do
Matrix.empty(0, 2),
Matrix.empty(2, 0),
].each do |rectangular_matrix|
lambda {
-> {
rectangular_matrix.normal?
}.should raise_error(Matrix::ErrDimensionMismatch)
end

View file

@ -18,7 +18,7 @@ describe "Matrix.orthogonal?" do
Matrix.empty(0, 2),
Matrix.empty(2, 0),
].each do |rectangular_matrix|
lambda {
-> {
rectangular_matrix.orthogonal?
}.should raise_error(Matrix::ErrDimensionMismatch)
end

View file

@ -24,7 +24,7 @@ describe "Matrix#permutation?" do
Matrix.empty(0, 2),
Matrix.empty(2, 0),
].each do |rectangular_matrix|
lambda {
-> {
rectangular_matrix.permutation?
}.should raise_error(Matrix::ErrDimensionMismatch)
end

View file

@ -17,20 +17,20 @@ describe "Matrix#+" do
end
it "raises a Matrix::ErrDimensionMismatch if the matrices are different sizes" do
lambda { @a + Matrix[ [1] ] }.should raise_error(Matrix::ErrDimensionMismatch)
-> { @a + Matrix[ [1] ] }.should raise_error(Matrix::ErrDimensionMismatch)
end
it "raises a ExceptionForMatrix::ErrOperationNotDefined if other is a Numeric Type" do
lambda { @a + 2 }.should raise_error(ExceptionForMatrix::ErrOperationNotDefined)
lambda { @a + 1.2 }.should raise_error(ExceptionForMatrix::ErrOperationNotDefined)
lambda { @a + bignum_value }.should raise_error(ExceptionForMatrix::ErrOperationNotDefined)
-> { @a + 2 }.should raise_error(ExceptionForMatrix::ErrOperationNotDefined)
-> { @a + 1.2 }.should raise_error(ExceptionForMatrix::ErrOperationNotDefined)
-> { @a + bignum_value }.should raise_error(ExceptionForMatrix::ErrOperationNotDefined)
end
it "raises a TypeError if other is of wrong type" do
lambda { @a + nil }.should raise_error(TypeError)
lambda { @a + "a" }.should raise_error(TypeError)
lambda { @a + [ [1, 2] ] }.should raise_error(TypeError)
lambda { @a + Object.new }.should raise_error(TypeError)
-> { @a + nil }.should raise_error(TypeError)
-> { @a + "a" }.should raise_error(TypeError)
-> { @a + [ [1, 2] ] }.should raise_error(TypeError)
-> { @a + Object.new }.should raise_error(TypeError)
end
describe "for a subclass of Matrix" do

View file

@ -20,11 +20,11 @@ describe "Matrix#regular?" do
end
it "raises an error for rectangular matrices" do
lambda {
-> {
Matrix[[1], [2], [3]].regular?
}.should raise_error(Matrix::ErrDimensionMismatch)
lambda {
-> {
Matrix.empty(3,0).regular?
}.should raise_error(Matrix::ErrDimensionMismatch)
end

View file

@ -30,7 +30,7 @@ describe "Matrix#row" do
end
it "never yields when out of bounds" do
lambda { @m.row(3){ raise } }.should_not raise_error
lambda { @m.row(-4){ raise } }.should_not raise_error
-> { @m.row(3){ raise } }.should_not raise_error
-> { @m.row(-4){ raise } }.should_not raise_error
end
end

View file

@ -27,11 +27,11 @@ describe :determinant, shared: true do
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

View file

@ -25,7 +25,7 @@ describe :inverse, shared: true do
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

View file

@ -6,7 +6,7 @@ describe :trace, shared: true do
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)
->{ Matrix[[1,2,3], [4,5,6]].trace}.should raise_error(Matrix::ErrDimensionMismatch)
end
end

View file

@ -19,11 +19,11 @@ describe "Matrix#singular?" do
end
it "raises an error for rectangular matrices" do
lambda {
-> {
Matrix[[1], [2], [3]].singular?
}.should raise_error(Matrix::ErrDimensionMismatch)
lambda {
-> {
Matrix.empty(3,0).singular?
}.should raise_error(Matrix::ErrDimensionMismatch)
end

View file

@ -21,7 +21,7 @@ describe "Matrix.symmetric?" do
Matrix.empty(0, 2),
Matrix.empty(2, 0),
].each do |rectangular_matrix|
lambda {
-> {
rectangular_matrix.symmetric?
}.should raise_error(Matrix::ErrDimensionMismatch)
end

View file

@ -20,7 +20,7 @@ describe "Matrix.unitary?" do
Matrix.empty(0, 2),
Matrix.empty(2, 0),
].each do |rectangular_matrix|
lambda {
-> {
rectangular_matrix.unitary?
}.should raise_error(Matrix::ErrDimensionMismatch)
end

View file

@ -7,7 +7,7 @@ describe "Vector#cross_product" do
end
it "raises an error unless both vectors have dimension 3" do
lambda {
-> {
Vector[1, 2, 3].cross_product(Vector[0, -4])
}.should raise_error(Vector::ErrDimensionMismatch)
end

View file

@ -8,8 +8,8 @@ describe "Vector.each2" do
end
it "requires one argument" do
lambda { @v.each2(@v2, @v2){} }.should raise_error(ArgumentError)
lambda { @v.each2(){} }.should raise_error(ArgumentError)
-> { @v.each2(@v2, @v2){} }.should raise_error(ArgumentError)
-> { @v.each2(){} }.should raise_error(ArgumentError)
end
describe "given one argument" do
@ -20,8 +20,8 @@ describe "Vector.each2" do
end
it "raises a DimensionMismatch error if the Vector size is different" do
lambda { @v.each2(Vector[1,2]){} }.should raise_error(Vector::ErrDimensionMismatch)
lambda { @v.each2(Vector[1,2,3,4]){} }.should raise_error(Vector::ErrDimensionMismatch)
-> { @v.each2(Vector[1,2]){} }.should raise_error(Vector::ErrDimensionMismatch)
-> { @v.each2(Vector[1,2,3,4]){} }.should raise_error(Vector::ErrDimensionMismatch)
end
it "yields arguments in sequence" do

View file

@ -11,7 +11,7 @@ describe "Vector#inner_product" do
end
it "raises an error for mismatched vectors" do
lambda {
-> {
Vector[1, 2, 3].inner_product(Vector[0, -4])
}.should raise_error(Vector::ErrDimensionMismatch)
end

View file

@ -8,10 +8,10 @@ describe "Vector#normalize" do
end
it "raises an error for zero vectors" do
lambda {
-> {
Vector[].normalize
}.should raise_error(Vector::ZeroVectorError)
lambda {
-> {
Vector[0, 0, 0].normalize
}.should raise_error(Vector::ZeroVectorError)
end