Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions library/bigdecimal/case_compare_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
require_relative '../../spec_helper'
require_relative 'shared/eql'
require 'bigdecimal'


describe "BigDecimal#===" do
it_behaves_like :bigdecimal_eql, :===
it "is an alias of Bigdecimal#==" do
BigDecimal.instance_method(:===).should == BigDecimal.instance_method(:==)
end
end
6 changes: 4 additions & 2 deletions library/bigdecimal/clone_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require_relative '../../spec_helper'
require_relative 'shared/clone'
require 'bigdecimal'

describe "BigDecimal#dup" do
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
describe "BigDecimal#dup" do
describe "BigDecimal#clone" do

it_behaves_like :bigdecimal_clone, :clone
it "is an alias of BigDecimal#clone" do
BigDecimal.instance_method(:dup).should == BigDecimal.instance_method(:clone)
Comment on lines +5 to +6
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it "is an alias of BigDecimal#clone" do
BigDecimal.instance_method(:dup).should == BigDecimal.instance_method(:clone)
it "is an alias of BigDecimal#dup" do
BigDecimal.instance_method(:clone).should == BigDecimal.instance_method(:dup)

end
end
Comment on lines 4 to 8
12 changes: 10 additions & 2 deletions library/bigdecimal/dup_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
require_relative '../../spec_helper'
require_relative 'shared/clone'
require 'bigdecimal'

describe "BigDecimal#dup" do
it_behaves_like :bigdecimal_clone, :dup
before :each do
@obj = BigDecimal("1.2345")
end

it "returns self" do
copy = @obj.dup

copy.should.equal?(@obj)
end
end
6 changes: 4 additions & 2 deletions library/bigdecimal/eql_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require_relative '../../spec_helper'
require_relative 'shared/eql'
require 'bigdecimal'

describe "BigDecimal#eql?" do
it_behaves_like :bigdecimal_eql, :eql?
it "is an alias of Bigdecimal#==" do
BigDecimal.instance_method(:eql?).should == BigDecimal.instance_method(:==)
end
end
60 changes: 58 additions & 2 deletions library/bigdecimal/equal_value_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,63 @@
require_relative '../../spec_helper'
require_relative 'shared/eql'
require 'bigdecimal'


describe "BigDecimal#==" do
it_behaves_like :bigdecimal_eql, :==
before :each do
@bg6543_21 = BigDecimal("6543.21")
@bg5667_19 = BigDecimal("5667.19")
@a = BigDecimal("1.0000000000000000000000000000000000000000005")
@b = BigDecimal("1.00000000000000000000000000000000000000000005")
@bigint = BigDecimal("1000.0")
@nan = BigDecimal("NaN")
@infinity = BigDecimal("Infinity")
@infinity_minus = BigDecimal("-Infinity")
end

it "tests for equality" do
(@bg6543_21 == @bg6543_21).should == true
(@a == @a).should == true
(@a == @b).should == false
(@bg6543_21 == @a).should == false
(@bigint == 1000).should == true
end

it "returns false for NaN as it is never equal to any number" do
(@nan == @nan).should == false
(@a == @nan).should == false
(@nan == @a).should == false
(@nan == @infinity).should == false
(@nan == @infinity_minus).should == false
(@infinity == @nan).should == false
(@infinity_minus == @nan).should == false
end

it "returns true for infinity values with the same sign" do
(@infinity == @infinity).should == true
(@infinity == BigDecimal("Infinity")).should == true
(BigDecimal("Infinity") == @infinity).should == true

(@infinity_minus == @infinity_minus).should == true
(@infinity_minus == BigDecimal("-Infinity")).should == true
(BigDecimal("-Infinity") == @infinity_minus).should == true
end

it "returns false for infinity values with different signs" do
(@infinity == @infinity_minus).should == false
(@infinity_minus == @infinity).should == false
end

it "returns false when infinite value compared to finite one" do
(@infinity == @a).should == false
(@infinity_minus == @a).should == false

(@a == @infinity).should == false
(@a == @infinity_minus).should == false
end

it "returns false when compared objects that can not be coerced into BigDecimal" do
(@infinity == nil).should == false
(@bigint == nil).should == false
(@nan == nil).should == false
end
end
15 changes: 12 additions & 3 deletions library/bigdecimal/modulo_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
require_relative '../../spec_helper'
require_relative 'shared/modulo'
require 'bigdecimal'

describe "BigDecimal#%" do
it_behaves_like :bigdecimal_modulo, :%
it_behaves_like :bigdecimal_modulo_zerodivisionerror, :%

it "raises ZeroDivisionError if other is zero" do
bd5667 = BigDecimal("5667.19")

-> { bd5667 % 0 }.should.raise(ZeroDivisionError)
-> { bd5667 % BigDecimal("0") }.should.raise(ZeroDivisionError)
-> { @zero % @zero }.should.raise(ZeroDivisionError)
end
end

describe "BigDecimal#modulo" do
it_behaves_like :bigdecimal_modulo, :modulo
it_behaves_like :bigdecimal_modulo_zerodivisionerror, :modulo
it "is an alias of Bigdecimal#%" do
BigDecimal.instance_method(:modulo).should == BigDecimal.instance_method(:%)
end
end
13 changes: 0 additions & 13 deletions library/bigdecimal/shared/clone.rb

This file was deleted.

61 changes: 0 additions & 61 deletions library/bigdecimal/shared/eql.rb

This file was deleted.

10 changes: 0 additions & 10 deletions library/bigdecimal/shared/modulo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,3 @@
}.should.raise(TypeError)
end
end

