source: ruby/branches/0.5/spec/lib/open_ehr/rm/data_types/quantity/dv_proportion_spec.rb@ 253

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

DvProportion moved test/unit to rspec

File size: 4.9 KB
Line 
1require File.dirname(__FILE__) + '/../../../../../spec_helper'
2include OpenEHR::RM::DataTypes::Quantity
3include OpenEHR::RM::DataTypes::Quantity::ProportionKind
4
5describe DvProportion do
6 before(:all) do
7 @dv_proportion0 = DvProportion.new(:numerator => 2,
8 :denominator => 3,
9 :type => PK_RATIO,
10 :accuracy => 1,
11 :accuracy_percent => true)
12 @dv_proportion1 = DvProportion.new(:numerator => 3,
13 :denominator => 1,
14 :type => PK_UNITARY)
15 @dv_proportion2 = DvProportion.new(:numerator => 5,
16 :denominator => 100,
17 :type => PK_PERCENT)
18 @dv_proportion3 = DvProportion.new(:numerator => 7,
19 :denominator => 8,
20 :type => PK_FRACTION)
21 @dv_proportion4 = DvProportion.new(:numerator => 9,
22 :denominator => 10,
23 :type => PK_INTEGER_FRACTION)
24 end
25
26 describe 'PK_RATIO type' do
27 it 'should be an instance of DvProportion' do
28 @dv_proportion0.should be_an_instance_of DvProportion
29 end
30
31 it 's numerator should be equal 2' do
32 @dv_proportion0.numerator.should be_equal 2
33 end
34
35 it 's denominator should be equal 3' do
36 @dv_proportion0.denominator.should be_equal 3
37 end
38
39 it 's type should be equal 0' do
40 @dv_proportion0.type.should == 0
41 end
42
43 it 's magnitude should be 2/3' do
44 @dv_proportion0.magnitude.should == 2.0/3.0
45 end
46
47 it 's accuracy should be 1' do
48 @dv_proportion0.accuracy.should == 1
49 end
50
51 it 'is_integral? should be true' do
52 @dv_proportion0.is_integral?.should be_true
53 end
54
55 it 'should be comperable to same type DvProportion' do
56 dv_propotion_type = DvProportion.new(:numerator => 3,
57 :denominator => 4,
58 :type => 0)
59 @dv_proportion0.is_strictly_comparable_to?(dv_propotion_type).
60 should be_true
61 end
62
63 it 'should not be comparable to other type DvPropotion' do
64 @dv_proportion0.is_strictly_comparable_to?(@dv_proportion1).
65 should_not be_true
66 end
67
68 it 'should not be comperable to other class' do
69 @dv_proportion0.is_strictly_comparable_to?(1).
70 should_not be_true
71 end
72
73 it 'should raise ArguentError with invalid type -1' do
74 lambda {
75 @dv_proportion0.type = -1
76 }.should raise_error ArgumentError
77 end
78
79 it 'should raise ArgumentError with invalid type 5' do
80 lambda {
81 @dv_proportion0.type = 5
82 }.should raise_error ArgumentError
83 end
84
85 it 's precision should be 0' do
86 @dv_proportion0.precision = 0
87 @dv_proportion0.precision.should == 0
88 end
89
90 it 'should raise ArgumentError when is_integral? and precision !=0' do
91 lambda {@dv_proportion0.precision = 1}.should raise_error ArgumentError
92 end
93
94 it 'shoud not raise ArgumentError when is_not ntegral' do
95 @dv_proportion0.numerator = 2.5
96 lambda {
97 @dv_proportion0.precision = 1
98 }.should_not raise_error ArgumentError
99 end
100 end
101
102 describe 'PK_UNITARY type' do
103 it 'should be an instance of DvPropotion' do
104 @dv_proportion1.should be_an_instance_of DvProportion
105 end
106
107 it 'should raise ArgumentError without denominator 1' do
108 lambda {
109 @dv_proportion1.denominator = 10
110 }.should raise_error ArgumentError
111 end
112 end
113
114 describe 'PK_PERCENT type' do
115 it 'should be an instance of DvProportion' do
116 @dv_proportion2.should be_an_instance_of DvProportion
117 end
118
119 it 'should raise ArgumentError without denominator 100' do
120 lambda {
121 @dv_proportion2.denominator = 101
122 }.should raise_error ArgumentError
123 end
124 end
125
126 describe 'PK_FRACTION type' do
127 it 'should be an instance of DvProportion' do
128 @dv_proportion3.should be_an_instance_of DvProportion
129 end
130
131 it 'should raise ArgumentError with fractional denominator' do
132 lambda {
133 @dv_proportion3.denominator = 0.5
134 }.should raise_error ArgumentError
135 end
136
137 it 'should raise ArgumentError with fractional numerator' do
138 lambda {
139 @dv_proportion3.numerator = 0.5
140 }.should raise_error ArgumentError
141 end
142 end
143
144 describe 'PK_FRACTION_INTEGER type' do
145 it 'should be an instance of DvProportion' do
146 @dv_proportion4.should be_an_instance_of DvProportion
147 end
148
149 it 'should raise ArgumentError with fractional denominator' do
150 lambda {
151 @dv_proportion4.denominator = 0.5
152 }.should raise_error ArgumentError
153
154 end
155
156 it 'should raise ArgumentError with fractional numerator' do
157 lambda {
158 @dv_proportion4.numerator = 0.5
159 }.should raise_error ArgumentError
160 end
161 end
162end
Note: See TracBrowser for help on using the repository browser.