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

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

refs #49

File size: 2.2 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_duration = DV_Duration.new('P1Y2M3W4DT5H6M7.8S')}
15 end
16
17 def test_init
18 assert_instance_of DV_Temporal, @dv_temporal
19 assert_instance_of DV_Date, @dv_date
20 assert_instance_of DV_Time, @dv_time
21 assert_instance_of DV_Duration, @dv_duration
22 end
23
24 def test_dv_temporal
25 assert_equal '2008', @dv_temporal.value
26 assert_raise(NotImplementedError){@dv_temporal.diff('2009')}
27 end
28
29 def test_dv_date
30 assert_equal '2009-06-29', @dv_date.value
31 assert_equal 2009, @dv_date.year
32 assert_equal 6, @dv_date.month
33 assert_equal 29, @dv_date.day
34 assert_equal 733954, @dv_date.magnitude
35 date2 = DV_Date.new('2009-07-08')
36 assert_equal 'P0Y0M1W9D',@dv_date.diff(date2).value
37 date2 = DV_Date.new('2004-02-28')
38 date3 = DV_Date.new('2004-03-01')
39 assert_equal 'P0Y0M0W2D', date2.diff(date3).value
40 date4 = DV_Date.new('2003-12-31')
41 assert_equal 'P0Y1M4W28D', date2.diff(date4).value
42 birthday = DV_Date.new('1970-04-19')
43 assert_equal 'P39Y2M1W11D', birthday.diff(DV_Date.new('2009-06-30')).value
44 end
45
46 def test_dv_time
47 assert_equal 12, @dv_time.hour
48 assert_equal 34, @dv_time.minute
49 assert_equal 56, @dv_time.second
50 assert_equal 0.78, @dv_time.fractional_second
51 assert_equal (12*60*60 + 34 * 60 + 56 + 0.78), @dv_time.magnitude
52 dv_time2 = DV_Time.new('15:36:48.05')
53 assert_equal 'P0Y0M0W0DT3H1M51.27S', @dv_time.diff(dv_time2)
54 end
55
56 def test_dv_duration
57 assert_equal 'P1Y2M3W4DT5H6M7.8S', @dv_duration.value
58 assert_equal 1, @dv_duration.years
59 assert_equal 2, @dv_duration.months
60 assert_equal 3, @dv_duration.weeks
61 assert_equal 4, @dv_duration.days
62 assert_equal 5, @dv_duration.hours
63 assert_equal 6, @dv_duration.minutes
64 assert_equal 7, @dv_duration.seconds
65 assert_equal 0.8, @dv_duration.fractional_second
66 end
67end
Note: See TracBrowser for help on using the repository browser.