Sha256: 38b5c01670e82eefd6d974f2a2b6009729fbe475bfedda2489a7f209f4f36f85

Contents?: true

Size: 1.31 KB

Versions: 2

Compression:

Stored size: 1.31 KB

Contents

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

require 'eymiha/units'

class TC_unit_rank < Test::Unit::TestCase
  
  include UnitsTest

  def load_units
    
    Units.create :length do |m|
      m.system :english do |s|
        s.unit :name => :inch, :plural => :inches, :abbrev => :in
        s.unit :name => :foot, :plural => :feet, :abbrev => :ft,
               :equals => 12.inches
        s.unit :name => :yard, :abbrevs => :yd, :equals => 3.feet
        s.unit :name => :mile, :abbrevs => :mi, :equals => 1760.yards
      end
      m.system :metric do |s|
        s.unit :name => :meter, :abbrev => :m, :equals => 39.370079.in,
               :greek => :ten
      end
    end

    Units.create :time do |m|
      m.system :base do |s|
        s.unit :name => :second, :abbrev => :sec
        s.unit :name => :minute, :abbrev => :min, :equals => 60.seconds
        s.unit :name => :hour, :abbrev => :hr, :equals => 60.minutes
        s.unit :name => :day, :abbrev => :dy, :equals => 24.hours
      end
    end

  end

  
  def test_unit_rank

    load_units

    unit_choices = {1.meter/min => 2, 1.mile/hour => 1, 1.km/hr => 1}
    samples = [7.35.in/sec, 1.18.in/sec, 0.92.in/sec]

    ranks = Units.rank(unit_choices,samples)

    assert(ranks[0] == 1.m/min)
    assert(ranks[1] == 1.km/hr)
    assert(ranks[2] == 1.mi/hr)

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
eymiha_units-1.0.1 test/tc_unit_rank.rb
eymiha_units-1.0.0 test/tc_unit_rank.rb