ruby-changes:52620
From: eregon <ko1@a...>
Date: Tue, 25 Sep 2018 19:41:28 +0900 (JST)
Subject: [ruby-changes:52620] eregon:r64831 (trunk): Update to ruby/spec@241f9e7
eregon 2018-09-25 19:41:16 +0900 (Tue, 25 Sep 2018) New Revision: 64831 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64831 Log: Update to ruby/spec@241f9e7 Added directories: trunk/spec/ruby/core/complex/shared/ trunk/spec/ruby/library/monitor/ trunk/spec/ruby/library/rbconfig/sizeof/ Added files: trunk/spec/ruby/core/complex/shared/abs.rb trunk/spec/ruby/core/complex/shared/arg.rb trunk/spec/ruby/core/complex/shared/conjugate.rb trunk/spec/ruby/core/complex/shared/divide.rb trunk/spec/ruby/core/complex/shared/image.rb trunk/spec/ruby/core/complex/shared/rect.rb trunk/spec/ruby/core/float/shared/arg.rb trunk/spec/ruby/core/kernel/fixtures/caller_at_exit.rb trunk/spec/ruby/core/module/fixtures/autoload_required_directly.rb trunk/spec/ruby/core/module/fixtures/autoload_required_directly_nested.rb trunk/spec/ruby/core/numeric/shared/arg.rb trunk/spec/ruby/core/numeric/shared/conj.rb trunk/spec/ruby/core/numeric/shared/imag.rb trunk/spec/ruby/core/thread/backtrace/location/fixtures/absolute_path_method_added.rb trunk/spec/ruby/library/monitor/mon_initialize_spec.rb trunk/spec/ruby/library/rbconfig/sizeof/sizeof_spec.rb Removed directories: trunk/spec/ruby/shared/complex/ Modified files: trunk/spec/ruby/core/complex/abs2_spec.rb trunk/spec/ruby/core/complex/abs_spec.rb trunk/spec/ruby/core/complex/angle_spec.rb trunk/spec/ruby/core/complex/arg_spec.rb trunk/spec/ruby/core/complex/coerce_spec.rb trunk/spec/ruby/core/complex/conj_spec.rb trunk/spec/ruby/core/complex/conjugate_spec.rb trunk/spec/ruby/core/complex/constants_spec.rb trunk/spec/ruby/core/complex/denominator_spec.rb trunk/spec/ruby/core/complex/divide_spec.rb trunk/spec/ruby/core/complex/equal_value_spec.rb trunk/spec/ruby/core/complex/exponent_spec.rb trunk/spec/ruby/core/complex/imag_spec.rb trunk/spec/ruby/core/complex/imaginary_spec.rb trunk/spec/ruby/core/complex/inspect_spec.rb trunk/spec/ruby/core/complex/integer_spec.rb trunk/spec/ruby/core/complex/magnitude_spec.rb trunk/spec/ruby/core/complex/minus_spec.rb trunk/spec/ruby/core/complex/multiply_spec.rb trunk/spec/ruby/core/complex/negative_spec.rb trunk/spec/ruby/core/complex/numerator_spec.rb trunk/spec/ruby/core/complex/phase_spec.rb trunk/spec/ruby/core/complex/plus_spec.rb trunk/spec/ruby/core/complex/polar_spec.rb trunk/spec/ruby/core/complex/positive_spec.rb trunk/spec/ruby/core/complex/quo_spec.rb trunk/spec/ruby/core/complex/rationalize_spec.rb trunk/spec/ruby/core/complex/real_spec.rb trunk/spec/ruby/core/complex/rect_spec.rb trunk/spec/ruby/core/complex/rectangular_spec.rb trunk/spec/ruby/core/complex/to_s_spec.rb trunk/spec/ruby/core/encoding/converter/convpath_spec.rb trunk/spec/ruby/core/encoding/converter/search_convpath_spec.rb trunk/spec/ruby/core/float/abs_spec.rb trunk/spec/ruby/core/float/angle_spec.rb trunk/spec/ruby/core/float/arg_spec.rb trunk/spec/ruby/core/float/phase_spec.rb trunk/spec/ruby/core/kernel/Complex_spec.rb trunk/spec/ruby/core/kernel/caller_spec.rb trunk/spec/ruby/core/kernel/lambda_spec.rb trunk/spec/ruby/core/marshal/dump_spec.rb trunk/spec/ruby/core/math/acos_spec.rb trunk/spec/ruby/core/math/acosh_spec.rb trunk/spec/ruby/core/math/asin_spec.rb trunk/spec/ruby/core/math/log10_spec.rb trunk/spec/ruby/core/math/log_spec.rb trunk/spec/ruby/core/module/autoload_spec.rb trunk/spec/ruby/core/numeric/abs_spec.rb trunk/spec/ruby/core/numeric/angle_spec.rb trunk/spec/ruby/core/numeric/arg_spec.rb trunk/spec/ruby/core/numeric/conj_spec.rb trunk/spec/ruby/core/numeric/conjugate_spec.rb trunk/spec/ruby/core/numeric/imag_spec.rb trunk/spec/ruby/core/numeric/imaginary_spec.rb trunk/spec/ruby/core/numeric/phase_spec.rb trunk/spec/ruby/core/numeric/polar_spec.rb trunk/spec/ruby/core/numeric/real_spec.rb trunk/spec/ruby/core/proc/source_location_spec.rb trunk/spec/ruby/core/rational/integer_spec.rb trunk/spec/ruby/core/struct/shared/select.rb trunk/spec/ruby/core/thread/backtrace/location/absolute_path_spec.rb trunk/spec/ruby/language/fixtures/rescue.rb trunk/spec/ruby/language/precedence_spec.rb trunk/spec/ruby/language/rescue_spec.rb trunk/spec/ruby/library/conditionvariable/wait_spec.rb trunk/spec/ruby/library/matrix/divide_spec.rb trunk/spec/ruby/library/matrix/real_spec.rb trunk/spec/ruby/library/socket/addrinfo/getnameinfo_spec.rb trunk/spec/ruby/library/socket/ancillarydata/family_spec.rb trunk/spec/ruby/library/socket/ancillarydata/initialize_spec.rb trunk/spec/ruby/library/socket/ancillarydata/int_spec.rb trunk/spec/ruby/library/socket/ancillarydata/ip_pktinfo_spec.rb trunk/spec/ruby/library/socket/ancillarydata/ipv6_pktinfo_spec.rb trunk/spec/ruby/library/socket/ancillarydata/level_spec.rb trunk/spec/ruby/library/socket/ancillarydata/type_spec.rb trunk/spec/ruby/library/socket/basicsocket/getsockopt_spec.rb trunk/spec/ruby/library/socket/basicsocket/recvmsg_nonblock_spec.rb trunk/spec/ruby/library/socket/basicsocket/recvmsg_spec.rb trunk/spec/ruby/library/socket/basicsocket/shutdown_spec.rb trunk/spec/ruby/library/socket/option/initialize_spec.rb trunk/spec/ruby/library/socket/shared/socketpair.rb trunk/spec/ruby/library/socket/socket/connect_nonblock_spec.rb trunk/spec/ruby/library/socket/socket/getaddrinfo_spec.rb trunk/spec/ruby/library/socket/socket/gethostbyaddr_spec.rb trunk/spec/ruby/library/socket/socket/getifaddrs_spec.rb trunk/spec/ruby/library/socket/socket/initialize_spec.rb trunk/spec/ruby/library/socket/socket/listen_spec.rb trunk/spec/ruby/library/socket/socket/sysaccept_spec.rb trunk/spec/ruby/library/socket/tcpserver/initialize_spec.rb trunk/spec/ruby/library/socket/tcpserver/listen_spec.rb trunk/spec/ruby/library/socket/tcpserver/new_spec.rb trunk/spec/ruby/library/socket/tcpserver/sysaccept_spec.rb trunk/spec/ruby/library/socket/tcpsocket/gethostbyname_spec.rb trunk/spec/ruby/library/socket/tcpsocket/initialize_spec.rb trunk/spec/ruby/library/socket/tcpsocket/shared/new.rb trunk/spec/ruby/library/socket/udpsocket/initialize_spec.rb trunk/spec/ruby/library/socket/udpsocket/new_spec.rb trunk/spec/ruby/library/socket/udpsocket/send_spec.rb trunk/spec/ruby/library/socket/unixserver/sysaccept_spec.rb trunk/spec/ruby/library/stringio/external_encoding_spec.rb trunk/spec/ruby/optional/capi/ext/thread_spec.c trunk/spec/ruby/optional/capi/spec_helper.rb trunk/spec/ruby/optional/capi/thread_spec.rb trunk/spec/ruby/shared/rational/Rational.rb trunk/spec/ruby/shared/rational/exponent.rb trunk/spec/ruby/shared/rational/inspect.rb trunk/spec/ruby/shared/rational/round.rb trunk/spec/ruby/shared/rational/to_r.rb trunk/spec/ruby/shared/rational/to_s.rb Index: spec/ruby/core/complex/multiply_spec.rb =================================================================== --- spec/ruby/core/complex/multiply_spec.rb (revision 64830) +++ spec/ruby/core/complex/multiply_spec.rb (revision 64831) @@ -1,5 +1,49 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/complex/multiply_spec.rb#L1 -require_relative '../../shared/complex/multiply' +require_relative '../../spec_helper' describe "Complex#*" do - it_behaves_like :complex_multiply, :* + describe "with Complex" do + it "multiplies according to the usual rule for complex numbers: (a + bi) * (c + di) = ac - bd + (ad + bc)i" do + (Complex(1, 2) * Complex(10, 20)).should == Complex((1 * 10) - (2 * 20), (1 * 20) + (2 * 10)) + (Complex(1.5, 2.1) * Complex(100.2, -30.3)).should == Complex((1.5 * 100.2) - (2.1 * -30.3), (1.5 * -30.3) + (2.1 * 100.2)) + end + end + + describe "with Integer" do + it "multiplies both parts of self by the given Integer" do + (Complex(3, 2) * 50).should == Complex(150, 100) + (Complex(-3, 2) * 50.5).should == Complex(-151.5, 101) + end + end + + describe "with Object" do + it "tries to coerce self into other" do + value = Complex(3, 9) + + obj = mock("Object") + obj.should_receive(:coerce).with(value).and_return([2, 5]) + (value * obj).should == 2 * 5 + end + end + + describe "with a Numeric which responds to #real? with true" do + it "multiples both parts of self by other" do + other = mock_numeric('other') + real = mock_numeric('real') + imag = mock_numeric('imag') + other.should_receive(:real?).and_return(true) + real.should_receive(:*).with(other).and_return(1) + imag.should_receive(:*).with(other).and_return(2) + (Complex(real, imag) * other).should == Complex(1, 2) + end + + describe "with a Numeric which responds to #real? with false" do + it "coerces the passed argument to Complex and multiplies the resulting elements" do + complex = Complex(3, 0) + other = mock_numeric('other') + other.should_receive(:real?).any_number_of_times.and_return(false) + other.should_receive(:coerce).with(complex).and_return([5, 2]) + (complex * other).should == 10 + end + end + end end Index: spec/ruby/core/complex/real_spec.rb =================================================================== --- spec/ruby/core/complex/real_spec.rb (revision 64830) +++ spec/ruby/core/complex/real_spec.rb (revision 64831) @@ -1,7 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/complex/real_spec.rb#L1 -require_relative '../../shared/complex/real' +require_relative '../../spec_helper' describe "Complex#real" do - it_behaves_like :complex_real, :real + it "returns the real part of self" do + Complex(1, 0).real.should == 1 + Complex(2, 1).real.should == 2 + Complex(6.7, 8.9).real.should == 6.7 + Complex(bignum_value, 3).real.should == bignum_value + end end describe "Complex#real?" do Index: spec/ruby/core/complex/conj_spec.rb =================================================================== --- spec/ruby/core/complex/conj_spec.rb (revision 64830) +++ spec/ruby/core/complex/conj_spec.rb (revision 64831) @@ -1,5 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/complex/conj_spec.rb#L1 require_relative '../../spec_helper' -require_relative '../../shared/complex/conjugate' +require_relative 'shared/conjugate' describe "Complex#conj" do it_behaves_like :complex_conjugate, :conj Index: spec/ruby/core/complex/shared/rect.rb =================================================================== --- spec/ruby/core/complex/shared/rect.rb (nonexistent) +++ spec/ruby/core/complex/shared/rect.rb (revision 64831) @@ -0,0 +1,94 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/complex/shared/rect.rb#L1 +describe :complex_rect, shared: true do + before :each do + @numbers = [ + Complex(1), + Complex(0, 20), + Complex(0, 0), + Complex(0.0), + Complex(9999999**99), + Complex(-20), + Complex.polar(76, 10) + ] + end + + it "returns an Array" do + @numbers.each do |number| + number.send(@method).should be_an_instance_of(Array) + end + end + + it "returns a two-element Array" do + @numbers.each do |number| + number.send(@method).size.should == 2 + end + end + + it "returns the real part of self as the first element" do + @numbers.each do |number| + number.send(@method).first.should == number.real + end + end + + it "returns the imaginary part of self as the last element" do + @numbers.each do |number| + number.send(@method).last.should == number.imaginary + end + end + + it "raises an ArgumentError if given any arguments" do + @numbers.each do |number| + lambda { number.send(@method, number) }.should raise_error(ArgumentError) + end + end +end + +describe :complex_rect_class, shared: true do + describe "passed a Numeric n which responds to #real? with true" do + it "returns a Complex with real part n and imaginary part 0" do + n = mock_numeric('n') + n.should_receive(:real?).any_number_of_times.and_return(true) + result = Complex.send(@method, n) + result.real.should == n + result.imag.should == 0 + end + end + + describe "passed a Numeric which responds to #real? with false" do + it "raises TypeError" do + n = mock_numeric('n') + n.should_receive(:real?).any_number_of_times.and_return(false) + lambda { Complex.send(@method, n) }.should raise_error(TypeError) + end + end + + describe "passed Numerics n1 and n2 and at least one responds to #real? with false" do + [[false, false], [false, true], [true, false]].each do |r1, r2| + it "raises TypeError" do + n1 = mock_numeric('n1') + n2 = mock_numeric('n2') + n1.should_receive(:real?).any_number_of_times.and_return(r1) + n2.should_receive(:real?).any_number_of_times.and_return(r2) + lambda { Complex.send(@method, n1, n2) }.should raise_error(TypeError) + end + end + end + + describe "passed Numerics n1 and n2 and both respond to #real? with true" do + it "returns a Complex with real part n1 and imaginary part n2" do + n1 = mock_numeric('n1') + n2 = mock_numeric('n2') + n1.should_receive(:real?).any_number_of_times.and_return(true) + n2.should_receive(:real?).any_number_of_times.and_return(true) + result = Complex.send(@method, n1, n2) + result.real.should == n1 + result.imag.should == n2 + end + end + + describe "passed a non-Numeric" do + it "raises TypeError" do + lambda { Complex.send(@method, :sym) }.should raise_error(TypeError) + lambda { Complex.send(@method, 0, :sym) }.should raise_error(TypeError) + end + end +end Property changes on: spec/ruby/core/complex/shared/rect.rb ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +LF \ No newline at end of property Index: spec/ruby/core/complex/shared/image.rb =================================================================== --- spec/ruby/core/complex/shared/image.rb (nonexistent) +++ spec/ruby/core/complex/shared/image.rb (revision 64831) @@ -0,0 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/complex/shared/image.rb#L1 +describe :complex_image, shared: true do + it "returns the imaginary part of self" do + Complex(1, 0).send(@method).should == 0 + Complex(2, 1).send(@method).should == 1 + Complex(6.7, 8.9).send(@method).should == 8.9 + Complex(1, bignum_value).send(@method).should == bignum_value + end +end Property changes on: spec/ruby/core/complex/shared/image.rb ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +LF \ No newline at end of property Index: spec/ruby/core/complex/rect_spec.rb =================================================================== --- spec/ruby/core/complex/rect_spec.rb (revision 64830) +++ spec/ruby/core/complex/rect_spec.rb (revision 64831) @@ -1,4 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/complex/rect_spec.rb#L1 -require_relative '../../shared/complex/rect' +require_relative '../../spec_helper' +require_relative 'shared/rect' describe "Complex#rect" do it_behaves_like :complex_rect, :rect Index: spec/ruby/core/complex/positive_spec.rb =================================================================== --- spec/ruby/core/complex/positive_spec.rb (revision 64830) +++ spec/ruby/core/complex/positive_spec.rb (revision 64831) @@ -1,3 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/complex/positive_spec.rb#L1 +require_relative '../../spec_helper' + describe "Complex#positive?" do it "is undefined" do c = Complex(1) Index: spec/ruby/core/complex/numerator_spec.rb =================================================================== --- spec/ruby/core/complex/numerator_spec.rb (revision 64830) +++ spec/ruby/core/complex/numerator_spec.rb (revision 64831) @@ -1,5 +1,19 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/complex/numerator_spec.rb#L1 -require_relative '../../shared/complex/numerator' +require_relative '../../spec_helper' describe "Complex#numerator" do - it_behaves_like :complex_numerator, :numerator + it "returns self's numerator" do + Complex(2).numerator.should == Complex(2) + Complex(3, 4).numerator.should == Complex(3, 4) + + Complex(Rational(3, 4), Rational(3, 4)).numerator.should == Complex(3, 3) + Complex(Rational(7, 4), Rational(8, 4)).numerator.should == Complex(7, 8) + + Complex(Rational(7, 8), Rational(8, 4)).numerator.should == Complex(7, 16) + Complex(Rational(7, 4), Rational(8, 8)).numerator.should == Complex(7, 4) + + # NOTE: + # Bug? - Fails with a MethodMissingError + # (undefined method `denominator' for 3.5:Float) + # Complex(3.5, 3.7).numerator + end end Index: spec/ruby/core/complex/magnitude_spec.rb =================================================================== --- spec/ruby/core/complex/magnitude_spec.rb (revision 64830) +++ spec/ruby/core/complex/magnitude_spec.rb (revision 64831) @@ -1,4 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/complex/magnitude_spec.rb#L1 -require_relative '../../shared/complex/abs' +require_relative '../../spec_helper' +require_relative 'shared/abs' describe "Complex#magnitude" do it_behaves_like :complex_abs, :magnitude Index: spec/ruby/core/complex/abs2_spec.rb =================================================================== --- spec/ruby/core/complex/abs2_spec.rb (revision 64830) +++ spec/ruby/core/complex/abs2_spec.rb (revision 64831) @@ -1,5 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/complex/abs2_spec.rb#L1 -require_relative '../../shared/complex/abs2' +require_relative '../../spec_helper' describe "Complex#abs2" do - it_behaves_like :complex_abs2, :abs2 + it "returns the sum of the squares of the real and imaginary parts" do + Complex(1, -2).abs2.should == 1 + 4 + Complex(-0.1, 0.2).abs2.should be_close(0.01 + 0.04, TOLERANCE) + Complex(0).abs2.should == 0 + end end Index: spec/ruby/core/complex/shared/divide.rb =================================================================== --- spec/ruby/core/complex/shared/divide.rb (nonexistent) +++ spec/ruby/core/complex/shared/divide.rb (revision 64831) @@ -0,0 +1,82 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/complex/shared/divide.rb#L1 +describe :complex_divide, shared: true do + describe "with Complex" 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.send(@method, 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.send(@method, d).should be_close(Complex(100.2, -30.3), TOLERANCE) + end + end + + describe "with Fixnum" do + it "divides both parts of the Complex number" do + Complex(20, 40).send(@method, 2).should == Complex(10, 20) + Complex(30, 30).send(@method, 10).should == Complex(3, 3) + end + + it "raises a ZeroDivisionError when given zero" do + lambda { Complex(20, 40).send(@method, 0) }.should raise_error(ZeroDivisionError) + end + + it "produces Rational parts" do + Complex(5, 9).send(@method, 2).should eql(Complex(Rational(5,2), Rational(9,2))) + end + end + + describe "with Bignum" do + it "divides both parts of the Complex number" do + Complex(20, 40).send(@method, 2).should == Complex(10, 20) + Complex(15, 16).send(@method, 2.0).should be_close(Complex(7.5, 8), TOLERANCE) + end + end + + describe "with Float" do + it "divides both parts of the Complex number" do + Complex(3, 9).send(@method, 1.5).should == Complex(2, 6) + Complex(15, 16).send(@method, 2.0).should be_close(Complex(7.5, 8), TOLERANCE) + end + + it "returns Complex(Infinity, Infinity) when given zero" do + Complex(20, 40).send(@method, 0.0).real.infinite?.should == 1 + Complex(20, 40).send(@method, 0.0).imag.infinite?.should == 1 + Complex(-20, 40).send(@method, 0.0).real.infinite?.should == -1 + Complex(-20, 40).send(@method, 0.0).imag.infinite?.should == 1 + end + end + + describe "with Object" 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.send(@method, obj).should == 2 + end + end + + describe "with a Numeric which responds to #real? with true" do + it "returns Complex(real.quo(other), imag.quo(other))" do + other = mock_numeric('other') + real = mock_numeric('real') + imag = mock_numeric('imag') + other.should_receive(:real?).and_return(true) + real.should_receive(:quo).with(other).and_return(1) + imag.should_receive(:quo).with(other).and_return(2) + Complex(real, imag).send(@method, other).should == Complex(1, 2) + end + end + + describe "with a Numeric which responds to #real? with false" do + it "coerces the passed argument to Complex and divides the resulting elements" do + complex = Complex(3, 0) + other = mock_numeric('other') + other.should_receive(:real?).any_number_of_times.and_return(false) + other.should_receive(:coerce).with(complex).and_return([5, 2]) + complex.send(@method, other).should eql(Rational(5, 2)) + end + end +end Property changes on: spec/ruby/core/complex/shared/divide.rb ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +LF \ No newline at end of property Index: spec/ruby/core/complex/coerce_spec.rb =================================================================== --- spec/ruby/core/complex/coerce_spec.rb (revision 64830) +++ spec/ruby/core/complex/coerce_spec.rb (revision 64831) @@ -1,5 +1,70 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/complex/coerce_spec.rb#L1 -require_relative '../../shared/complex/coerce' +require_relative '../../spec_helper' describe "Complex#coerce" do - it_behaves_like :complex_coerce, :coerce + before :each do + @one = Complex(1) + end + + it "returns an array containing other and self as Complex when other is an Integer" do + result = @one.coerce(2) + result.should == [2, 1] + result.first.should be_kind_of(Complex) + result.last.should be_kind_of(Complex) + end + + it "returns an array containing other and self as Complex when other is a Float" do + result = @one.coerce(20.5) + result.should == [20.5, 1] + result.first.should be_kind_of(Complex) + result.last.should be_kind_of(Complex) + end + + it "returns an array containing other and self as Complex when other is a Bignum" do + result = @one.coerce(4294967296) + result.should == [4294967296, 1] + result.first.should be_kind_of(Complex) + result.last.should be_kind_of(Complex) + end + + it "returns an array containing other and self as Complex when other is a Rational" do + result = @one.coerce(Rational(5,6)) + result.should == [Rational(5,6), 1] + result.first.should be_kind_of(Complex) + result.last.should be_kind_of(Complex) + end + + it "returns an array containing other and self when other is a Complex" do + other = Complex(2) + result = @one.coerce(other) + result.should == [other, @one] + result.first.should equal(other) + result.last.should equal(@one) + end + + it "returns an array containing other as Complex and self when other is a Numeric which responds to #real? with true" do + other = mock_numeric('other') + other.should_receive(:real?).any_number_of_times.and_return(true) + result = @one.coerce(other) + result.should == [other, @one] + result.first.should eql(Complex(other)) + result.last.should equal(@one) + end + + it "raises TypeError when other is a Numeric which responds to #real? with false" do + other = mock_numeric('other') + other.should_receive(:real?).any_number_of_times.and_return(false) + lambda { @one.coerce(other) }.should raise_error(TypeError) + end + + it "raises a TypeError when other is a String" do + lambda { @one.coerce("20") }.should raise_error(TypeError) + end + + it "raises a TypeError when other is nil" do + lambda { @one.coerce(nil) }.should raise_error(TypeError) + end + + it "raises a TypeError when other is false" do + lambda { @one.coerce(false) }.should raise_error(TypeError) + end end Index: spec/ruby/core/complex/to_s_spec.rb =================================================================== --- spec/ruby/core/complex/to_s_spec.rb (revision 64830) +++ spec/ruby/core/complex/to_s_spec.rb (revision 64831) @@ -1,5 +1,44 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/complex/to_s_spec.rb#L1 -require_relative '../../shared/complex/to_s' +require_relative '../../spec_helper' describe "Complex#to_s" do - it_behaves_like :complex_to_s, :to_s + describe "when self's real component is 0" do + it "returns both the real and imaginary component even when the real is 0" do + Complex(0, 5).to_s.should == "0+5i" + Complex(0, -3.2).to_s.should == "0-3.2i" + end + end + + it "returns self as String" do + Complex(1, 5).to_s.should == "1+5i" + Complex(-2.5, 1.5).to_s.should == "-2.5+1.5i" + + Complex(1, -5).to_s.should == "1-5i" + Complex(-2.5, -1.5).to_s.should == "-2.5-1.5i" + + # Guard against the Mathn library + guard -> { !defined?(Math.rsqrt) } do + Complex(1, 0).to_s.should == "1+0i" + Complex(1, -0).to_s.should == "1+0i" + end + end + + it "returns 1+0.0i for Complex(1, 0.0)" do + Complex(1, 0.0).to_s.should == "1+0.0i" + end + + it "returns 1-0.0i for Complex(1, -0.0)" do + Complex(1, -0.0).to_s.should == "1-0.0i" + end + + it "returns 1+Infinity*i for Complex(1, Infinity)" do + Complex(1, infinity_value).to_s.should == "1+Infinity*i" + end + + it "returns 1-Infinity*i for Complex(1, -Infinity)" do + Complex(1, -infinity_value).to_s.should == "1-Infinity*i" + end + + it "returns 1+NaN*i for Complex(1, NaN)" do + Complex(1, nan_value).to_s.should == "1+NaN*i" + end end Index: spec/ruby/core/complex/imag_spec.rb =================================================================== --- spec/ruby/core/complex/imag_spec.rb (revision 64830) +++ spec/ruby/core/complex/imag_spec.rb (revision 64831) @@ -1,4 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/complex/imag_spec.rb#L1 -require_relative '../../shared/complex/image' +require_relative '../../spec_helper' +require_relative 'shared/image' describe "Complex#imag" do it_behaves_like :complex_image, :imag Index: spec/ruby/core/complex/rationalize_spec.rb ==== (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/