Sha256: dfa06038e94e1b1d3e588429ad583c8be78538ec0261bbefb0d98c4678a80da7
Contents?: true
Size: 1.92 KB
Versions: 2
Compression:
Stored size: 1.92 KB
Contents
require 'test/unit' require 'test/framework' require 'eymiha/units' class TC_formatting_derived < Test::Unit::TestCase include UnitsTest def test_formatting_derived Units.create :length do |m| m.system :metric do |s| s.unit :name => :meter, :abbrev => :m, :greek => :ten end end Units.derive :volume, Units.length**3 do |m| m.system :metric do |s| s.unit :name => :milliliter, :abbrev => :ml, :equals => 1.cm**3 end end Units.create :time do |m| m.system :base do |s| s.unit :name => :second, :abbrev => :s end end assert((225.ml/5.cm) =~ (45.0.cm^2)) a = 225.ml assert(a.to_s == "225 milliliters") b = 5.cm c = 15.cm^3 assert((a/b).to_s == "45.0 cm^2") assert((b/a).to_s == "222.222222222222 1/m^2") assert((a*b).to_s == "1125.0 cm^4") ba = (b*a).to_s assert((ba == "1.125e-05 m^4")||(ba == "1.125e-005 m^4")) assert((a+c).to_s == "240.0 cm^3") assert((c+a).to_s == "0.00024 m^3") assert((a-c).to_s == "210.0 cm^3") assert((c-a).to_s == "-0.00021 m^3") assert(c.in_ml.to_s == "15.0 milliliters") c = 15.cm^7 assert(c.ml.to_s == "15.0 cm ml^2") NumericWithUnits.derived_align_type = :fractional_powers assert(c.ml.to_s == "15.0 ml^2.33333333333333") d = 15.ml^(7.0/3) assert(d =~ c) assert(c =~ d) assert(c.ml =~ d) assert(d.cm =~ c) assert(c.in_ml =~ 15.ml^(7.0/3)) d = c.to_ml assert(d.to_s == "15.0 ml^2.33333333333333") NumericWithUnits.derived_align_type = :whole_powers assert((225.ml/5.cm).to_s == '45.0 cm^2') assert((225.ml/5.cm).in_ml.to_s == '45.0 ml / cm') assert((225.ml/5.cm).align([1.cm^2]).to_s == '45.0 cm^2') assert((225.ml/5.cm).align([1.ml,1/cm]).to_s == '45.0 ml / cm') assert((225.ml/5.cm).align([1.m^2]).to_s == '0.0045 m^2') assert((225.ml/5.cm).align([1.ml,1/m]).to_s == '4500.0 ml / m') end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
eymiha_units-1.0.0 | test/tc_formatting_derived.rb |
eymiha_units-1.0.1 | test/tc_formatting_derived.rb |