Sha256: 6e95c3508e2f34f2f008453db3adaf6395830dce127d999e4ba7627c3713ec0b
Contents?: true
Size: 1.44 KB
Versions: 2
Compression:
Stored size: 1.44 KB
Contents
require File.dirname(__FILE__) + '/test_helper' class UnitTest < Test::Unit::TestCase def test_exchange_rate assert_in_delta 1.609344, Conversions::Unit.exchange_rate(:miles, :kilometres), DELTA assert_in_delta 0.621371192237334, Conversions::Unit.exchange_rate(:kilometres, :miles), DELTA assert_raises(ArgumentError) { Conversions::Unit.exchange_rate(:unknown, :miles) } assert_raises(ArgumentError) { Conversions::Unit.exchange_rate(:miles, :unknown) } assert_raises(ArgumentError) { Conversions::Unit.exchange_rate(nil, :miles) } assert_raises(ArgumentError) { Conversions::Unit.exchange_rate(:miles, nil) } end def test_exchange_rate_for_identity_transform Conversions::Unit.conversion.keys.each do |unit| assert_equal 1, Conversions::Unit.exchange_rate(unit, unit) end end def test_to amount = Conversions::Unit.new(10.0, :miles) assert_in_delta 16.09344, amount.to(:kilometres), DELTA amount = Conversions::Unit.new(10.0, :miles) assert_equal 16.09, amount.to(:kilometres, 2), DELTA amount = Conversions::Unit.new(10.0, :kilograms) assert_in_delta 22.0462262184878, amount.to(:pounds), DELTA amount = Conversions::Unit.new(10.0, :kilograms) assert_equal 22.05, amount.to(:pounds, 2), DELTA end def test_identity_transforms Conversions::Unit.conversion.keys.each do |unit| assert_equal 1.0, Conversions::Unit.new(1.0, unit).to(unit, 2) end end end
Version data entries
2 entries across 2 versions & 2 rubygems
Version | Path |
---|---|
Fingertips-conversions-1.2.1 | test/unit_test.rb |
seamusabshere-conversions-1.2 | test/unit_test.rb |