diff options
Diffstat (limited to 'spec/ruby/core/numeric/polar_spec.rb')
-rw-r--r-- | spec/ruby/core/numeric/polar_spec.rb | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/spec/ruby/core/numeric/polar_spec.rb b/spec/ruby/core/numeric/polar_spec.rb index b5aec52eec..b594e408b2 100644 --- a/spec/ruby/core/numeric/polar_spec.rb +++ b/spec/ruby/core/numeric/polar_spec.rb @@ -1,6 +1,50 @@ require_relative '../../spec_helper' -require_relative '../../shared/complex/numeric/polar' describe "Numeric#polar" do - it_behaves_like :numeric_polar, :polar + 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 |