describe :bigdecimal_modulo_zerodivisionerror, shared: true do
it "raises ZeroDivisionError if other is zero" do
bd5667 = BigDecimal("5667.19")

-> { bd5667.send(@method, 0) }.should.raise(ZeroDivisionError)
-> { bd5667.send(@method, BigDecimal("0")) }.should.raise(ZeroDivisionError)
-> { @zero.send(@method, @zero) }.should.raise(ZeroDivisionError)
end
end
16 changes: 0 additions & 16 deletions library/bigdecimal/shared/to_int.rb

This file was deleted.

14 changes: 12 additions & 2 deletions library/bigdecimal/to_i_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
require_relative '../../spec_helper'
require_relative 'shared/to_int'
require 'bigdecimal'

describe "BigDecimal#to_i" do
it_behaves_like :bigdecimal_to_int, :to_i
it "raises FloatDomainError if BigDecimal is infinity or NaN" do
-> { BigDecimal("Infinity").to_i }.should.raise(FloatDomainError)
-> { BigDecimal("NaN").to_i }.should.raise(FloatDomainError)
end

it "returns Integer otherwise" do
BigDecimal("3E-20001").to_i.should == 0
BigDecimal("2E4000").to_i.should == 2 * 10 ** 4000
BigDecimal("2").to_i.should == 2
BigDecimal("2E10").to_i.should == 20000000000
BigDecimal("3.14159").to_i.should == 3
end
end
6 changes: 3 additions & 3 deletions library/bigdecimal/to_int_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require_relative '../../spec_helper'
require_relative 'shared/to_int'
require 'bigdecimal'


describe "BigDecimal#to_int" do
it_behaves_like :bigdecimal_to_int, :to_int
it "is an alias of Bigdecimal#to_i" do
BigDecimal.instance_method(:to_int).should == BigDecimal.instance_method(:to_i)
end
end
46 changes: 39 additions & 7 deletions library/date/commercial_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
require 'date'
require_relative '../../spec_helper'
require_relative 'shared/commercial'

describe "Date#commercial" do

it_behaves_like :date_commercial, :commercial

end

# reference:
# October 1582 (the Gregorian calendar, Civil Date)
Expand All @@ -15,3 +8,42 @@
# 17 18 19 20 21 22 23
# 24 25 26 27 28 29 30
# 31
describe "Date.commercial" do
it "creates a Date for Julian Day Number day 0 by default" do
d = Date.commercial
d.year.should == -4712
d.month.should == 1
d.day.should == 1
end

it "creates a Date for the monday in the year and week given" do
d = Date.commercial(2000, 1)
d.year.should == 2000
d.month.should == 1
d.day.should == 3
d.cwday.should == 1
end

it "creates a Date for the correct day given the year, week and day number" do
d = Date.commercial(2004, 1, 1)
d.year.should == 2003
d.month.should == 12
d.day.should == 29
d.cwday.should == 1
d.cweek.should == 1
d.cwyear.should == 2004
end

it "creates only Date objects for valid weeks" do
-> { Date.commercial(2004, 53, 1) }.should_not.raise(ArgumentError)
-> { Date.commercial(2004, 53, 0) }.should.raise(ArgumentError)
-> { Date.commercial(2004, 53, 8) }.should.raise(ArgumentError)
-> { Date.commercial(2004, 54, 1) }.should.raise(ArgumentError)
-> { Date.commercial(2004, 0, 1) }.should.raise(ArgumentError)

-> { Date.commercial(2003, 52, 1) }.should_not.raise(ArgumentError)
-> { Date.commercial(2003, 53, 1) }.should.raise(ArgumentError)
-> { Date.commercial(2003, 52, 0) }.should.raise(ArgumentError)
-> { Date.commercial(2003, 52, 8) }.should.raise(ArgumentError)
end
end
4 changes: 3 additions & 1 deletion library/date/ctime_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
require 'date'

describe "Date#ctime" do
it "needs to be reviewed for spec completeness"
it "is an alias of Date#asctime" do
Date.instance_method(:ctime).should == Date.instance_method(:asctime)
end
end
15 changes: 11 additions & 4 deletions library/date/jd_spec.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
require_relative '../../spec_helper'
require_relative 'shared/jd'
require 'date'

describe "Date#jd" do

it "determines the Julian day for a Date object" do
Date.civil(2008, 1, 16).jd.should == 2454482
end

end

describe "Date.jd" do
it_behaves_like :date_jd, :jd
it "constructs a Date object if passed a Julian day" do
Date.jd(2454482).should == Date.civil(2008, 1, 16)
end

it "returns a Date object representing Julian day 0 (-4712-01-01) if no arguments passed" do
Date.jd.should == Date.civil(-4712, 1, 1)
end

it "constructs a Date object if passed a negative number" do
Date.jd(-1).should == Date.civil(-4713, 12, 31)
end
end
4 changes: 3 additions & 1 deletion library/date/mday_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
require 'date'

describe "Date#mday" do
it "needs to be reviewed for spec completeness"
it "is an alias of Date#day" do
Date.instance_method(:mday).should == Date.instance_method(:day)
end
end
5 changes: 3 additions & 2 deletions library/date/mon_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
require_relative '../../spec_helper'
require_relative 'shared/month'
require 'date'

describe "Date#mon" do
it_behaves_like :date_month, :mon
it "is an alias of Date#month" do
Date.instance_method(:mon).should == Date.instance_method(:month)
end
end
Loading
Loading