Sha256: 1caead51e3b499dc74d0fd01e414aa01519afb14aa99d254ed9d2fce66951f2c

Contents?: true

Size: 1.84 KB

Versions: 52

Compression:

Stored size: 1.84 KB

Contents

require File.expand_path('../../../spec_helper', __FILE__)

describe :complex_divide_complex, :shared => true do
  it "divides according to the usual rule for complex numbers" do
    a = Complex((1 * 10) - (2 * 20), (1 * 20) + (2 * 10))
    b = Complex(1, 2)
    (a / b).should == Complex(10, 20)

    c = Complex((1.5 * 100.2) - (2.1 * -30.3), (1.5 * -30.3) + (2.1 * 100.2))
    d = Complex(1.5, 2.1)
    # remember the floating-point arithmetic
    (c / d).should be_close(Complex(100.2, -30.3), TOLERANCE)
  end
end

describe :complex_divide_fixnum, :shared => true do
  it "divides both parts of the Complex number" do
    (Complex(20, 40) / 2).should == Complex(10, 20)
    (Complex(30, 30) / 10).should == Complex(3, 3)
  end

  it "raises a ZeroDivisionError when given zero" do
    lambda { Complex(20, 40) / 0 }.should raise_error(ZeroDivisionError)
  end
end

describe :complex_divide_bignum, :shared => true do
  it "divides both parts of the Complex number" do
    (Complex(20, 40) / 2).should == Complex(10, 20)
    (Complex(15, 16) / 2.0).should be_close(Complex(7.5, 8), TOLERANCE)
  end
end

describe :complex_divide_float, :shared => true do
  it "divides both parts of the Complex number" do
    (Complex(3, 9) / 1.5).should == Complex(2, 6)
    (Complex(15, 16) / 2.0).should be_close(Complex(7.5, 8), TOLERANCE)
  end

  it "returns Complex(Infinity, Infinity) when given zero" do
    (Complex(20, 40) / 0.0).real.infinite?.should == 1
    (Complex(20, 40) / 0.0).imag.infinite?.should == 1
    (Complex(-20, 40) / 0.0).real.infinite?.should == -1
    (Complex(-20, 40) / 0.0).imag.infinite?.should == 1
  end

end

describe :complex_divide_object, :shared => true do
  it "tries to coerce self into other" do
    value = Complex(3, 9)

    obj = mock("Object")
    obj.should_receive(:coerce).with(value).and_return([4, 2])
    (value / obj).should == 2
  end
end

Version data entries

52 entries across 52 versions & 2 rubygems

Version Path
rhodes-7.6.0 spec/framework_spec/app/spec/shared/complex/divide.rb
rhodes-7.5.1 spec/framework_spec/app/spec/shared/complex/divide.rb
rhodes-7.4.1 spec/framework_spec/app/spec/shared/complex/divide.rb
rhodes-7.1.17 spec/framework_spec/app/spec/shared/complex/divide.rb
rhodes-6.2.0 spec/framework_spec/app/spec/shared/complex/divide.rb
rhodes-6.0.11 spec/framework_spec/app/spec/shared/complex/divide.rb
rhodes-5.5.18 spec/framework_spec/app/spec/shared/complex/divide.rb
rhodes-5.5.17 spec/framework_spec/app/spec/shared/complex/divide.rb
rhodes-5.5.15 spec/framework_spec/app/spec/shared/complex/divide.rb
rhodes-5.5.0.22 spec/framework_spec/app/spec/shared/complex/divide.rb
rhodes-5.5.2 spec/framework_spec/app/spec/shared/complex/divide.rb
rhodes-5.5.0.7 spec/framework_spec/app/spec/shared/complex/divide.rb
rhodes-5.5.0.3 spec/framework_spec/app/spec/shared/complex/divide.rb
rhodes-5.5.0 spec/framework_spec/app/spec/shared/complex/divide.rb
tauplatform-1.0.3 spec/framework_spec/app/spec/shared/complex/divide.rb
tauplatform-1.0.2 spec/framework_spec/app/spec/shared/complex/divide.rb
tauplatform-1.0.1 spec/framework_spec/app/spec/shared/complex/divide.rb
rhodes-3.5.1.12 spec/framework_spec/app/spec/shared/complex/divide.rb
rhodes-3.3.5 spec/framework_spec/app/spec/shared/complex/divide.rb
rhodes-3.4.2 spec/framework_spec/app/spec/shared/complex/divide.rb