require 'test/unit' require 'test/framework' require 'units' class TC_unit_equality < Test::Unit::TestCase understands UnitsTest def test_unit_equality 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 end end inch = Units.length.english.inch foot = Units.length.english.foot yard = Units.length.english.yard assert(inch.equals.numeric == 1) assert(inch.equals.unit == {inch => 1}) assert(foot.equals.numeric == 12) assert(foot.equals.unit == {inch => 1}) assert(yard.equals.numeric == 36) assert(yard.equals.unit == {inch => 1}) assert(inch.equals.to_s == "1 inch") assert(foot.equals.to_s == "12 inches") assert(yard.equals.to_s == "36 inches") a = 12.feet assert(a.numeric == 12) assert(a.unit == {foot => 1}) assert(a.to_s == "12 feet") b = (2.0.ft^2)**0.5 c = 1.4142135623.ft assert(b != c) assert(b =~ c) end end