require 'test/unit' require 'test/framework' require 'eymiha/units' class TC_unit_derive < Test::Unit::TestCase include UnitsTest def test_unit_derived length = Units.create :length do |m| m.system :metric do |s| s.unit :name => :meter, :abbrev => :m, :greek => :ten end 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, :abbrev => :yd, :equals => 3.feet end end centimeter = length.metric.centimeter inch = length.english.inch foot = length.english.foot yard = length.english.yard volume = Units.derive :volume, length**3 do |m| m.system :metric do |s| s.unit :name => :milliliter, :abbrev => :mL, :equals => 1.cm**3 end end assert(volume.derived.size == 1) assert(volume.derived[length] == 3) milliliter = volume.metric.milliliter mass = Units.create :mass do |m| m.system :metric do |s| s.unit :name => :gram, :abbrev => :g, :greek => :ten end end gram = mass.metric.gram density = Units.derive :density, mass/volume do |m| m.system :base do |s| s.unit :name => :foo, :equals => 1.g/1.mL end end assert(density.derived.size == 2) assert(density.derived[length] == -3) assert(density.derived[mass] == 1) area = Units.derive :area, length**2 do |m| m.system :english do |s| s.unit :name => :acre, :equals => 220.yards * 66.feet end end assert(area.derived.size == 1) assert(area.derived[length] == 2) end end