Sha256: 5b30c92f8c027203d72faf0d311f86a45e4279413712b5c346370ec957a8d991

Contents?: true

Size: 1.91 KB

Versions: 2

Compression:

Stored size: 1.91 KB

Contents

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubysl-complex-1.0.0 spec/math/shared/log10.rb
rubysl-complex-2.0.0 spec/math/shared/log10.rb