Updated RubySpec source to 55122684.
[rbx.git] / spec / frozen / 1.8 / library / mathn / rational / power2_spec.rb
blob2186e96a01a42b2f9eaa80954cf3646e74f769fc
1 require File.dirname(__FILE__) + '/../../../spec_helper'
2 require 'mathn'
4 describe "Rational#power2 when passed [Rational]" do
5   ruby_bug "#175", "1.8.7" do
6     it "returns Rational.new!(1, 1) when the passed argument is 0" do
7       (Rational.new!(3, 4).power2(Rational.new!(0, 3))).should == Rational.new!(1, 1)
8       (Rational.new!(-3, 4).power2(Rational.new!(0, 3))).should == Rational.new!(1, 1)
9       (Rational.new!(3, -4).power2(Rational.new!(0, 3))).should == Rational.new!(1, 1)
10       (Rational.new!(3, 4).power2(Rational.new!(0, -3))).should == Rational.new!(1, 1)
11     end
12   end
14   it "returns Rational.new!(1, 1) when self is 1" do
15     (Rational.new!(1,1).power2(Rational.new!(2, 3))).should == Rational.new!(1, 1)
16     (Rational.new!(1,1).power2(Rational.new!(-2, 3))).should == Rational.new!(1, 1)
17     (Rational.new!(1,1).power2(Rational.new!(2, -3))).should == Rational.new!(1, 1)
18     (Rational.new!(1,1).power2(Rational.new!(-2, -3))).should == Rational.new!(1, 1)
19   end
21   it "returns Rational.new!(0, 1) when self is 0" do
22     (Rational.new!(0,1).power2(Rational.new!(2, 3))).should == Rational.new!(0, 1)
23     (Rational.new!(0,1).power2(Rational.new!(-2, 3))).should == Rational.new!(0, 1)
24     (Rational.new!(0,1).power2(Rational.new!(2, -3))).should == Rational.new!(0, 1)
25     (Rational.new!(0,1).power2(Rational.new!(-2, -3))).should == Rational.new!(0, 1)
26   end
28   ruby_bug "#175", "1.8.7" do
29     it "returns the Rational value of self raised to the passed argument" do
30       (Rational.new!(1, 4).power2(Rational.new!(1, 2))).should == Rational.new!(1, 2)
31       (Rational.new!(1, 4).power2(Rational.new!(1, -2))).should == Rational.new!(2, 1)
32     end
33   end
35   it "returns a Complex number when self is negative" do
36     (Rational.new!(-1,2).power2(Rational.new!(2, 3))).should be_close(Complex(-0.314980262473718, 0.545561817985861), TOLERANCE)
37     (Rational.new!(-1,2).power2(Rational.new!(-2, 3))).should be_close(Complex(-0.793700525984099, -1.3747296369986), TOLERANCE)
38     (Rational.new!(-1,2).power2(Rational.new!(2, -3))).should be_close(Complex(-0.793700525984099, -1.3747296369986), TOLERANCE)
39   end
40 end
42 describe "Rational#power2 when passed [Integer]" do
43   it "returns the Rational value of self raised to the passed argument" do
44     (Rational.new!(3, 4).power2(4)).should == Rational.new!(81, 256)
45     (Rational.new!(3, 4).power2(-4)).should == Rational.new!(256, 81)
46     (Rational.new!(-3, 4).power2(-4)).should == Rational.new!(256, 81)
47     (Rational.new!(3, -4).power2(-4)).should == Rational.new!(256, 81)
48   end
49   
50   it "returns Rational.new!(1, 1) when the passed argument is 0" do
51     (Rational.new!(3, 4).power2(0)).should == Rational.new!(1, 1)
52     (Rational.new!(-3, 4).power2(0)).should == Rational.new!(1, 1)
53     (Rational.new!(3, -4).power2(0)).should == Rational.new!(1, 1)
55     (Rational.new!(bignum_value, 100).power2(0)).should == Rational.new!(1, 1)
56     (Rational.new!(3, -bignum_value).power2(0)).should == Rational.new!(1, 1)
57   end
58 end
60 describe "Rational#power2 when passed [Float]" do
61   it "returns self converted to Float and raised to the passed argument" do
62     (Rational.new!(3, 2).power2(3.0)).should == 3.375
63     (Rational.new!(3, 2).power2(1.5)).should be_close(1.83711730708738, TOLERANCE)
64     (Rational.new!(3, 2).power2(-1.5)).should be_close(0.544331053951817, TOLERANCE)
65   end
66   
67   it "returns 1.0 when the passed argument is 0" do
68     (Rational.new!(3, 4).power2(0.0)).should == 1.0
69     (Rational.new!(-3, 4).power2(0.0)).should == 1.0
70     (Rational.new!(-3, 4).power2(0.0)).should == 1.0
71   end
72   
73   it "returns NaN if self is negative and the passed argument is not 0" do
74     (Rational.new!(-3, 2).power2(1.5)).nan?.should be_true
75     (Rational.new!(3, -2).power2(1.5)).nan?.should be_true
76     (Rational.new!(3, -2).power2(-1.5)).nan?.should be_true
77   end
78 end