Sha256: 1a87ab9194c252fae451675a982ac9642c6866cf4683180756bf989da7ad22b9

Contents?: true

Size: 1.44 KB

Versions: 1

Compression:

Stored size: 1.44 KB

Contents

require 'test/unit'
require 'test/framework'

require 'units'

class TC_unit_hash < Test::Unit::TestCase

  understands UnitsTest
  
  def test_unit_hash

    Units.create :length do |m|
      m.system :english do |s|
        s.unit :name => :inch,
               :plural => :inches,
               :abbrev => :in
      end
    end
    Units.create :mass do |m|
      m.system :english do |s|
        s.unit :name => :pound,
               :abbrev => :lb
      end
    end
    Units.create :time do |m|
      m.system :english do |s|
        s.unit :name => :second,
               :abbrev => :s
      end
    end

    nwu1 = 2.inches
    u1 = (Units.lookup :inch)[0]
    nwu2 = 3.pounds
    u2 = (Units.lookup :pound)[0]
    nwu3 = 5.seconds
    u3 = (Units.lookup :second)[0]

    assert(nwu1.unit == nwu1.unit.clone)
    nwu1.unit.merge! nwu2
    assert(nwu1.unit.size == 2)
    assert(nwu1.unit[u1] == 1)
    assert(nwu1.unit[u2] == 1)
    nwu1.unit.merge! nwu3,-2
    assert(nwu1.unit.size == 3)
    assert(nwu1.unit[u1] == 1)
    assert(nwu1.unit[u2] == 1)
    assert(nwu1.unit[u3] == -2)
    nwu1.unit.merge! nwu2,-1
    assert(nwu1.unit.size == 2)
    assert(nwu1.unit[u1] == 1)
    assert(nwu1.unit[u3] == -2)

    unit1 = nwu1.unit**2
    assert(unit1.size == 2)
    assert(unit1[u1] == 2)
    assert(unit1[u3] == -4)
    
    unit2 = UnitsHash.new(unit1,2)
    assert(unit2.size == 2)
    assert(unit2[u1] == 4)
    assert(unit2[u3] == -8)
    
  end
    
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
eymiha_units-0.1.0 test/tc_unit_hash.rb