Sha256: 892766bf8739739a210302eff4e6c6667d48ae25de5cd32a9e438f1ecb96023a
Contents?: true
Size: 1.23 KB
Versions: 2
Compression:
Stored size: 1.23 KB
Contents
require 'test/unit' require 'test/framework' require 'eymiha/units' class TC_formatting < Test::Unit::TestCase include UnitsTest def test_fractions 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 s.unit :name => :mile, :abbrevs => :mi, :equals => 1760.yards s.format :name => :feet_inches_and_32s, :format => lambda { |u| ru = u.inch.round_to_nearest 32 feet = ru.feet.floor inches = (ru-feet).inches "#{feet} #{inches.with_fraction 32}" } end end l = 13.28090635.ft assert(l.measure == Units.length) assert(3.46875.with_fraction(32) == "3-15/32") assert(l.format(:feet_inches_and_32s) == "13 feet 3-12/32 inches") almost = 1.999.ft assert(almost.inch.round_to_nearest(32) == 24.0.in) almost = 1.996.ft assert(almost.inch.round_to_nearest(32) == 23.9375.in) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
eymiha_units-1.0.0 | test/tc_formatting.rb |
eymiha_units-1.0.1 | test/tc_formatting.rb |