summaryrefslogtreecommitdiff
path: root/spec/ruby/shared
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/shared')
-rw-r--r--spec/ruby/shared/complex/Complex.rb141
-rw-r--r--spec/ruby/shared/complex/abs.rb12
-rw-r--r--spec/ruby/shared/complex/abs2.rb12
-rw-r--r--spec/ruby/shared/complex/arg.rb9
-rw-r--r--spec/ruby/shared/complex/coerce.rb70
-rw-r--r--spec/ruby/shared/complex/conjugate.rb8
-rw-r--r--spec/ruby/shared/complex/constants.rb7
-rw-r--r--spec/ruby/shared/complex/denominator.rb13
-rw-r--r--spec/ruby/shared/complex/divide.rb84
-rw-r--r--spec/ruby/shared/complex/equal_value.rb93
-rw-r--r--spec/ruby/shared/complex/exponent.rb61
-rw-r--r--spec/ruby/shared/complex/float/arg.rb38
-rw-r--r--spec/ruby/shared/complex/image.rb10
-rw-r--r--spec/ruby/shared/complex/inspect.rb14
-rw-r--r--spec/ruby/shared/complex/minus.rb45
-rw-r--r--spec/ruby/shared/complex/multiply.rb49
-rw-r--r--spec/ruby/shared/complex/numerator.rb19
-rw-r--r--spec/ruby/shared/complex/numeric/arg.rb38
-rw-r--r--spec/ruby/shared/complex/numeric/conj.rb20
-rw-r--r--spec/ruby/shared/complex/numeric/imag.rb26
-rw-r--r--spec/ruby/shared/complex/numeric/polar.rb50
-rw-r--r--spec/ruby/shared/complex/numeric/real.rb30
-rw-r--r--spec/ruby/shared/complex/plus.rb45
-rw-r--r--spec/ruby/shared/complex/polar.rb22
-rw-r--r--spec/ruby/shared/complex/real.rb8
-rw-r--r--spec/ruby/shared/complex/rect.rb96
-rw-r--r--spec/ruby/shared/complex/to_s.rb44
-rw-r--r--spec/ruby/shared/rational/Rational.rb2
-rw-r--r--spec/ruby/shared/rational/exponent.rb6
-rw-r--r--spec/ruby/shared/rational/inspect.rb12
-rw-r--r--spec/ruby/shared/rational/round.rb7
-rw-r--r--spec/ruby/shared/rational/to_r.rb12
-rw-r--r--spec/ruby/shared/rational/to_s.rb7
33 files changed, 27 insertions, 1083 deletions
diff --git a/spec/ruby/shared/complex/Complex.rb b/spec/ruby/shared/complex/Complex.rb
deleted file mode 100644
index 201e09e6ce..0000000000
--- a/spec/ruby/shared/complex/Complex.rb
+++ /dev/null
@@ -1,141 +0,0 @@
-require_relative '../../spec_helper'
-
-describe :kernel_Complex, shared: true do
- describe "when passed [Complex, Complex]" do
- it "returns a new Complex number based on the two given numbers" do
- Complex(Complex(3, 4), Complex(5, 6)).should == Complex(3 - 6, 4 + 5)
- Complex(Complex(1.5, 2), Complex(-5, 6.3)).should == Complex(1.5 - 6.3, 2 - 5)
- end
- end
-
- describe "when passed [Complex]" do
- it "returns the passed Complex number" do
- Complex(Complex(1, 2)).should == Complex(1, 2)
- Complex(Complex(-3.4, bignum_value)).should == Complex(-3.4, bignum_value)
- end
- end
-
- describe "when passed [Integer, Integer]" do
- it "returns a new Complex number" do
- Complex(1, 2).should be_an_instance_of(Complex)
- Complex(1, 2).real.should == 1
- Complex(1, 2).imag.should == 2
-
- Complex(-3, -5).should be_an_instance_of(Complex)
- Complex(-3, -5).real.should == -3
- Complex(-3, -5).imag.should == -5
-
- Complex(3.5, -4.5).should be_an_instance_of(Complex)
- Complex(3.5, -4.5).real.should == 3.5
- Complex(3.5, -4.5).imag.should == -4.5
-
- Complex(bignum_value, 30).should be_an_instance_of(Complex)
- Complex(bignum_value, 30).real.should == bignum_value
- Complex(bignum_value, 30).imag.should == 30
- end
- end
-
- describe "when passed [Integer/Float]" do
- it "returns a new Complex number with 0 as the imaginary component" do
- # Guard against the Mathn library
- conflicts_with :Prime do
- Complex(1).should be_an_instance_of(Complex)
- Complex(1).imag.should == 0
- Complex(1).real.should == 1
-
- Complex(-3).should be_an_instance_of(Complex)
- Complex(-3).imag.should == 0
- Complex(-3).real.should == -3
-
- Complex(-4.5).should be_an_instance_of(Complex)
- Complex(-4.5).imag.should == 0
- Complex(-4.5).real.should == -4.5
-
- Complex(bignum_value).should be_an_instance_of(Complex)
- Complex(bignum_value).imag.should == 0
- Complex(bignum_value).real.should == bignum_value
- end
- end
- end
-
- describe "when passed a String" do
- it "needs to be reviewed for spec completeness"
- end
-
- describe "when passed an Object which responds to #to_c" do
- it "returns the passed argument" do
- obj = Object.new; def obj.to_c; 1i end
- Complex(obj).should == Complex(0, 1)
- end
- end
-
- describe "when passed a Numeric which responds to #real? with false" do
- it "returns the passed argument" do
- n = mock_numeric("unreal")
- n.should_receive(:real?).any_number_of_times.and_return(false)
- Complex(n).should equal(n)
- end
- end
-
- describe "when passed a Numeric which responds to #real? with true" do
- it "returns a Complex with the passed argument as the real component and 0 as the imaginary component" do
- n = mock_numeric("real")
- n.should_receive(:real?).any_number_of_times.and_return(true)
- result = Complex(n)
- result.real.should equal(n)
- result.imag.should equal(0)
- end
- end
-
- describe "when 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 "returns n1 + n2 * Complex(0, 1)" do
- n1 = mock_numeric("n1")
- n2 = mock_numeric("n2")
- n3 = mock_numeric("n3")
- n4 = mock_numeric("n4")
- n1.should_receive(:real?).any_number_of_times.and_return(r1)
- n2.should_receive(:real?).any_number_of_times.and_return(r2)
- n2.should_receive(:*).with(Complex(0, 1)).and_return(n3)
- n1.should_receive(:+).with(n3).and_return(n4)
- Complex(n1, n2).should equal(n4)
- end
- end
- end
-
- describe "when passed two Numerics and both respond to #real? with true" do
- it "returns a Complex with the passed arguments as real and imaginary components respectively" 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(n1, n2)
- result.real.should equal(n1)
- result.imag.should equal(n2)
- end
- end
-
- describe "when passed a single non-Numeric" do
- it "coerces the passed argument using #to_c" do
- n = mock("n")
- c = Complex(0, 0)
- n.should_receive(:to_c).and_return(c)
- Complex(n).should equal(c)
- end
- end
-
- describe "when passed a non-Numeric second argument" do
- it "raises TypeError" do
- lambda { Complex.send(@method, :sym, :sym) }.should raise_error(TypeError)
- lambda { Complex.send(@method, 0, :sym) }.should raise_error(TypeError)
- end
- end
-
- describe "when passed nil" do
- it "raises TypeError" do
- lambda { Complex(nil) }.should raise_error(TypeError, "can't convert nil into Complex")
- lambda { Complex(0, nil) }.should raise_error(TypeError, "can't convert nil into Complex")
- lambda { Complex(nil, 0) }.should raise_error(TypeError, "can't convert nil into Complex")
- end
- end
-end
diff --git a/spec/ruby/shared/complex/abs.rb b/spec/ruby/shared/complex/abs.rb
deleted file mode 100644
index 2b51c416c2..0000000000
--- a/spec/ruby/shared/complex/abs.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require_relative '../../spec_helper'
-
-describe :complex_abs, shared: true do
- it "returns the modulus: |a + bi| = sqrt((a ^ 2) + (b ^ 2))" do
- Complex(0, 0).send(@method).should == 0
- Complex(3, 4).send(@method).should == 5 # well-known integer case
- Complex(-3, 4).send(@method).should == 5
- Complex(1, -1).send(@method).should be_close(Math.sqrt(2), TOLERANCE)
- Complex(6.5, 0).send(@method).should be_close(6.5, TOLERANCE)
- Complex(0, -7.2).send(@method).should be_close(7.2, TOLERANCE)
- end
-end
diff --git a/spec/ruby/shared/complex/abs2.rb b/spec/ruby/shared/complex/abs2.rb
deleted file mode 100644
index a39530d4e2..0000000000
--- a/spec/ruby/shared/complex/abs2.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require_relative '../../spec_helper'
-
-describe :complex_abs2, shared: true do
- 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)
- # Guard against Mathn library
- conflicts_with :Prime do
- Complex(0).abs2.should == 0
- end
- end
-end
diff --git a/spec/ruby/shared/complex/arg.rb b/spec/ruby/shared/complex/arg.rb
deleted file mode 100644
index c81f197433..0000000000
--- a/spec/ruby/shared/complex/arg.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-describe :complex_arg, shared: true do
- it "returns the argument -- i.e., the angle from (1, 0) in the complex plane" do
- two_pi = 2 * Math::PI
- (Complex(1, 0).send(@method) % two_pi).should be_close(0, TOLERANCE)
- (Complex(0, 2).send(@method) % two_pi).should be_close(Math::PI * 0.5, TOLERANCE)
- (Complex(-100, 0).send(@method) % two_pi).should be_close(Math::PI, TOLERANCE)
- (Complex(0, -75.3).send(@method) % two_pi).should be_close(Math::PI * 1.5, TOLERANCE)
- end
-end
diff --git a/spec/ruby/shared/complex/coerce.rb b/spec/ruby/shared/complex/coerce.rb
deleted file mode 100644
index 2bb08cf5a2..0000000000
--- a/spec/ruby/shared/complex/coerce.rb
+++ /dev/null
@@ -1,70 +0,0 @@
-require_relative '../../spec_helper'
-
-describe :complex_coerce, shared: true do
- 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
diff --git a/spec/ruby/shared/complex/conjugate.rb b/spec/ruby/shared/complex/conjugate.rb
deleted file mode 100644
index d1ae47bcb6..0000000000
--- a/spec/ruby/shared/complex/conjugate.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-describe :complex_conjugate, shared: true do
- it "returns the complex conjugate: conj a + bi = a - bi" do
- Complex(3, 5).send(@method).should == Complex(3, -5)
- Complex(3, -5).send(@method).should == Complex(3, 5)
- Complex(-3.0, 5.2).send(@method).should be_close(Complex(-3.0, -5.2), TOLERANCE)
- Complex(3.0, -5.2).send(@method).should be_close(Complex(3.0, 5.2), TOLERANCE)
- end
-end
diff --git a/spec/ruby/shared/complex/constants.rb b/spec/ruby/shared/complex/constants.rb
deleted file mode 100644
index a181fd9e30..0000000000
--- a/spec/ruby/shared/complex/constants.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-require_relative '../../spec_helper'
-
-describe :complex_I, shared: true do
- it "is Complex(0, 1)" do
- Complex::I.should eql(Complex(0, 1))
- end
-end
diff --git a/spec/ruby/shared/complex/denominator.rb b/spec/ruby/shared/complex/denominator.rb
deleted file mode 100644
index aee309cb11..0000000000
--- a/spec/ruby/shared/complex/denominator.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-require_relative '../../spec_helper'
-
-describe :complex_denominator, shared: true do
- it "returns the least common multiple denominator of the real and imaginary parts" do
- Complex(3, 4).denominator.should == 1
- Complex(3, bignum_value).denominator.should == 1
-
- Complex(3, Rational(3,4)).denominator.should == 4
-
- Complex(Rational(4,8), Rational(3,4)).denominator.should == 4
- Complex(Rational(3,8), Rational(3,4)).denominator.should == 8
- end
-end
diff --git a/spec/ruby/shared/complex/divide.rb b/spec/ruby/shared/complex/divide.rb
deleted file mode 100644
index 90143c6ef0..0000000000
--- a/spec/ruby/shared/complex/divide.rb
+++ /dev/null
@@ -1,84 +0,0 @@
-require_relative '../../spec_helper'
-
-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
diff --git a/spec/ruby/shared/complex/equal_value.rb b/spec/ruby/shared/complex/equal_value.rb
deleted file mode 100644
index 9f341d956f..0000000000
--- a/spec/ruby/shared/complex/equal_value.rb
+++ /dev/null
@@ -1,93 +0,0 @@
-require_relative '../../spec_helper'
-
-describe :complex_equal_value, shared: true do
- describe "with Complex" do
- it "returns true when self and other have numerical equality" do
- Complex(1, 2).should == Complex(1, 2)
- Complex(3, 9).should == Complex(3, 9)
- Complex(-3, -9).should == Complex(-3, -9)
-
- Complex(1, 2).should_not == Complex(3, 4)
- Complex(3, 9).should_not == Complex(9, 3)
-
- Complex(1.0, 2.0).should == Complex(1, 2)
- Complex(3.0, 9.0).should_not == Complex(9.0, 3.0)
-
- Complex(1.5, 2.5).should == Complex(1.5, 2.5)
- Complex(1.5, 2.5).should == Complex(1.5, 2.5)
- Complex(-1.5, 2.5).should == Complex(-1.5, 2.5)
-
- Complex(1.5, 2.5).should_not == Complex(2.5, 1.5)
- Complex(3.75, 2.5).should_not == Complex(1.5, 2.5)
-
- Complex(bignum_value, 2.5).should == Complex(bignum_value, 2.5)
- Complex(3.75, bignum_value).should_not == Complex(1.5, bignum_value)
-
- Complex(nan_value).should_not == Complex(nan_value)
- end
- end
-
- describe "with Numeric" do
- it "returns true when self's imaginary part is 0 and the real part and other have numerical equality" do
- Complex(3, 0).should == 3
- Complex(-3, 0).should == -3
-
- Complex(3.5, 0).should == 3.5
- Complex(-3.5, 0).should == -3.5
-
- Complex(bignum_value, 0).should == bignum_value
- Complex(-bignum_value, 0).should == -bignum_value
-
- Complex(3.0, 0).should == 3
- Complex(-3.0, 0).should == -3
-
- Complex(3, 0).should_not == 4
- Complex(-3, 0).should_not == -4
-
- Complex(3.5, 0).should_not == -4.5
- Complex(-3.5, 0).should_not == 2.5
-
- Complex(bignum_value, 0).should_not == bignum_value(10)
- Complex(-bignum_value, 0).should_not == -bignum_value(20)
- end
- end
-
- describe "with Object" do
- # Fixnum#==, Float#== and Bignum#== only return booleans - Bug?
- it "calls other#== with self" do
- value = Complex(3, 0)
-
- obj = mock("Object")
- obj.should_receive(:==).with(value).and_return(:expected)
-
- (value == obj).should_not be_false
- end
- end
-
- describe "with a Numeric which responds to #real? with true" do
- before do
- @other = mock_numeric('other')
- @other.should_receive(:real?).any_number_of_times.and_return(true)
- end
-
- it "returns real == other when the imaginary part is zero" do
- real = mock_numeric('real')
- real.should_receive(:==).with(@other).and_return(true)
- (Complex(real, 0) == @other).should be_true
- end
-
- it "returns false when when the imaginary part is not zero" do
- (Complex(3, 1) == @other).should be_false
- end
- end
-
- describe "with a Numeric which responds to #real? with false" do
- it "returns other == self" do
- complex = Complex(3, 0)
- other = mock_numeric('other')
- other.should_receive(:real?).any_number_of_times.and_return(false)
- other.should_receive(:==).with(complex).and_return(true)
- (complex == other).should be_true
- end
- end
-end
diff --git a/spec/ruby/shared/complex/exponent.rb b/spec/ruby/shared/complex/exponent.rb
deleted file mode 100644
index 650bb6d0f9..0000000000
--- a/spec/ruby/shared/complex/exponent.rb
+++ /dev/null
@@ -1,61 +0,0 @@
-require_relative '../../spec_helper'
-
-describe :complex_exponent, shared: true do
- describe "with Fixnum 0" do
- it "returns Complex(1)" do
- (Complex(3, 4) ** 0).should eql(Complex(1))
- end
- end
-
- describe "with Float 0.0" do
- it "returns Complex(1.0, 0.0)" do
- (Complex(3, 4) ** 0.0).should eql(Complex(1.0, 0.0))
- end
- end
-
- describe "with Complex" do
- it "returns self raised to the given power" do
- (Complex(2, 1) ** Complex(2, 1)).should be_close(Complex(-0.504824688978319, 3.10414407699553), TOLERANCE)
- (Complex(2, 1) ** Complex(3, 4)).should be_close(Complex(-0.179174656916581, -1.74071656397662), TOLERANCE)
-
- (Complex(2, 1) ** Complex(-2, -1)).should be_close(Complex(-0.051041070450869, -0.313849223270419), TOLERANCE)
- (Complex(-2, -1) ** Complex(2, 1)).should be_close(Complex(-11.6819929610857, 71.8320439736158), TOLERANCE)
- end
- end
-
- describe "with Integer" do
- it "returns self raised to the given power" do
- (Complex(2, 1) ** 2).should == Complex(3, 4)
- (Complex(3, 4) ** 2).should == Complex(-7, 24)
- (Complex(3, 4) ** -2).should be_close(Complex(-0.0112, -0.0384), TOLERANCE)
-
-
- (Complex(2, 1) ** 2.5).should be_close(Complex(2.99179707178602, 6.85206901006896), TOLERANCE)
- (Complex(3, 4) ** 2.5).should be_close(Complex(-38.0, 41.0), TOLERANCE)
- (Complex(3, 4) ** -2.5).should be_close(Complex(-0.01216, -0.01312), TOLERANCE)
-
- (Complex(1) ** 1).should == Complex(1)
-
- # NOTE: Takes way too long...
- #(Complex(2, 1) ** bignum_value)
- end
- end
-
- describe "with Rational" do
- it "returns self raised to the given power" do
- (Complex(2, 1) ** Rational(3, 4)).should be_close(Complex(1.71913265276568, 0.623124744394697), TOLERANCE)
- (Complex(2, 1) ** Rational(4, 3)).should be_close(Complex(2.3828547125173, 1.69466313833091), TOLERANCE)
- (Complex(2, 1) ** Rational(-4, 3)).should be_close(Complex(0.278700377879388, -0.198209003071003), TOLERANCE)
- 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
-end
diff --git a/spec/ruby/shared/complex/float/arg.rb b/spec/ruby/shared/complex/float/arg.rb
deleted file mode 100644
index a18d3b3e02..0000000000
--- a/spec/ruby/shared/complex/float/arg.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-require_relative '../../../spec_helper'
-
-describe :float_arg, shared: true do
- it "returns NaN if NaN" do
- f = nan_value
- f.send(@method).nan?.should be_true
- end
-
- it "returns self if NaN" do
- f = nan_value
- f.send(@method).should equal(f)
- end
-
- it "returns 0 if positive" do
- 1.0.send(@method).should == 0
- end
-
- it "returns 0 if +0.0" do
- 0.0.send(@method).should == 0
- end
-
- it "returns 0 if +Infinity" do
- infinity_value.send(@method).should == 0
- end
-
- it "returns Pi if negative" do
- (-1.0).send(@method).should == Math::PI
- end
-
- # This was established in r23960
- it "returns Pi if -0.0" do
- (-0.0).send(@method).should == Math::PI
- end
-
- it "returns Pi if -Infinity" do
- (-infinity_value).send(@method).should == Math::PI
- end
-end
diff --git a/spec/ruby/shared/complex/image.rb b/spec/ruby/shared/complex/image.rb
deleted file mode 100644
index f214b102f9..0000000000
--- a/spec/ruby/shared/complex/image.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-require_relative '../../spec_helper'
-
-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
diff --git a/spec/ruby/shared/complex/inspect.rb b/spec/ruby/shared/complex/inspect.rb
deleted file mode 100644
index 7c0c3d6b9c..0000000000
--- a/spec/ruby/shared/complex/inspect.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-describe :complex_inspect, shared: true do
- it "returns (${real}+${image}i) for positive imaginary parts" do
- Complex(1).inspect.should == "(1+0i)"
- Complex(7).inspect.should == "(7+0i)"
- Complex(-1, 4).inspect.should == "(-1+4i)"
- Complex(-7, 6.7).inspect.should == "(-7+6.7i)"
- end
-
- it "returns (${real}-${image}i) for negative imaginary parts" do
- Complex(0, -1).inspect.should == "(0-1i)"
- Complex(-1, -4).inspect.should == "(-1-4i)"
- Complex(-7, -6.7).inspect.should == "(-7-6.7i)"
- end
-end
diff --git a/spec/ruby/shared/complex/minus.rb b/spec/ruby/shared/complex/minus.rb
deleted file mode 100644
index af6c368581..0000000000
--- a/spec/ruby/shared/complex/minus.rb
+++ /dev/null
@@ -1,45 +0,0 @@
-require_relative '../../spec_helper'
-
-describe :complex_minus, shared: true do
- describe "with Complex" do
- it "subtracts both the real and imaginary components" do
- (Complex(1, 2) - Complex(10, 20)).should == Complex(1 - 10, 2 - 20)
- (Complex(1.5, 2.1) - Complex(100.2, -30.3)).should == Complex(1.5 - 100.2, 2.1 - (-30.3))
- end
- end
-
- describe "with Integer" do
- it "subtracts the real number from the real component of self" do
- (Complex(1, 2) - 50).should == Complex(-49, 2)
- (Complex(1, 2) - 50.5).should == Complex(-49.5, 2)
- 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 "passed Numeric which responds to #real? with true" do
- it "coerces the passed argument to the type of the real part and subtracts the resulting elements" do
- n = mock_numeric('n')
- n.should_receive(:real?).and_return(true)
- n.should_receive(:coerce).with(1).and_return([1, 4])
- (Complex(1, 2) - n).should == Complex(-3, 2)
- end
- end
-
- describe "passed Numeric which responds to #real? with false" do
- it "coerces the passed argument to Complex and subtracts the resulting elements" do
- n = mock_numeric('n')
- n.should_receive(:real?).and_return(false)
- n.should_receive(:coerce).with(Complex(1, 2)).and_return([Complex(1, 2), Complex(3, 4)])
- (Complex(1, 2) - n).should == Complex(-2, -2)
- end
- end
-end
diff --git a/spec/ruby/shared/complex/multiply.rb b/spec/ruby/shared/complex/multiply.rb
deleted file mode 100644
index 0b711c2c80..0000000000
--- a/spec/ruby/shared/complex/multiply.rb
+++ /dev/null
@@ -1,49 +0,0 @@
-require_relative '../../spec_helper'
-
-describe :complex_multiply, shared: true do
- 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
diff --git a/spec/ruby/shared/complex/numerator.rb b/spec/ruby/shared/complex/numerator.rb
deleted file mode 100644
index 5113d2ac8b..0000000000
--- a/spec/ruby/shared/complex/numerator.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-require_relative '../../spec_helper'
-
-describe :complex_numerator, shared: true do
- 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
diff --git a/spec/ruby/shared/complex/numeric/arg.rb b/spec/ruby/shared/complex/numeric/arg.rb
deleted file mode 100644
index c8e7ad8333..0000000000
--- a/spec/ruby/shared/complex/numeric/arg.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-require_relative '../../../spec_helper'
-
-describe :numeric_arg, shared: true do
- before :each do
- @numbers = [
- 20,
- Rational(3, 4),
- bignum_value,
- infinity_value
- ]
- end
-
- it "returns 0 if positive" do
- @numbers.each do |number|
- number.send(@method).should == 0
- end
- end
-
- it "returns Pi if negative" do
- @numbers.each do |number|
- (0-number).send(@method).should == Math::PI
- end
- end
-
- describe "with a Numeric subclass" do
- it "returns 0 if self#<(0) returns false" do
- numeric = mock_numeric('positive')
- numeric.should_receive(:<).with(0).and_return(false)
- numeric.send(@method).should == 0
- end
-
- it "returns Pi if self#<(0) returns true" do
- numeric = mock_numeric('positive')
- numeric.should_receive(:<).with(0).and_return(true)
- numeric.send(@method).should == Math::PI
- end
- end
-end
diff --git a/spec/ruby/shared/complex/numeric/conj.rb b/spec/ruby/shared/complex/numeric/conj.rb
deleted file mode 100644
index 6d5197ecab..0000000000
--- a/spec/ruby/shared/complex/numeric/conj.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-require_relative '../../../spec_helper'
-
-describe :numeric_conj, shared: true do
- before :each do
- @numbers = [
- 20, # Integer
- 398.72, # Float
- Rational(3, 4), # Rational
- bignum_value,
- infinity_value,
- nan_value
- ]
- end
-
- it "returns self" do
- @numbers.each do |number|
- number.send(@method).should equal(number)
- end
- end
-end
diff --git a/spec/ruby/shared/complex/numeric/imag.rb b/spec/ruby/shared/complex/numeric/imag.rb
deleted file mode 100644
index 11daf0af55..0000000000
--- a/spec/ruby/shared/complex/numeric/imag.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-require_relative '../../../spec_helper'
-
-describe :numeric_imag, shared: true do
- before :each do
- @numbers = [
- 20, # Integer
- 398.72, # Float
- Rational(3, 4), # Rational
- bignum_value, # Bignum
- infinity_value,
- nan_value
- ].map{|n| [n,-n]}.flatten
- end
-
- it "returns 0" do
- @numbers.each do |number|
- number.send(@method).should == 0
- 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
diff --git a/spec/ruby/shared/complex/numeric/polar.rb b/spec/ruby/shared/complex/numeric/polar.rb
deleted file mode 100644
index 74586c52ad..0000000000
--- a/spec/ruby/shared/complex/numeric/polar.rb
+++ /dev/null
@@ -1,50 +0,0 @@
-require_relative '../../../spec_helper'
-
-describe :numeric_polar, shared: true do
- before :each do
- @pos_numbers = [
- 1,
- 3898172610**9,
- 987.18273,
- Float::MAX,
- Rational(13,7),
- infinity_value,
- ]
- @neg_numbers = @pos_numbers.map {|n| -n}
- @numbers = @pos_numbers + @neg_numbers
- @numbers.push(0, 0.0)
- end
-
- it "returns a two-element Array" do
- @numbers.each do |number|
- number.polar.should be_an_instance_of(Array)
- number.polar.size.should == 2
- end
- end
-
- it "sets the first value to the absolute value of self" do
- @numbers.each do |number|
- number.polar.first.should == number.abs
- end
- end
-
- it "sets the last value to 0 if self is positive" do
- (@numbers - @neg_numbers).each do |number|
- number.should >= 0
- number.polar.last.should == 0
- end
- end
-
- it "sets the last value to Pi if self is negative" do
- @neg_numbers.each do |number|
- number.should < 0
- number.polar.last.should == Math::PI
- end
- end
-
- it "returns [NaN, NaN] if self is NaN" do
- nan_value.polar.size.should == 2
- nan_value.polar.first.nan?.should be_true
- nan_value.polar.last.nan?.should be_true
- end
-end
diff --git a/spec/ruby/shared/complex/numeric/real.rb b/spec/ruby/shared/complex/numeric/real.rb
deleted file mode 100644
index d00e3b41cf..0000000000
--- a/spec/ruby/shared/complex/numeric/real.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-require_relative '../../../spec_helper'
-
-describe :numeric_real, shared: true do
- before :each do
- @numbers = [
- 20, # Integer
- 398.72, # Float
- Rational(3, 4), # Rational
- bignum_value, # Bignum
- infinity_value,
- nan_value
- ].map{|n| [n,-n]}.flatten
- end
-
- it "returns self" do
- @numbers.each do |number|
- if number.to_f.nan?
- number.real.nan?.should be_true
- else
- number.real.should == number
- end
- end
- end
-
- it "raises an ArgumentError if given any arguments" do
- @numbers.each do |number|
- lambda { number.real(number) }.should raise_error(ArgumentError)
- end
- end
-end
diff --git a/spec/ruby/shared/complex/plus.rb b/spec/ruby/shared/complex/plus.rb
deleted file mode 100644
index d258720e61..0000000000
--- a/spec/ruby/shared/complex/plus.rb
+++ /dev/null
@@ -1,45 +0,0 @@
-require_relative '../../spec_helper'
-
-describe :complex_plus, shared: true do
- describe "with Complex" do
- it "adds both the real and imaginary components" do
- (Complex(1, 2) + Complex(10, 20)).should == Complex(1 + 10, 2 + 20)
- (Complex(1.5, 2.1) + Complex(100.2, -30.3)).should == Complex(1.5 + 100.2, 2.1 + (-30.3))
- end
- end
-
- describe "with Integer" do
- it "adds the real number to the real component of self" do
- (Complex(1, 2) + 50).should == Complex(51, 2)
- (Complex(1, 2) + 50.5).should == Complex(51.5, 2)
- 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 "passed Numeric which responds to #real? with true" do
- it "coerces the passed argument to the type of the real part and adds the resulting elements" do
- n = mock_numeric('n')
- n.should_receive(:real?).and_return(true)
- n.should_receive(:coerce).with(1).and_return([1, 4])
- (Complex(1, 2) + n).should == Complex(5, 2)
- end
- end
-
- describe "passed Numeric which responds to #real? with false" do
- it "coerces the passed argument to Complex and adds the resulting elements" do
- n = mock_numeric('n')
- n.should_receive(:real?).and_return(false)
- n.should_receive(:coerce).with(Complex(1, 2)).and_return([Complex(1, 2), Complex(3, 4)])
- (Complex(1, 2) + n).should == Complex(4, 6)
- end
- end
-end
diff --git a/spec/ruby/shared/complex/polar.rb b/spec/ruby/shared/complex/polar.rb
deleted file mode 100644
index 9703cd3ce7..0000000000
--- a/spec/ruby/shared/complex/polar.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-require_relative '../../spec_helper'
-
-describe :complex_polar_class, shared: true do
- it "returns a complex number in terms of radius and angle" do
- Complex.polar(50, 60).should be_close(Complex(-47.6206490207578, -15.2405310551108), TOLERANCE)
- Complex.polar(-10, -20).should be_close(Complex(-4.08082061813392, 9.12945250727628), TOLERANCE)
- end
-end
-
-describe :complex_polar, shared: true do
- it "returns the absolute value and the argument" do
- a = Complex(3, 4)
- a.polar.size.should == 2
- a.polar.first.should == 5.0
- a.polar.last.should be_close(0.927295218001612, TOLERANCE)
-
- b = Complex(-3.5, 4.7)
- b.polar.size.should == 2
- b.polar.first.should be_close(5.86003412959345, TOLERANCE)
- b.polar.last.should be_close(2.21088447955664, TOLERANCE)
- end
-end
diff --git a/spec/ruby/shared/complex/real.rb b/spec/ruby/shared/complex/real.rb
deleted file mode 100644
index ab8ed07a4d..0000000000
--- a/spec/ruby/shared/complex/real.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-describe :complex_real, shared: true do
- 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
diff --git a/spec/ruby/shared/complex/rect.rb b/spec/ruby/shared/complex/rect.rb
deleted file mode 100644
index cb4bd75b4a..0000000000
--- a/spec/ruby/shared/complex/rect.rb
+++ /dev/null
@@ -1,96 +0,0 @@
-require_relative '../../spec_helper'
-
-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
diff --git a/spec/ruby/shared/complex/to_s.rb b/spec/ruby/shared/complex/to_s.rb
deleted file mode 100644
index 6cc20bdafe..0000000000
--- a/spec/ruby/shared/complex/to_s.rb
+++ /dev/null
@@ -1,44 +0,0 @@
-require_relative '../../spec_helper'
-
-describe :complex_to_s, shared: true do
- 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
- conflicts_with :Prime 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
diff --git a/spec/ruby/shared/rational/Rational.rb b/spec/ruby/shared/rational/Rational.rb
index 68f0150186..752225269e 100644
--- a/spec/ruby/shared/rational/Rational.rb
+++ b/spec/ruby/shared/rational/Rational.rb
@@ -4,7 +4,7 @@ require_relative '../../fixtures/rational'
describe :kernel_Rational, shared: true do
describe "passed Integer" do
# Guard against the Mathn library
- conflicts_with :Prime do
+ guard -> { !defined?(Math.rsqrt) } do
it "returns a new Rational number with 1 as the denominator" do
Rational(1).should eql(Rational(1, 1))
Rational(-3).should eql(Rational(-3, 1))
diff --git a/spec/ruby/shared/rational/exponent.rb b/spec/ruby/shared/rational/exponent.rb
index f40f3c57d6..ac8237c291 100644
--- a/spec/ruby/shared/rational/exponent.rb
+++ b/spec/ruby/shared/rational/exponent.rb
@@ -2,7 +2,8 @@ require_relative '../../spec_helper'
describe :rational_exponent, shared: true do
describe "when passed Rational" do
- conflicts_with :Prime do
+ # Guard against the Mathn library
+ guard -> { !defined?(Math.rsqrt) } do
it "returns Rational(1) if the exponent is Rational(0)" do
(Rational(0) ** Rational(0)).should eql(Rational(1))
(Rational(1) ** Rational(0)).should eql(Rational(1))
@@ -45,7 +46,8 @@ describe :rational_exponent, shared: true do
(Rational(3, -bignum_value) ** -4).should == Rational(7237005577332262213973186563042994240829374041602535252466099000494570602496, 81)
end
- conflicts_with :Prime do
+ # Guard against the Mathn library
+ guard -> { !defined?(Math.rsqrt) } do
it "returns Rational(1, 1) when the passed argument is 0" do
(Rational(3, 4) ** 0).should eql(Rational(1, 1))
(Rational(-3, 4) ** 0).should eql(Rational(1, 1))
diff --git a/spec/ruby/shared/rational/inspect.rb b/spec/ruby/shared/rational/inspect.rb
index a7fd42ccac..19691a2f25 100644
--- a/spec/ruby/shared/rational/inspect.rb
+++ b/spec/ruby/shared/rational/inspect.rb
@@ -1,11 +1,13 @@
require_relative '../../spec_helper'
describe :rational_inspect, shared: true do
- conflicts_with :Prime do
- it "returns a string representation of self" do
- Rational(3, 4).inspect.should == "(3/4)"
- Rational(-5, 8).inspect.should == "(-5/8)"
- Rational(-1, -2).inspect.should == "(1/2)"
+ it "returns a string representation of self" do
+ Rational(3, 4).inspect.should == "(3/4)"
+ Rational(-5, 8).inspect.should == "(-5/8)"
+ Rational(-1, -2).inspect.should == "(1/2)"
+
+ # Guard against the Mathn library
+ guard -> { !defined?(Math.rsqrt) } do
Rational(bignum_value, 1).inspect.should == "(#{bignum_value}/1)"
end
end
diff --git a/spec/ruby/shared/rational/round.rb b/spec/ruby/shared/rational/round.rb
index a3f92413e7..36ed476350 100644
--- a/spec/ruby/shared/rational/round.rb
+++ b/spec/ruby/shared/rational/round.rb
@@ -47,8 +47,11 @@ describe :rational_round, shared: true do
it "returns a Rational" do
@rational.round(1).should be_kind_of(Rational)
@rational.round(2).should be_kind_of(Rational)
- Rational(0, 1).round(1).should be_kind_of(Rational)
- Rational(2, 1).round(1).should be_kind_of(Rational)
+ # Guard against the Mathn library
+ guard -> { !defined?(Math.rsqrt) } do
+ Rational(0, 1).round(1).should be_kind_of(Rational)
+ Rational(2, 1).round(1).should be_kind_of(Rational)
+ end
end
it "moves the truncation point n decimal places right" do
diff --git a/spec/ruby/shared/rational/to_r.rb b/spec/ruby/shared/rational/to_r.rb
index 9ae7571ffe..372c086850 100644
--- a/spec/ruby/shared/rational/to_r.rb
+++ b/spec/ruby/shared/rational/to_r.rb
@@ -1,13 +1,11 @@
require_relative '../../spec_helper'
describe :rational_to_r, shared: true do
- conflicts_with :Prime do
- it "returns self" do
- a = Rational(3, 4)
- a.to_r.should equal(a)
+ it "returns self" do
+ a = Rational(3, 4)
+ a.to_r.should equal(a)
- a = Rational(bignum_value, 4)
- a.to_r.should equal(a)
- end
+ a = Rational(bignum_value, 4)
+ a.to_r.should equal(a)
end
end
diff --git a/spec/ruby/shared/rational/to_s.rb b/spec/ruby/shared/rational/to_s.rb
index b16594f10c..e90c6e5e39 100644
--- a/spec/ruby/shared/rational/to_s.rb
+++ b/spec/ruby/shared/rational/to_s.rb
@@ -2,8 +2,11 @@ require_relative '../../spec_helper'
describe :rational_to_s, shared: true do
it "returns a string representation of self" do
- Rational(1, 1).to_s.should == "1/1"
- Rational(2, 1).to_s.should == "2/1"
+ # Guard against the Mathn library
+ guard -> { !defined?(Math.rsqrt) } do
+ Rational(1, 1).to_s.should == "1/1"
+ Rational(2, 1).to_s.should == "2/1"
+ end
Rational(1, 2).to_s.should == "1/2"
Rational(-1, 3).to_s.should == "-1/3"
Rational(1, -3).to_s.should == "-1/3"