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



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_yardsObject



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_inchesObject



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_yardsObject



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_feetObject



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_millimetresObject



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_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



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_fObject



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_iObject



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_unitsObject



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_systemsObject



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_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