1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/spec/ruby/library/complex/math/shared/log10.rb
eregon 1d15d5f080 Move spec/rubyspec to spec/ruby for consistency
* Other ruby implementations use the spec/ruby directory.
  [Misc #13792] [ruby-core:82287]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-20 20:18:52 +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