require 'test/unit' require 'test/framework' require 'eymiha/units' # note that different rubys apparently have different minimum exponent digits class TC_unit_greek < Test::Unit::TestCase include UnitsTest def test_unit_greek Units.create :length do |m| m.system :metric do |s| s.unit :name => :meter, :abbrev => :m, :greek => :ten end end yoctometer = Units.length.metric.yoctometer.equals assert((yoctometer.to_s == "1.0e-24 meters")|| (yoctometer.to_s == "1.0e-024 meters")) assert(yoctometer == 0.000000000000000000000001.meters) zeptometer = Units.length.metric.zeptometer.equals assert((zeptometer.to_s == "1.0e-21 meters")|| (zeptometer.to_s == "1.0e-021 meters")) assert(zeptometer == 0.000000000000000000001.meters) attometer = Units.length.metric.attometer.equals assert((attometer.to_s == "1.0e-18 meters")|| (attometer.to_s == "1.0e-018 meters")) assert(attometer == 0.000000000000000001.meters) femtometer = Units.length.metric.femtometer.equals assert((femtometer.to_s == "1.0e-15 meters")|| (femtometer.to_s == "1.0e-015 meters")) assert(femtometer == 0.000000000000001.meters) picometer = Units.length.metric.picometer.equals assert((picometer.to_s == "1.0e-12 meters")|| (picometer.to_s == "1.0e-012 meters")) assert(picometer == 0.000000000001.meters) nanometer = Units.length.metric.nanometer.equals assert((nanometer.to_s == "1.0e-09 meters")|| (nanometer.to_s == "1.0e-009 meters")) assert(nanometer == 0.000000001.meters) micrometer = Units.length.metric.micrometer.equals assert((micrometer.to_s == "1.0e-06 meters")|| (micrometer.to_s == "1.0e-006 meters")) assert(micrometer == 0.000001.meters) millimeter = Units.length.metric.millimeter.equals assert(millimeter.to_s == "0.001 meters") assert(millimeter == 0.001.meters) centimeter = Units.length.metric.centimeter.equals assert(centimeter.to_s == "0.01 meters") assert(centimeter == 0.01.meters) decimeter = Units.length.metric.decimeter.equals assert(decimeter.to_s == "0.1 meters") assert(decimeter == 0.1.meters) meter = Units.length.metric.meter.equals assert(meter.to_s == "1 meter") assert(meter == 1.meter) decameter = Units.length.metric.decameter.equals assert(decameter.to_s == "10.0 meters") assert(decameter == 10.meters) hectometer = Units.length.metric.hectometer.equals assert(hectometer.to_s == "100.0 meters") assert(hectometer == 100.meters) kilometer = Units.length.metric.kilometer.equals assert(kilometer.to_s == "1000.0 meters") assert(kilometer == 1000.meters) megameter = Units.length.metric.megameter.equals assert(megameter.to_s == "1000000.0 meters") assert(megameter == 1000000.meters) gigameter = Units.length.metric.gigameter.equals assert(gigameter.to_s == "1000000000.0 meters") assert(gigameter == 1000000000.meters) terameter = Units.length.metric.terameter.equals assert(terameter.to_s == "1000000000000.0 meters") assert(terameter == 1000000000000.meters) petameter = Units.length.metric.petameter.equals assert((petameter.to_s == "1.0e+15 meters")|| (petameter.to_s == "1.0e+015 meters")) assert(petameter == 1000000000000000.meters) exameter = Units.length.metric.exameter.equals assert((exameter.to_s == "1.0e+18 meters")|| (exameter.to_s == "1.0e+018 meters")) assert(exameter == 1000000000000000000.meters) zettameter = Units.length.metric.zettameter.equals assert((zettameter.to_s == "1.0e+21 meters")|| (zettameter.to_s == "1.0e+021 meters")) assert(zettameter == 1000000000000000000000.meters) yottameter = Units.length.metric.yottameter.equals assert((yottameter.to_s == "1.0e+24 meters")|| (yottameter.to_s == "1.0e+024 meters")) assert(yottameter == 1000000000000000000000000.meters) Units.create :storage do |m| m.system :base do |s| s.unit :name => :byte, :abbrev => :b, :greek => :two end end byte = Units.storage.base.byte.equals assert(byte.to_s == "1 byte") assert(byte == 1.byte) kilobyte = Units.storage.base.kilobyte.equals assert(kilobyte.to_s == "1024 bytes") assert(kilobyte == 1024.bytes) megabyte = Units.storage.base.megabyte.equals assert(megabyte.to_s == "1048576 bytes") assert(megabyte == 1048576.bytes) gigabyte = Units.storage.base.gigabyte.equals assert(gigabyte.to_s == "1073741824 bytes") assert(gigabyte == 1073741824.bytes) terabyte = Units.storage.base.terabyte.equals assert(terabyte.to_s == "1099511627776 bytes") assert(terabyte == 1099511627776.bytes) petabyte = Units.storage.base.petabyte.equals assert(petabyte.to_s == "1125899906842624 bytes") assert(petabyte == 1125899906842624.bytes) exabyte = Units.storage.base.exabyte.equals assert(exabyte.to_s == "1152921504606846976 bytes") assert(exabyte == 1152921504606846976.byte) zettabyte = Units.storage.base.zettabyte.equals assert(zettabyte.to_s == "1180591620717411303424 bytes") assert(zettabyte == 1180591620717411303424.bytes) yottabyte = Units.storage.base.yottabyte.equals assert(yottabyte.to_s == "1208925819614629174706176 bytes") assert(yottabyte == 1208925819614629174706176.bytes) end end