1 | require File.dirname(__FILE__) + '/../../../../../spec_helper'
|
---|
2 | include OpenEHR::RM::DataTypes::Quantity
|
---|
3 |
|
---|
4 | describe DvQuantity do
|
---|
5 | before(:each) do
|
---|
6 | @dv_quantity = DvQuantity.new(:magnitude => 3,
|
---|
7 | :units => 'mg',
|
---|
8 | :precision => 0)
|
---|
9 | end
|
---|
10 |
|
---|
11 | it 'should be an instance of DvQuantity' do
|
---|
12 | @dv_quantity.should be_instance_of DvQuantity
|
---|
13 | end
|
---|
14 |
|
---|
15 | it 's units should be mg' do
|
---|
16 | @dv_quantity.units.should == 'mg'
|
---|
17 | end
|
---|
18 |
|
---|
19 | describe 'Mathematical Operation' do
|
---|
20 | before(:each) do
|
---|
21 | @dv_quantity5 = DvQuantity.new(:magnitude => 5,
|
---|
22 | :units => 'mg')
|
---|
23 | end
|
---|
24 |
|
---|
25 | it 'should be comparable to 5mg' do
|
---|
26 | @dv_quantity.is_strictly_comparable_to?(@dv_quantity5).should be_true
|
---|
27 | end
|
---|
28 |
|
---|
29 | it 'should be 8mg added 5mg' do
|
---|
30 | dv_quantity = @dv_quantity + @dv_quantity5
|
---|
31 | dv_quantity.magnitude.should == 8
|
---|
32 | end
|
---|
33 |
|
---|
34 | it 'should be -2mg minus 5mg' do
|
---|
35 | dv_quantity = @dv_quantity - @dv_quantity5
|
---|
36 | dv_quantity.magnitude.should == -2
|
---|
37 | end
|
---|
38 |
|
---|
39 | it 's unit should be mg' do
|
---|
40 | (@dv_quantity + @dv_quantity5).units.should == 'mg'
|
---|
41 | end
|
---|
42 | end
|
---|
43 |
|
---|
44 | it 'should not be comparable to 8km' do
|
---|
45 | dv_quantity = DvQuantity.new(:magnitude => 8,
|
---|
46 | :units => 'km')
|
---|
47 | @dv_quantity.is_strictly_comparable_to?(dv_quantity).should_not be_true
|
---|
48 | end
|
---|
49 |
|
---|
50 | it 'should return false with other type' do
|
---|
51 | @dv_quantity.is_strictly_comparable_to?(1).should_not be_true
|
---|
52 | end
|
---|
53 |
|
---|
54 | it 's precision should be equal 0' do
|
---|
55 | @dv_quantity.precision.should == 0
|
---|
56 | end
|
---|
57 |
|
---|
58 | it 'should be integral' do
|
---|
59 | @dv_quantity.is_integral?.should be_true
|
---|
60 | end
|
---|
61 |
|
---|
62 | it 'should not be integral do' do
|
---|
63 | @dv_quantity.precision = 3
|
---|
64 | @dv_quantity.is_integral?.should_not be_true
|
---|
65 | end
|
---|
66 |
|
---|
67 | it 'should not raise ArgumentError with -1 precision' do
|
---|
68 | lambda {
|
---|
69 | @dv_quantity.precision = -1
|
---|
70 | }.should_not raise_error ArgumentError
|
---|
71 | end
|
---|
72 |
|
---|
73 | it 'should raise ArgumentError with -2 precision' do
|
---|
74 | lambda {
|
---|
75 | @dv_quantity.precision = -2
|
---|
76 | }.should raise_error ArgumentError
|
---|
77 | end
|
---|
78 | end
|
---|