source: ruby/trunk/lib/models/tests/rm/quantity/ts_date_time.rb@ 151

Last change on this file since 151 was 151, checked in by KOBAYASHI, Shinji, 15 years ago

fixed #49

File size: 3.0 KB
Line 
1require 'test/unit'
2require 'rm'
3include OpenEHR::RM::Data_Types::Quantity::Date_Time
4
5class DateTimeTest < Test::Unit::TestCase
6 def setup
7 assert_nothing_raised(Exception){
8 @dv_temporal = DV_Temporal.new('2008')}
9 assert_nothing_raised(Exception){
10 @dv_date = DV_Date.new('2009-06-29')}
11 assert_nothing_raised(Exception){
12 @dv_time = DV_Time.new('12:34:56.78')}
13 assert_nothing_raised(Exception){
14 @dv_date_time = DV_Date_Time.new('2009-06-29T12:34:56.78')}
15 assert_nothing_raised(Exception){
16 @dv_duration = DV_Duration.new('P1Y2M3W4DT5H6M7.8S')}
17 end
18
19 def test_init
20 assert_instance_of DV_Temporal, @dv_temporal
21 assert_instance_of DV_Date, @dv_date
22 assert_instance_of DV_Time, @dv_time
23 assert_instance_of DV_Date_Time, @dv_date_time
24 assert_instance_of DV_Duration, @dv_duration
25 end
26
27 def test_dv_temporal
28 assert_equal '2008', @dv_temporal.value
29 assert_raise(NotImplementedError){@dv_temporal.diff('2009')}
30 end
31
32 def test_dv_date
33 assert_equal '2009-06-29', @dv_date.value
34 assert_equal 2009, @dv_date.year
35 assert_equal 6, @dv_date.month
36 assert_equal 29, @dv_date.day
37 assert_equal 733954, @dv_date.magnitude
38 date2 = DV_Date.new('2009-07-08')
39 assert_equal 'P0Y0M1W9D',@dv_date.diff(date2).value
40 date2 = DV_Date.new('2004-02-28')
41 date3 = DV_Date.new('2004-03-01')
42 assert_equal 'P0Y0M0W2D', date2.diff(date3).value
43 date4 = DV_Date.new('2003-12-31')
44 assert_equal 'P0Y1M4W28D', date2.diff(date4).value
45 birthday = DV_Date.new('1970-04-19')
46 assert_equal 'P39Y2M1W11D', birthday.diff(DV_Date.new('2009-06-30')).value
47 end
48
49 def test_dv_time
50 assert_equal '12:34:56.78', @dv_time.value
51 assert_equal 12, @dv_time.hour
52 assert_equal 34, @dv_time.minute
53 assert_equal 56, @dv_time.second
54 assert_equal 0.78, @dv_time.fractional_second
55 assert_equal((12*60*60 + 34 * 60 + 56 + 0.78), @dv_time.magnitude)
56 dv_time2 = DV_Time.new('15:36:48.05')
57 assert_equal 'P0Y0M0W0DT3H1M51.27S', @dv_time.diff(dv_time2).value
58 end
59
60 def test_dv_date_time
61 assert_equal '2009-06-29T12:34:56.78', @dv_date_time.value
62 assert_equal 2009, @dv_date_time.year
63 assert_equal 6, @dv_date_time.month
64 assert_equal 29, @dv_date_time.day
65 assert_equal 12, @dv_date_time.hour
66 assert_equal 34, @dv_date_time.minute
67 assert_equal 56, @dv_date_time.second
68 assert_equal 0.78, @dv_date_time.fractional_second
69 dv_date_time2 = DV_Date_Time.new('1970-04-19T13:55:30.12')
70 assert_equal 'P39Y2M1W9DT22H39M26.66S', @dv_date_time.diff(dv_date_time2).value
71 end
72
73 def test_dv_duration
74 assert_equal 'P1Y2M3W4DT5H6M7.8S', @dv_duration.value
75 assert_equal 1, @dv_duration.years
76 assert_equal 2, @dv_duration.months
77 assert_equal 3, @dv_duration.weeks
78 assert_equal 4, @dv_duration.days
79 assert_equal 5, @dv_duration.hours
80 assert_equal 6, @dv_duration.minutes
81 assert_equal 7, @dv_duration.seconds
82 assert_equal 0.8, @dv_duration.fractional_second
83 end
84end
Note: See TracBrowser for help on using the repository browser.