ruby/spec/rubyspec/library/complex/math/shared/log10.rb
eregon 95e8c48dd3 Add in-tree mspec and ruby/spec
* For easier modifications of ruby/spec by MRI developers.
* .gitignore: track changes under spec.
* spec/mspec, spec/rubyspec: add in-tree mspec and ruby/spec.
  These files can therefore be updated like any other file in MRI.
  Instructions are provided in spec/README.
  [Feature #13156] [ruby-core:79246]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58595 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-07 12:04:49 +00:00

41 lines
1.9 KiB
Ruby

require File.expand_path('../../fixtures/classes', __FILE__)
describe :complex_math_log10, shared: true do
it "returns the base-10 logarithm of the passed argument" do
@object.send(:log10, 0.0001).should be_close(-4.0, TOLERANCE)
@object.send(:log10, 0.000000000001e-15).should be_close(-27.0, TOLERANCE)
@object.send(:log10, 1).should be_close(0.0, TOLERANCE)
@object.send(:log10, 10).should be_close(1.0, TOLERANCE)
@object.send(:log10, 10e15).should be_close(16.0, TOLERANCE)
end
it "returns the base-10 logarithm for Complex numbers" do
@object.send(:log10, Complex(3, 4)).should be_close(Complex(0.698970004336019, 0.402719196273373), TOLERANCE)
@object.send(:log10, Complex(-3, 4)).should be_close(Complex(0.698970004336019, 0.961657157568468), TOLERANCE)
end
# BUG: does not work correctly, because Math#log10
# does not check for negative values
#it "returns the base-10 logarithm for negative numbers as a Complex number" do
# @object.send(:log10, -10).should be_close(Complex(2.30258509299405, 3.14159265358979), TOLERANCE)
# @object.send(:log10, -20).should be_close(Complex(2.99573227355399, 3.14159265358979), TOLERANCE)
#end
end
describe :complex_math_log10_bang, shared: true do
it "returns the base-10 logarithm of the argument" do
@object.send(:log10!, 0.0001).should be_close(-4.0, TOLERANCE)
@object.send(:log10!, 0.000000000001e-15).should be_close(-27.0, TOLERANCE)
@object.send(:log10!, 1).should be_close(0.0, TOLERANCE)
@object.send(:log10!, 10).should be_close(1.0, TOLERANCE)
@object.send(:log10!, 10e15).should be_close(16.0, TOLERANCE)
end
it "raises an Errno::EDOM when the passed argument is negative" do
lambda { @object.send(:log10!, -10) }.should raise_error(Errno::EDOM)
end
it "raises a TypeError when passed a Complex number" do
lambda { @object.send(:log10!, Complex(4, 5)) }.should raise_error(TypeError)
end
end