Class: LengthTest
- Includes:
- Quantified
- Defined in:
- lib/vendor/quantified/test/length_test.rb
Instance Method Summary collapse
- #setup ⇒ Object
- #test_comparison_with_numeric ⇒ Object
- #test_convert_feet_to_yards ⇒ Object
- #test_convert_metres_to_inches ⇒ Object
- #test_convert_millimetres_to_yards ⇒ Object
- #test_convert_yards_to_feet ⇒ Object
- #test_convert_yards_to_millimetres ⇒ Object
- #test_equalities ⇒ Object
- #test_initialize_from_numeric ⇒ Object
- #test_inspect ⇒ Object
- #test_method_missing_minus ⇒ Object
- #test_method_missing_to_f ⇒ Object
- #test_method_missing_to_i ⇒ Object
- #test_numeric_methods_not_added_for_some_units ⇒ Object
- #test_systems ⇒ Object
- #test_to_s ⇒ Object
Instance Method Details
#setup ⇒ Object
8 9 10 |
# File 'lib/vendor/quantified/test/length_test.rb', line 8 def setup @length = Length.new(5, :feet) end |
#test_comparison_with_numeric ⇒ Object
56 57 58 59 60 61 |
# File 'lib/vendor/quantified/test/length_test.rb', line 56 def test_comparison_with_numeric assert 2.feet > 1 assert 2.feet == 2 assert 2.feet <= 2 assert 2.feet < 3 end |
#test_convert_feet_to_yards ⇒ Object
38 39 40 |
# File 'lib/vendor/quantified/test/length_test.rb', line 38 def test_convert_feet_to_yards assert Length.new(2, :yards).eql?(6.feet.to_yards) end |
#test_convert_metres_to_inches ⇒ Object
50 51 52 53 54 |
# File 'lib/vendor/quantified/test/length_test.rb', line 50 def test_convert_metres_to_inches assert_equal 1.inches, (0.0254).metres.to_inches assert 1.inches.eql?((0.0254).metres.to_inches) assert 1.inches.eql?((0.0254).metres.in_inches) end |
#test_convert_millimetres_to_yards ⇒ Object
46 47 48 |
# File 'lib/vendor/quantified/test/length_test.rb', line 46 def test_convert_millimetres_to_yards assert Length.new(1, :yards).eql?(Length.new(914.4, :millimetres).to_yards) end |
#test_convert_yards_to_feet ⇒ Object
34 35 36 |
# File 'lib/vendor/quantified/test/length_test.rb', line 34 def test_convert_yards_to_feet assert 6.feet.eql?(Length.new(2, :yards).to_feet) end |
#test_convert_yards_to_millimetres ⇒ Object
42 43 44 |
# File 'lib/vendor/quantified/test/length_test.rb', line 42 def test_convert_yards_to_millimetres assert Length.new(914.4, :millimetres).eql?(Length.new(1, :yards).to_millimetres) end |
#test_equalities ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/vendor/quantified/test/length_test.rb', line 24 def test_equalities assert_equal 1.feet, (1.0).feet # == based on value assert_equal 6.feet, Length.new(2, :yards) # eql? based on value and unit assert !6.feet.eql?(Length.new(2, :yards)) # equal? based on object identity assert !2.feet.equal?(2.feet) end |
#test_initialize_from_numeric ⇒ Object
20 21 22 |
# File 'lib/vendor/quantified/test/length_test.rb', line 20 def test_initialize_from_numeric assert_equal "5 feet", 5.feet.to_s end |
#test_inspect ⇒ Object
12 13 14 |
# File 'lib/vendor/quantified/test/length_test.rb', line 12 def test_inspect assert_equal "#<Quantified::Length: 5 feet>", @length.inspect end |
#test_method_missing_minus ⇒ Object
71 72 73 |
# File 'lib/vendor/quantified/test/length_test.rb', line 71 def test_method_missing_minus assert_equal 2.feet, 5.feet - 3.feet end |
#test_method_missing_to_f ⇒ Object
67 68 69 |
# File 'lib/vendor/quantified/test/length_test.rb', line 67 def test_method_missing_to_f assert_equal 2.4, (2.4).feet.to_f end |
#test_method_missing_to_i ⇒ Object
63 64 65 |
# File 'lib/vendor/quantified/test/length_test.rb', line 63 def test_method_missing_to_i assert_equal 2, (2.4).feet.to_i end |
#test_numeric_methods_not_added_for_some_units ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'lib/vendor/quantified/test/length_test.rb', line 75 def test_numeric_methods_not_added_for_some_units assert_raises NoMethodError do 2.yards end assert_raises NoMethodError do 2.millimetres end end |
#test_systems ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'lib/vendor/quantified/test/length_test.rb', line 84 def test_systems assert_equal [:metric, :imperial], Length.systems assert_equal [:metres, :centimetres, :millimetres, :kilometres], Length.units(:metric) assert_equal [:inches, :feet, :yards, :miles], Length.units(:imperial) assert_equal :metric, 2.centimetres.system assert_equal :imperial, 2.feet.system end |
#test_to_s ⇒ Object
16 17 18 |
# File 'lib/vendor/quantified/test/length_test.rb', line 16 def test_to_s assert_equal "5 feet", @length.to_s end |