1 require File.dirname(__FILE__) + '/../../../spec_helper'
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)
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)
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)
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)
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)
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)
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)
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)
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
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