Sha256: b2eafb4a8419d56efc8d92a6866dd285cd41e5df0ef2272882e8c2f6805b0f8f

Contents?: true

Size: 1.84 KB

Versions: 2

Compression:

Stored size: 1.84 KB

Contents

require 'test/unit'

require 'eymiha/units'

class TC_definitions < Test::Unit::TestCase

  def test_definitions

    assert(Units.forward_references.size == 0)  # all the definitions loaded

    t = 5.years
    assert(t.to_s == "5 years")
    assert(t.in_months.to_s == "60 months")
    assert(t.in_months.in_days.to_s == "1800 days")
    assert(t.in_days.to_s == "1825 days")
    assert(t.in_days.in_months.to_s == "60.8333333333333 months")
    assert(t.in_hours.to_s == "43800.0 hours")
    assert(t.in_weeks.to_s == "260 weeks")
    assert(t.in_months.in_weeks.to_s == "240 weeks")
    assert(t.in_days.in_weeks.to_s == "260.714285714286 weeks")
    assert(t.in_days == 260.weeks+5.days)

    assert(days_in_january.to_s == "31.0")
    assert(hours_in_january.to_s == "744.0")
    assert(hours_per_january == 744)
    assert(1.january.hours == 744.hours)
    assert(january.hours == 744.hours)
    assert(february.hours == 672.hours)
    assert(july.weeks.to_s == "4.42857142857143 weeks")
    assert(july.format(:weeks_and_days).to_s == "4 weeks 3 days")
    assert(july.to_s(:weeks_and_days) == "4 weeks 3 days")

    assert(speed_of_light.in_mi_s.to_s == "186282.024486427 mi / s")
    assert(4.5.ly.in_mi.to_s == "26435654658917.8 miles")
    assert(4.5.ly.AU.to_s == "284389.813364457 astronomical units")
    assert(speed_of_light.miles.to_s == "186282.024486427 mi / s")
    assert(speed_of_light.feet_nanosecond.to_s == "0.983569089288333 ft / ns")
    assert(4.5.unite(["light_years"]).AU.to_s ==
           "284389.813364457 astronomical units")
    assert(4.5.light_years.AU.to_s == 
           "284389.813364457 astronomical units")
    assert(4.5.light_years.astronomical_units.to_s == 
           "284389.813364457 astronomical units")
    assert(1.speed_of_light.to_s == "1 speed of light")
    assert(4.5.speed_of_light.to_s == "4.5 speed of light")

  end
    
end

Version data entries

2 entries across 2 versions & 1 rubygems

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