diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-09-20 20:18:52 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-09-20 20:18:52 +0000 |
commit | 1d15d5f08032acf1b7bceacbb450d617ff6e0931 (patch) | |
tree | a3785a79899302bc149e4a6e72f624ac27dc1f10 /spec/ruby/core/complex/fdiv_spec.rb | |
parent | 75bfc6440d595bf339007f4fb280fd4d743e89c1 (diff) | |
download | ruby-1d15d5f08032acf1b7bceacbb450d617ff6e0931.tar.gz |
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
Diffstat (limited to 'spec/ruby/core/complex/fdiv_spec.rb')
-rw-r--r-- | spec/ruby/core/complex/fdiv_spec.rb | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/spec/ruby/core/complex/fdiv_spec.rb b/spec/ruby/core/complex/fdiv_spec.rb new file mode 100644 index 0000000000..8211dfc9de --- /dev/null +++ b/spec/ruby/core/complex/fdiv_spec.rb @@ -0,0 +1,129 @@ +require File.expand_path('../../../spec_helper', __FILE__) + +describe "Complex#fdiv" do + it "accepts a numeric argument" do + lambda { Complex(20).fdiv(2) }.should_not raise_error(TypeError) + lambda { Complex(20).fdiv(2.0) }.should_not raise_error(TypeError) + lambda { Complex(20).fdiv(bignum_value) }.should_not raise_error(TypeError) + end + + it "accepts a negative numeric argument" do + lambda { Complex(20).fdiv(-2) }.should_not raise_error(TypeError) + lambda { Complex(20).fdiv(-2.0) }.should_not raise_error(TypeError) + lambda { Complex(20).fdiv(-bignum_value) }.should_not raise_error(TypeError) + end + + it "raises a TypeError if passed a non-numeric argument" do + lambda { Complex(20).fdiv([]) }.should raise_error(TypeError) + lambda { Complex(20).fdiv(:sym) }.should raise_error(TypeError) + lambda { Complex(20).fdiv('s') }.should raise_error(TypeError) + end + + it "sets the real part to NaN if self's real part is NaN" do + Complex(nan_value).fdiv(2).real.nan?.should be_true + end + + it "sets the imaginary part to NaN if self's imaginary part is NaN" do + Complex(2, nan_value).fdiv(2).imag.nan?.should be_true + end + + it "sets the real and imaginary part to NaN if self's real and imaginary parts are NaN" do + Complex(nan_value, nan_value).fdiv(2).imag.nan?.should be_true + Complex(nan_value, nan_value).fdiv(2).real.nan?.should be_true + end + + it "sets the real and imaginary part to NaN if self's real part and the argument are both NaN" do + Complex(nan_value, 2).fdiv(nan_value).imag.nan?.should be_true + Complex(nan_value, 2).fdiv(nan_value).real.nan?.should be_true + end + + it "sets the real and imaginary part to NaN if self's real part, self's imaginary part, and the argument are NaN" do + Complex(nan_value, nan_value).fdiv(nan_value).imag.nan?.should be_true + Complex(nan_value, nan_value).fdiv(nan_value).real.nan?.should be_true + end + + it "sets the real part to Infinity if self's real part is Infinity" do + Complex(infinity_value).fdiv(2).real.infinite?.should == 1 + Complex(infinity_value,2).fdiv(2).real.infinite?.should == 1 + end + + it "sets the imaginary part to Infinity if self's imaginary part is Infinity" do + Complex(2, infinity_value).fdiv(2).imag.infinite?.should == 1 + Complex(2, infinity_value).fdiv(2).imag.infinite?.should == 1 + end + + it "sets the imaginary and real part to Infinity if self's imaginary and real parts are Infinity" do + Complex(infinity_value, infinity_value).fdiv(2).real.infinite?.should == 1 + Complex(infinity_value, infinity_value).fdiv(2).imag.infinite?.should == 1 + end + + it "sets the real part to NaN and the imaginary part to NaN if self's imaginary part, self's real part, and the argument are Infinity" do + Complex(infinity_value, infinity_value).fdiv(infinity_value).real.nan?.should be_true + Complex(infinity_value, infinity_value).fdiv(infinity_value).imag.nan?.should be_true + end +end + +describe "Complex#fdiv with no imaginary part" do + before :each do + @numbers = [1, 5.43, 10, bignum_value, 99872.2918710].map{|n| [n,-n]}.flatten + end + + it "returns a Complex number" do + @numbers.each do |real| + @numbers.each do |other| + Complex(real).fdiv(other).should be_an_instance_of(Complex) + end + end + end + + it "sets the real part to self's real part fdiv'd with the argument" do + @numbers.each do |real| + @numbers.each do |other| + Complex(real).fdiv(other).real.should == real.fdiv(other) + end + end + end + + it "sets the imaginary part to 0.0" do + @numbers.each do |real| + @numbers.each do |other| + Complex(real).fdiv(other).imaginary.should == 0.0 + end + end + end +end + +describe "Complex#fdiv with an imaginary part" do + before :each do + @numbers = [1, 5.43, 10, bignum_value, 99872.2918710].map{|n| [n,-n]}.flatten + end + + it "returns a Complex number" do + @numbers.each do |real| + @numbers.each_with_index do |other,idx| + Complex( + real,@numbers[idx == 0 ? -1 : idx-1] + ).fdiv(other).should be_an_instance_of(Complex) + end + end + end + + it "sets the real part to self's real part fdiv'd with the argument" do + @numbers.each do |real| + @numbers.each_with_index do |other,idx| + Complex( + real,@numbers[idx == 0 ? -1 : idx-1] + ).fdiv(other).real.should == real.fdiv(other) + end + end + end + + it "sets the imaginary part to the imaginary part fdiv'd with the argument" do + @numbers.each do |real| + @numbers.each_with_index do |other,idx| + im = @numbers[idx == 0 ? -1 : idx-1] + Complex(real, im).fdiv(other).imag.should == im.fdiv(other) + end + end + end +end |