summaryrefslogtreecommitdiff
path: root/spec/ruby/library/date
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/library/date')
-rw-r--r--spec/ruby/library/date/asctime_spec.rb5
-rw-r--r--spec/ruby/library/date/commercial_spec.rb46
-rw-r--r--spec/ruby/library/date/ctime_spec.rb4
-rw-r--r--spec/ruby/library/date/jd_spec.rb15
-rw-r--r--spec/ruby/library/date/mday_spec.rb4
-rw-r--r--spec/ruby/library/date/mon_spec.rb5
-rw-r--r--spec/ruby/library/date/month_spec.rb6
-rw-r--r--spec/ruby/library/date/ordinal_spec.rb14
-rw-r--r--spec/ruby/library/date/shared/commercial.rb39
-rw-r--r--spec/ruby/library/date/shared/jd.rb14
-rw-r--r--spec/ruby/library/date/shared/month.rb6
-rw-r--r--spec/ruby/library/date/shared/ordinal.rb22
-rw-r--r--spec/ruby/library/date/shared/valid_civil.rb36
-rw-r--r--spec/ruby/library/date/shared/valid_commercial.rb34
-rw-r--r--spec/ruby/library/date/shared/valid_jd.rb20
-rw-r--r--spec/ruby/library/date/shared/valid_ordinal.rb26
-rw-r--r--spec/ruby/library/date/succ_spec.rb4
-rw-r--r--spec/ruby/library/date/valid_civil_spec.rb9
-rw-r--r--spec/ruby/library/date/valid_commercial_spec.rb33
-rw-r--r--spec/ruby/library/date/valid_date_spec.rb35
-rw-r--r--spec/ruby/library/date/valid_jd_spec.rb18
-rw-r--r--spec/ruby/library/date/valid_ordinal_spec.rb26
22 files changed, 187 insertions, 234 deletions
diff --git a/spec/ruby/library/date/asctime_spec.rb b/spec/ruby/library/date/asctime_spec.rb
index 67d158cc01..e268ffe098 100644
--- a/spec/ruby/library/date/asctime_spec.rb
+++ b/spec/ruby/library/date/asctime_spec.rb
@@ -2,5 +2,8 @@ require_relative '../../spec_helper'
require 'date'
describe "Date#asctime" do
- it "needs to be reviewed for spec completeness"
+ it "returns a canonical string representation of date" do
+ d = Date.today
+ d.asctime.should == d.strftime("%a %b %e %H:%M:%S %Y")
+ end
end
diff --git a/spec/ruby/library/date/commercial_spec.rb b/spec/ruby/library/date/commercial_spec.rb
index d7fc34d74a..8e2df79b90 100644
--- a/spec/ruby/library/date/commercial_spec.rb
+++ b/spec/ruby/library/date/commercial_spec.rb
@@ -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)
@@ -15,3 +8,42 @@ end
# 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
diff --git a/spec/ruby/library/date/ctime_spec.rb b/spec/ruby/library/date/ctime_spec.rb
index 3faa7c6380..330076a735 100644
--- a/spec/ruby/library/date/ctime_spec.rb
+++ b/spec/ruby/library/date/ctime_spec.rb
@@ -2,5 +2,7 @@ require_relative '../../spec_helper'
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
diff --git a/spec/ruby/library/date/jd_spec.rb b/spec/ruby/library/date/jd_spec.rb
index 336b783e8d..e5cfe10eff 100644
--- a/spec/ruby/library/date/jd_spec.rb
+++ b/spec/ruby/library/date/jd_spec.rb
@@ -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
diff --git a/spec/ruby/library/date/mday_spec.rb b/spec/ruby/library/date/mday_spec.rb
index 53f6f98169..32fd8fc7f1 100644
--- a/spec/ruby/library/date/mday_spec.rb
+++ b/spec/ruby/library/date/mday_spec.rb
@@ -2,5 +2,7 @@ require_relative '../../spec_helper'
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
diff --git a/spec/ruby/library/date/mon_spec.rb b/spec/ruby/library/date/mon_spec.rb
index 616d72cf88..15754ffb1f 100644
--- a/spec/ruby/library/date/mon_spec.rb
+++ b/spec/ruby/library/date/mon_spec.rb
@@ -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
diff --git a/spec/ruby/library/date/month_spec.rb b/spec/ruby/library/date/month_spec.rb
index f493ec8119..e040f9a94c 100644
--- a/spec/ruby/library/date/month_spec.rb
+++ b/spec/ruby/library/date/month_spec.rb
@@ -1,7 +1,9 @@
require_relative '../../spec_helper'
-require_relative 'shared/month'
require 'date'
describe "Date#month" do
- it_behaves_like :date_month, :month
+ it "returns the month" do
+ m = Date.new(2000, 7, 1).month
+ m.should == 7
+ end
end
diff --git a/spec/ruby/library/date/ordinal_spec.rb b/spec/ruby/library/date/ordinal_spec.rb
index ec490fd49c..c8bf715163 100644
--- a/spec/ruby/library/date/ordinal_spec.rb
+++ b/spec/ruby/library/date/ordinal_spec.rb
@@ -1,7 +1,17 @@
require 'date'
require_relative '../../spec_helper'
-require_relative 'shared/ordinal'
describe "Date.ordinal" do
- it_behaves_like :date_ordinal, :ordinal
+ it "constructs a Date object from an ordinal date" do
+ # October 1582 (the Gregorian calendar, Ordinal Date)
+ # S M Tu W Th F S
+ # 274 275 276 277 278 279
+ # 280 281 282 283 284 285 286
+ # 287 288 289 290 291 292 293
+ # 294
+ Date.ordinal(1582, 274).should == Date.civil(1582, 10, 1)
+ Date.ordinal(1582, 277).should == Date.civil(1582, 10, 4)
+ Date.ordinal(1582, 278).should == Date.civil(1582, 10, 15)
+ Date.ordinal(1582, 287, Date::ENGLAND).should == Date.civil(1582, 10, 14, Date::ENGLAND)
+ end
end
diff --git a/spec/ruby/library/date/shared/commercial.rb b/spec/ruby/library/date/shared/commercial.rb
deleted file mode 100644
index f53d83235a..0000000000
--- a/spec/ruby/library/date/shared/commercial.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-describe :date_commercial, shared: true do
- it "creates a Date for Julian Day Number day 0 by default" do
- d = Date.send(@method)
- 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.send(@method, 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.send(@method, 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.send(@method, 2004, 53, 1) }.should_not.raise(ArgumentError)
- -> { Date.send(@method, 2004, 53, 0) }.should.raise(ArgumentError)
- -> { Date.send(@method, 2004, 53, 8) }.should.raise(ArgumentError)
- -> { Date.send(@method, 2004, 54, 1) }.should.raise(ArgumentError)
- -> { Date.send(@method, 2004, 0, 1) }.should.raise(ArgumentError)
-
- -> { Date.send(@method, 2003, 52, 1) }.should_not.raise(ArgumentError)
- -> { Date.send(@method, 2003, 53, 1) }.should.raise(ArgumentError)
- -> { Date.send(@method, 2003, 52, 0) }.should.raise(ArgumentError)
- -> { Date.send(@method, 2003, 52, 8) }.should.raise(ArgumentError)
- end
-end
diff --git a/spec/ruby/library/date/shared/jd.rb b/spec/ruby/library/date/shared/jd.rb
deleted file mode 100644
index 511557b4f7..0000000000
--- a/spec/ruby/library/date/shared/jd.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-describe :date_jd, shared: true do
- it "constructs a Date object if passed a Julian day" do
- Date.send(@method, 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.send(@method).should == Date.civil(-4712, 1, 1)
- end
-
- it "constructs a Date object if passed a negative number" do
- Date.send(@method, -1).should == Date.civil(-4713, 12, 31)
- end
-
-end
diff --git a/spec/ruby/library/date/shared/month.rb b/spec/ruby/library/date/shared/month.rb
deleted file mode 100644
index 5fcb2cbeb0..0000000000
--- a/spec/ruby/library/date/shared/month.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-describe :date_month, shared: true do
- it "returns the month" do
- m = Date.new(2000, 7, 1).send(@method)
- m.should == 7
- end
-end
diff --git a/spec/ruby/library/date/shared/ordinal.rb b/spec/ruby/library/date/shared/ordinal.rb
deleted file mode 100644
index 4b182d5a25..0000000000
--- a/spec/ruby/library/date/shared/ordinal.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-# reference:
-# October 1582 (the Gregorian calendar, Civil Date)
-# S M Tu W Th F S
-# 1 2 3 4 15 16
-# 17 18 19 20 21 22 23
-# 24 25 26 27 28 29 30
-# 31
-
-describe :date_ordinal, shared: true do
- it "constructs a Date object from an ordinal date" do
- # October 1582 (the Gregorian calendar, Ordinal Date)
- # S M Tu W Th F S
- # 274 275 276 277 278 279
- # 280 281 282 283 284 285 286
- # 287 288 289 290 291 292 293
- # 294
- Date.send(@method, 1582, 274).should == Date.civil(1582, 10, 1)
- Date.send(@method, 1582, 277).should == Date.civil(1582, 10, 4)
- Date.send(@method, 1582, 278).should == Date.civil(1582, 10, 15)
- Date.send(@method, 1582, 287, Date::ENGLAND).should == Date.civil(1582, 10, 14, Date::ENGLAND)
- end
-end
diff --git a/spec/ruby/library/date/shared/valid_civil.rb b/spec/ruby/library/date/shared/valid_civil.rb
deleted file mode 100644
index 425fee4d2d..0000000000
--- a/spec/ruby/library/date/shared/valid_civil.rb
+++ /dev/null
@@ -1,36 +0,0 @@
-describe :date_valid_civil?, shared: true do
-
- # reference:
- # October 1582 (the Gregorian calendar, Civil Date)
- # S M Tu W Th F S
- # 1 2 3 4 15 16
- # 17 18 19 20 21 22 23
- # 24 25 26 27 28 29 30
- # 31
-
- it "returns true if it is a valid civil date" do
- Date.send(@method, 1582, 10, 15).should == true
- Date.send(@method, 1582, 10, 14, Date::ENGLAND).should == true
- end
-
- it "returns false if it is not a valid civil date" do
- Date.send(@method, 1582, 10, 14).should == false
- end
-
- it "handles negative months and days" do
- # October 1582 (the Gregorian calendar, Civil Date)
- # S M Tu W Th F S
- # -21 -20 -19 -18 -17 -16
- # -15 -14 -13 -12 -11 -10 -9
- # -8 -7 -6 -5 -4 -3 -2
- # -1
- Date.send(@method, 1582, -3, -22).should == false
- Date.send(@method, 1582, -3, -21).should == true
- Date.send(@method, 1582, -3, -18).should == true
- Date.send(@method, 1582, -3, -17).should == true
-
- Date.send(@method, 2007, -11, -10).should == true
- Date.send(@method, 2008, -11, -10).should == true
- end
-
-end
diff --git a/spec/ruby/library/date/shared/valid_commercial.rb b/spec/ruby/library/date/shared/valid_commercial.rb
deleted file mode 100644
index 573b851fdd..0000000000
--- a/spec/ruby/library/date/shared/valid_commercial.rb
+++ /dev/null
@@ -1,34 +0,0 @@
-describe :date_valid_commercial?, shared: true do
-
- it "returns true if it is a valid commercial date" do
- # October 1582 (the Gregorian calendar, Commercial Date)
- # M Tu W Th F Sa Su
- # 39: 1 2 3 4 5 6 7
- # 40: 1 2 3 4 5 6 7
- # 41: 1 2 3 4 5 6 7
- Date.send(@method, 1582, 39, 4).should == true
- Date.send(@method, 1582, 39, 5).should == true
- Date.send(@method, 1582, 41, 4).should == true
- Date.send(@method, 1582, 41, 5).should == true
- Date.send(@method, 1582, 41, 4, Date::ENGLAND).should == true
- Date.send(@method, 1752, 37, 4, Date::ENGLAND).should == true
- end
-
- it "returns false it is not a valid commercial date" do
- Date.send(@method, 1999, 53, 1).should == false
- end
-
- it "handles negative week and day numbers" do
- # October 1582 (the Gregorian calendar, Commercial Date)
- # M Tu W Th F Sa Su
- # -12: -7 -6 -5 -4 -3 -2 -1
- # -11: -7 -6 -5 -4 -3 -2 -1
- # -10: -7 -6 -5 -4 -3 -2 -1
- Date.send(@method, 1582, -12, -4).should == true
- Date.send(@method, 1582, -12, -3).should == true
- Date.send(@method, 2007, -44, -2).should == true
- Date.send(@method, 2008, -44, -2).should == true
- Date.send(@method, 1999, -53, -1).should == false
- end
-
-end
diff --git a/spec/ruby/library/date/shared/valid_jd.rb b/spec/ruby/library/date/shared/valid_jd.rb
deleted file mode 100644
index 0c01710208..0000000000
--- a/spec/ruby/library/date/shared/valid_jd.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-describe :date_valid_jd?, shared: true do
- it "returns true if passed a number value" do
- Date.send(@method, -100).should == true
- Date.send(@method, 100.0).should == true
- Date.send(@method, 2**100).should == true
- Date.send(@method, Rational(1,2)).should == true
- end
-
- it "returns false if passed nil" do
- Date.send(@method, nil).should == false
- end
-
- it "returns false if passed symbol" do
- Date.send(@method, :number).should == false
- end
-
- it "returns false if passed false" do
- Date.send(@method, false).should == false
- end
-end
diff --git a/spec/ruby/library/date/shared/valid_ordinal.rb b/spec/ruby/library/date/shared/valid_ordinal.rb
deleted file mode 100644
index 1ed961be23..0000000000
--- a/spec/ruby/library/date/shared/valid_ordinal.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-describe :date_valid_ordinal?, shared: true do
- it "determines if the date is a valid ordinal date" do
- # October 1582 (the Gregorian calendar, Ordinal Date)
- # S M Tu W Th F S
- # 274 275 276 277 278 279
- # 280 281 282 283 284 285 286
- # 287 288 289 290 291 292 293
- # 294
- Date.send(@method, 1582, 277).should == true
- Date.send(@method, 1582, 278).should == true
- Date.send(@method, 1582, 287).should == true
- Date.send(@method, 1582, 288).should == true
- end
-
- it "handles negative day numbers" do
- # October 1582 (the Gregorian calendar, Ordinal Date)
- # S M Tu W Th F S
- # -82 -81 -80 -79 -78 -77
- # -76 -75 -74 -73 -72 -71 -70
- # -69 -68 -67 -66 -65 -64 -63
- # -62
- Date.send(@method, 1582, -79).should == true
- Date.send(@method, 1582, -78).should == true
- Date.send(@method, 2007, -100).should == true
- end
-end
diff --git a/spec/ruby/library/date/succ_spec.rb b/spec/ruby/library/date/succ_spec.rb
index c4a902aa63..0b14d3bb73 100644
--- a/spec/ruby/library/date/succ_spec.rb
+++ b/spec/ruby/library/date/succ_spec.rb
@@ -2,5 +2,7 @@ require_relative '../../spec_helper'
require 'date'
describe "Date#succ" do
- it "needs to be reviewed for spec completeness"
+ it "is an alias of Date#next" do
+ Date.instance_method(:succ).should == Date.instance_method(:next)
+ end
end
diff --git a/spec/ruby/library/date/valid_civil_spec.rb b/spec/ruby/library/date/valid_civil_spec.rb
index 00f2c57205..8cffc80310 100644
--- a/spec/ruby/library/date/valid_civil_spec.rb
+++ b/spec/ruby/library/date/valid_civil_spec.rb
@@ -1,9 +1,8 @@
require_relative '../../spec_helper'
-require_relative 'shared/valid_civil'
require 'date'
-describe "Date#valid_civil?" do
-
- it_behaves_like :date_valid_civil?, :valid_civil?
-
+describe "Date.valid_civil?" do
+ it "is an alias of Date.valid_date?" do
+ Date.method(:valid_civil?).should == Date.method(:valid_date?)
+ end
end
diff --git a/spec/ruby/library/date/valid_commercial_spec.rb b/spec/ruby/library/date/valid_commercial_spec.rb
index 7e96782b6b..21a91ad867 100644
--- a/spec/ruby/library/date/valid_commercial_spec.rb
+++ b/spec/ruby/library/date/valid_commercial_spec.rb
@@ -1,8 +1,35 @@
require_relative '../../spec_helper'
-require_relative 'shared/valid_commercial'
require 'date'
-describe "Date#valid_commercial?" do
+describe "Date.valid_commercial?" do
+ it "returns true if it is a valid commercial date" do
+ # October 1582 (the Gregorian calendar, Commercial Date)
+ # M Tu W Th F Sa Su
+ # 39: 1 2 3 4 5 6 7
+ # 40: 1 2 3 4 5 6 7
+ # 41: 1 2 3 4 5 6 7
+ Date.valid_commercial?(1582, 39, 4).should == true
+ Date.valid_commercial?(1582, 39, 5).should == true
+ Date.valid_commercial?(1582, 41, 4).should == true
+ Date.valid_commercial?(1582, 41, 5).should == true
+ Date.valid_commercial?(1582, 41, 4, Date::ENGLAND).should == true
+ Date.valid_commercial?(1752, 37, 4, Date::ENGLAND).should == true
+ end
- it_behaves_like :date_valid_commercial?, :valid_commercial?
+ it "returns false it is not a valid commercial date" do
+ Date.valid_commercial?(1999, 53, 1).should == false
+ end
+
+ it "handles negative week and day numbers" do
+ # October 1582 (the Gregorian calendar, Commercial Date)
+ # M Tu W Th F Sa Su
+ # -12: -7 -6 -5 -4 -3 -2 -1
+ # -11: -7 -6 -5 -4 -3 -2 -1
+ # -10: -7 -6 -5 -4 -3 -2 -1
+ Date.valid_commercial?(1582, -12, -4).should == true
+ Date.valid_commercial?(1582, -12, -3).should == true
+ Date.valid_commercial?(2007, -44, -2).should == true
+ Date.valid_commercial?(2008, -44, -2).should == true
+ Date.valid_commercial?(1999, -53, -1).should == false
+ end
end
diff --git a/spec/ruby/library/date/valid_date_spec.rb b/spec/ruby/library/date/valid_date_spec.rb
index f12a71d966..f0d5ec7b4d 100644
--- a/spec/ruby/library/date/valid_date_spec.rb
+++ b/spec/ruby/library/date/valid_date_spec.rb
@@ -1,7 +1,36 @@
require_relative '../../spec_helper'
-require_relative 'shared/valid_civil'
require 'date'
-describe "Date#valid_date?" do
- it_behaves_like :date_valid_civil?, :valid_date?
+describe "Date.valid_date?" do
+ # reference:
+ # October 1582 (the Gregorian calendar, Civil Date)
+ # S M Tu W Th F S
+ # 1 2 3 4 15 16
+ # 17 18 19 20 21 22 23
+ # 24 25 26 27 28 29 30
+ # 31
+ it "returns true if it is a valid civil date" do
+ Date.valid_date?(1582, 10, 15).should == true
+ Date.valid_date?(1582, 10, 14, Date::ENGLAND).should == true
+ end
+
+ it "returns false if it is not a valid civil date" do
+ Date.valid_date?(1582, 10, 14).should == false
+ end
+
+ it "handles negative months and days" do
+ # October 1582 (the Gregorian calendar, Civil Date)
+ # S M Tu W Th F S
+ # -21 -20 -19 -18 -17 -16
+ # -15 -14 -13 -12 -11 -10 -9
+ # -8 -7 -6 -5 -4 -3 -2
+ # -1
+ Date.valid_date?(1582, -3, -22).should == false
+ Date.valid_date?(1582, -3, -21).should == true
+ Date.valid_date?(1582, -3, -18).should == true
+ Date.valid_date?(1582, -3, -17).should == true
+
+ Date.valid_date?(2007, -11, -10).should == true
+ Date.valid_date?(2008, -11, -10).should == true
+ end
end
diff --git a/spec/ruby/library/date/valid_jd_spec.rb b/spec/ruby/library/date/valid_jd_spec.rb
index aecaaabcf4..46f22de497 100644
--- a/spec/ruby/library/date/valid_jd_spec.rb
+++ b/spec/ruby/library/date/valid_jd_spec.rb
@@ -1,9 +1,23 @@
require_relative '../../spec_helper'
-require_relative 'shared/valid_jd'
require 'date'
describe "Date.valid_jd?" do
+ it "returns true if passed a number value" do
+ Date.valid_jd?(-100).should == true
+ Date.valid_jd?(100.0).should == true
+ Date.valid_jd?(2**100).should == true
+ Date.valid_jd?(Rational(1,2)).should == true
+ end
- it_behaves_like :date_valid_jd?, :valid_jd?
+ it "returns false if passed nil" do
+ Date.valid_jd?(nil).should == false
+ end
+ it "returns false if passed symbol" do
+ Date.valid_jd?(:number).should == false
+ end
+
+ it "returns false if passed false" do
+ Date.valid_jd?(false).should == false
+ end
end
diff --git a/spec/ruby/library/date/valid_ordinal_spec.rb b/spec/ruby/library/date/valid_ordinal_spec.rb
index 58d548c704..bb5c259606 100644
--- a/spec/ruby/library/date/valid_ordinal_spec.rb
+++ b/spec/ruby/library/date/valid_ordinal_spec.rb
@@ -1,9 +1,29 @@
require_relative '../../spec_helper'
-require_relative 'shared/valid_ordinal'
require 'date'
describe "Date.valid_ordinal?" do
+ it "determines if the date is a valid ordinal date" do
+ # October 1582 (the Gregorian calendar, Ordinal Date)
+ # S M Tu W Th F S
+ # 274 275 276 277 278 279
+ # 280 281 282 283 284 285 286
+ # 287 288 289 290 291 292 293
+ # 294
+ Date.valid_ordinal?(1582, 277).should == true
+ Date.valid_ordinal?(1582, 278).should == true
+ Date.valid_ordinal?(1582, 287).should == true
+ Date.valid_ordinal?(1582, 288).should == true
+ end
- it_behaves_like :date_valid_ordinal?, :valid_ordinal?
-
+ it "handles negative day numbers" do
+ # October 1582 (the Gregorian calendar, Ordinal Date)
+ # S M Tu W Th F S
+ # -82 -81 -80 -79 -78 -77
+ # -76 -75 -74 -73 -72 -71 -70
+ # -69 -68 -67 -66 -65 -64 -63
+ # -62
+ Date.valid_ordinal?(1582, -79).should == true
+ Date.valid_ordinal?(1582, -78).should == true
+ Date.valid_ordinal?(2007, -100).should == true
+ end
end