require 'test/unit' require 'test/framework' require 'eymiha/units' class TC_measure_derive < Test::Unit::TestCase include UnitsTest def test_measure_derive assert((length = Units.create :length) == Units.length) assert(length.derived == nil) assert((distance = Units.derive 'distance', length) == Units.length) assert(distance.derived == nil) assert((area = Units.derive 'area', length**2) == Units.area) assert(area.derived.size == 1) assert(area.derived[Units.length] == 2) assert((volume = Units.derive 'volume', area*length) == Units.volume) assert(volume.derived.size == 1) assert(volume.derived[Units.length] == 3) assert((time = Units.create 'time') == Units.time) assert(time.derived == nil) assert((velocity = Units.derive :velocity, distance/time) == Units.velocity) assert(velocity.derived.size == 2) assert(velocity.derived[Units.distance] == 1) assert(velocity.derived[Units.time] == -1) assert((acceleration = Units.derive :acceleration, distance/time**2) == Units.acceleration) assert(acceleration.derived.size == 2) assert(acceleration.derived[Units.distance] == 1) assert(acceleration.derived[Units.time] == -2) assert(acceleration == Units.derive(:acceleration2, distance/time**2)) assert(Units.acceleration2 == Units.acceleration) end end