Class: MassTest

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

Instance Method Summary collapse

Instance Method Details

#setupObject



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

def setup
  @mass = Mass.new(5, :pounds)
end

#test_comparison_with_numericObject



55
56
57
58
59
60
# File 'lib/vendor/quantified/test/mass_test.rb', line 55

def test_comparison_with_numeric
  assert 2.pounds > 1
  assert 2.pounds == 2
  assert 2.pounds <= 2
  assert 2.pounds < 3
end

#test_convert_grams_to_ouncesObject



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

def test_convert_grams_to_ounces
  assert 1.ounces.eql?((28.349523125).grams.to_ounces)
  assert 1.ounces.eql?((28.349523125).grams.in_ounces)
end

#test_convert_milligrams_to_short_tonsObject



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

def test_convert_milligrams_to_short_tons
  assert Mass.new(1, :short_tons).eql?(Mass.new(907_184_740, :milligrams).to_short_tons)
end

#test_convert_pounds_to_short_tonsObject



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

def test_convert_pounds_to_short_tons
  assert Mass.new(2, :short_tons).eql?(4000.pounds.to_short_tons)
end

#test_convert_short_tons_to_milligramsObject



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

def test_convert_short_tons_to_milligrams
  assert Mass.new(907_184_740, :milligrams).eql?(Mass.new(1, :short_tons).to_milligrams)
end

#test_convert_short_tons_to_poundsObject



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

def test_convert_short_tons_to_pounds
  assert 4000.pounds.eql?(Mass.new(2, :short_tons).to_pounds)
end

#test_equalitiesObject



24
25
26
27
28
29
30
31
32
# File 'lib/vendor/quantified/test/mass_test.rb', line 24

def test_equalities
  assert_equal 1.pounds, (1.0).pounds
  # == based on value
  assert_equal 4000.pounds, Mass.new(2, :short_tons)
  # eql? based on value and unit
  assert !4000.pounds.eql?(Mass.new(2, :short_tons))
  # equal? based on object identity
  assert !2.pounds.equal?(2.pounds)
end

#test_initialize_from_numericObject



20
21
22
# File 'lib/vendor/quantified/test/mass_test.rb', line 20

def test_initialize_from_numeric
  assert_equal "5 pounds", 5.pounds.to_s
end

#test_inspectObject



12
13
14
# File 'lib/vendor/quantified/test/mass_test.rb', line 12

def test_inspect
  assert_equal "#<Quantified::Mass: 5 pounds>", @mass.inspect
end

#test_method_missing_minusObject



70
71
72
# File 'lib/vendor/quantified/test/mass_test.rb', line 70

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

#test_method_missing_to_fObject



66
67
68
# File 'lib/vendor/quantified/test/mass_test.rb', line 66

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

#test_method_missing_to_iObject



62
63
64
# File 'lib/vendor/quantified/test/mass_test.rb', line 62

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

#test_numeric_methods_not_added_for_some_unitsObject



74
75
76
77
78
79
80
81
# File 'lib/vendor/quantified/test/mass_test.rb', line 74

def test_numeric_methods_not_added_for_some_units
  assert_raises NoMethodError do
    2.short_tons
  end
  assert_raises NoMethodError do
    2.milligrams
  end
end

#test_systemsObject



83
84
85
86
87
# File 'lib/vendor/quantified/test/mass_test.rb', line 83

def test_systems
  assert_equal [:metric, :imperial], Mass.systems
  assert_equal [:grams, :milligrams, :kilograms], Mass.units(:metric)
  assert_equal [:ounces, :pounds, :stones, :short_tons], Mass.units(:imperial)
end

#test_to_sObject



16
17
18
# File 'lib/vendor/quantified/test/mass_test.rb', line 16

def test_to_s
  assert_equal "5 pounds", @mass.to_s
end