Class: LengthTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Includes:
Quantified
Defined in:
lib/vendor/quantified/test/length_test.rb

Instance Method Summary collapse

Instance Method Details

#setupObject


8
9
10
# File 'lib/vendor/quantified/test/length_test.rb', line 8

def setup
  @length = Length.new(5, :feet)
end

#test_comparison_with_numericObject


58
59
60
61
62
63
# File 'lib/vendor/quantified/test/length_test.rb', line 58

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_yardsObject


42
43
44
# File 'lib/vendor/quantified/test/length_test.rb', line 42

def test_convert_feet_to_yards
  assert Length.new(2, :yards).eql?(6.feet.to_yards)
end

#test_convert_metres_to_inchesObject


54
55
56
# File 'lib/vendor/quantified/test/length_test.rb', line 54

def test_convert_metres_to_inches
  assert_in_epsilon 1.inches.to_f, (0.0254).metres.to_inches.to_f
end

#test_convert_millimetres_to_yardsObject


50
51
52
# File 'lib/vendor/quantified/test/length_test.rb', line 50

def test_convert_millimetres_to_yards
  assert_in_epsilon Length.new(1, :yards).to_f, Length.new(914.4, :millimetres).to_yards.to_f
end

#test_convert_mm_to_inchesObject


34
35
36
# File 'lib/vendor/quantified/test/length_test.rb', line 34

def test_convert_mm_to_inches
  assert_equal 12, Length.new(304.8, :millimetres).to_inches
end

#test_convert_yards_to_feetObject


38
39
40
# File 'lib/vendor/quantified/test/length_test.rb', line 38

def test_convert_yards_to_feet
  assert 6.feet.eql?(Length.new(2, :yards).to_feet)
end

#test_convert_yards_to_millimetresObject


46
47
48
# File 'lib/vendor/quantified/test/length_test.rb', line 46

def test_convert_yards_to_millimetres
  assert_in_epsilon Length.new(914.4, :millimetres).to_f, Length.new(1, :yards).to_millimetres.to_f
end

#test_equalitiesObject


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_numericObject


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_inspectObject


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_minusObject


73
74
75
# File 'lib/vendor/quantified/test/length_test.rb', line 73

def test_method_missing_minus
  assert_equal 2.feet, 5.feet - 3.feet
end

#test_method_missing_to_fObject


69
70
71
# File 'lib/vendor/quantified/test/length_test.rb', line 69

def test_method_missing_to_f
  assert_equal 2.4, (2.4).feet.to_f
end

#test_method_missing_to_iObject


65
66
67
# File 'lib/vendor/quantified/test/length_test.rb', line 65

def test_method_missing_to_i
  assert_equal 2, (2.4).feet.to_i
end

#test_numeric_methods_not_added_for_some_unitsObject


77
78
79
80
81
82
83
84
# File 'lib/vendor/quantified/test/length_test.rb', line 77

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_systemsObject


86
87
88
89
90
91
92
93
# File 'lib/vendor/quantified/test/length_test.rb', line 86

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_sObject


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