Changeset 248


Ignore:
Timestamp:
Sep 7, 2009, 12:07:59 PM (15 years ago)
Author:
KOBAYASHI, Shinji
Message:

move DvAmount, DvCount test to spec

Location:
ruby/branches/0.5
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • ruby/branches/0.5/lib/open_ehr/rm/data_types/quantity.rb

    r247 r248  
    4343          end
    4444
    45           def is_strictly_comparable_to?(other)
    46             raise NotImplementedError, 'this method should be implemented'
     45          def is_strictly_comparable_to?(others)
     46            if others.instance_of? self.class
     47              return true
     48            else
     49              return false
     50            end
    4751          end
    4852        end
     
    113117          end
    114118
    115           def is_strictly_comparable_to?(others)
    116             unless others.instance_of? OpenEHR::RM::DataTypes::Quantity::DvOrdinal
    117               return false
    118             end
    119             unless others.symbol.defining_code.terminology_id.value ==
    120                 @symbol.defining_code.terminology_id.value
    121               return false
    122             end
    123             return true
    124           end
    125 
    126119          def <=>(other)
    127120            @value <=> other.value
     
    133126            else
    134127              @limits = limits
     128            end
     129          end
     130          def is_strictly_comparable_to?(others)
     131            super
     132            unless others.instance_of? self.class
     133              return false
     134            end
     135            unless others.symbol.defining_code.terminology_id.value ==
     136                @symbol.defining_code.terminology_id.value
     137              return false
     138            else
     139              return true
    135140            end
    136141          end
     
    163168        class DvAmount < DvQuantified
    164169          attr_reader :accuracy, :accuracy_percent
    165           def initialize(magnitude, magnitude_status=nil, accuracy=nil,
    166                          accuracy_percent=nil, normal_range=nil,
    167                          normal_status = nil, other_reference_ranges=nil)
    168             super(magnitude, magnitude_status, normal_range,
    169                   normal_status, other_reference_ranges)
    170             unless accuracy.nil?
    171               set_accuracy(accuracy, accuracy_percent)
     170
     171          def initialize(args = {})
     172            super(args)
     173            unless args[:accuracy].nil?
     174              set_accuracy(args[:accuracy], args[:accuracy_percent])
    172175            else
    173176              @accuracy, @accuracy_percent = nil, nil
     
    176179
    177180          def +(other)
    178             unless self.is_strictly_comparable_to?(other)
     181            unless self.is_strictly_comparable_to? other
    179182              raise ArgumentError, 'type mismatch'
    180183            end
    181             return DvAmount.new(@magnitude+other.magnitude, @magnitude_status,
    182                                  @accuracy, @accuracy_percent, @normal_range,
    183                                  @normal_status, @other_reference_ranges)
    184           end
    185 
    186           def -(other)
     184            result = self.dup
     185            result.magnitude = @magnitude + other.magnitude
     186            return result
     187          end
     188
     189          def -(other)           
    187190            other.magnitude = - other.magnitude
    188191            self+(other)
     
    253256
    254257        class DvCount < DvAmount
    255           def is_strictly_comparable_to?(others)
    256             return false if others.nil?
    257             if others.instance_of?(DvCount)
    258               return true
    259             else
    260               return false
    261             end
    262           end
     258
    263259        end
    264260
  • ruby/branches/0.5/spec/lib/open_ehr/rm/data_types/quantity/dv_ordered_spec.rb

    r243 r248  
    4949  end
    5050
    51   it 'is_strictly_comparable_to should raise ArgumentError' do
    52     lambda{
    53       @dv_ordered.is_strictly_comparable_to? 'test'
    54     }.should raise_error(NotImplementedError)
     51  it 'is_strictly_comparable_to should be true for DvOrdered' do
     52    @dv_ordered.is_strictly_comparable_to?(DvOrdered.new).should be_true
    5553  end
    5654
  • ruby/branches/0.5/spec/lib/open_ehr/rm/data_types/quantity/dv_ordinal_spec.rb

    r246 r248  
    6161
    6262  it 'is_strictly comparable should be false with other instance' do
    63     @dv_ordinal.is_strictly_comparable_to?(stub).should be_false
     63    @dv_ordinal.is_strictly_comparable_to?('dummy').should be_false
    6464  end
    6565
Note: See TracChangeset for help on using the changeset viewer.