Class: TemperatureTest
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- TemperatureTest
show all
- Defined in:
- ext/cargo-vendor/magnus-0.7.1/examples/complete_object/test/temperature_test.rb
Defined Under Namespace
Classes: OffsetTemperature
Instance Method Summary
collapse
Instance Method Details
#test_clone ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'ext/cargo-vendor/magnus-0.7.1/examples/complete_object/test/temperature_test.rb', line 49
def test_clone
temp = Temperature.new(celsius: 19.5)
def temp.singlton_method_example
end
copy = temp.clone
assert { temp.object_id != copy.object_id }
assert { temp == copy }
assert { !copy.frozen? }
assert { copy.respond_to?(:singlton_method_example)}
temp2 = Temperature.new(celsius: 19.5)
temp2.freeze
copy2 = temp2.clone
assert { copy2.frozen? }
temp3 = Temperature.new(celsius: 19.5)
copy3 = temp3.clone(freeze: true)
assert { copy3.frozen? }
temp4 = Temperature.new(celsius: 19.5)
temp4.freeze
copy4 = temp4.clone(freeze: false)
assert { !copy4.frozen? }
end
|
#test_dup ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'ext/cargo-vendor/magnus-0.7.1/examples/complete_object/test/temperature_test.rb', line 32
def test_dup
temp = Temperature.new(celsius: 19.5)
def temp.singlton_method_example
end
copy = temp.dup
assert { temp.object_id != copy.object_id }
assert { temp == copy }
assert { !copy.frozen? }
assert { !copy.respond_to?(:singlton_method_example)}
temp2 = Temperature.new(celsius: 19.5)
temp2.freeze
copy2 = temp2.dup
assert { !copy2.frozen? }
end
|
#test_hash ⇒ Object
75
76
77
78
79
80
81
82
83
|
# File 'ext/cargo-vendor/magnus-0.7.1/examples/complete_object/test/temperature_test.rb', line 75
def test_hash
freezing = Temperature.new(celsius: 0)
boiling = Temperature.new(celsius: 100)
hash = {freezing => :cold, boiling => :hot}
assert { hash[Temperature.new(fahrenheit: 32)] == :cold }
assert { hash[Temperature.new(fahrenheit: 212)] == :hot }
end
|
#test_inspect ⇒ Object
94
95
96
|
# File 'ext/cargo-vendor/magnus-0.7.1/examples/complete_object/test/temperature_test.rb', line 94
def test_inspect
assert { Temperature.new(celsius: 19.5).inspect == "Temperature { microkelvin: RefCell { value: 292650000 } }" }
end
|
#test_new ⇒ Object
8
9
10
11
12
|
# File 'ext/cargo-vendor/magnus-0.7.1/examples/complete_object/test/temperature_test.rb', line 8
def test_new
assert { Temperature.new(kelvin: 292.65).to_kelvin == 292.65 }
assert { Temperature.new(celsius: 19.5).to_celsius == 19.5 }
assert { Temperature.new(fahrenheit: 67.1).to_fahrenheit == 67.1 }
end
|
#test_sort ⇒ Object
85
86
87
88
89
90
91
92
|
# File 'ext/cargo-vendor/magnus-0.7.1/examples/complete_object/test/temperature_test.rb', line 85
def test_sort
temps = [Temperature.new(celsius: 25), Temperature::new(fahrenheit: 80), Temperature::new(kelvin: 273.15)]
assert { temps.sort == [Temperature::new(kelvin: 273.15), Temperature.new(celsius: 25), Temperature::new(fahrenheit: 80)] }
assert { Temperature.new(celsius: 40) > Temperature.new(fahrenheit: 90)}
assert { Temperature.new(fahrenheit: 32) < Temperature.new(celsius: 1)}
assert { Temperature.new(celsius: -40) == Temperature.new(fahrenheit: -40 )}
end
|
#test_subclass ⇒ Object
111
112
113
|
# File 'ext/cargo-vendor/magnus-0.7.1/examples/complete_object/test/temperature_test.rb', line 111
def test_subclass
assert { OffsetTemperature.new(2,celsius: 19.5).to_s == "21.5°C" }
end
|
#test_to_celsius ⇒ Object
20
21
22
23
24
|
# File 'ext/cargo-vendor/magnus-0.7.1/examples/complete_object/test/temperature_test.rb', line 20
def test_to_celsius
assert { Temperature.new(kelvin: 292.65).to_celsius == 19.5 }
assert { Temperature.new(celsius: 19.5).to_celsius == 19.5 }
assert { Temperature.new(fahrenheit: 67.1).to_celsius == 19.5 }
end
|
#test_to_fahrenheit ⇒ Object
26
27
28
29
30
|
# File 'ext/cargo-vendor/magnus-0.7.1/examples/complete_object/test/temperature_test.rb', line 26
def test_to_fahrenheit
assert { Temperature.new(kelvin: 292.65).to_fahrenheit == 67.1 }
assert { Temperature.new(celsius: 19.5).to_fahrenheit == 67.1 }
assert { Temperature.new(fahrenheit: 67.1).to_fahrenheit == 67.1 }
end
|
#test_to_kelvin ⇒ Object
14
15
16
17
18
|
# File 'ext/cargo-vendor/magnus-0.7.1/examples/complete_object/test/temperature_test.rb', line 14
def test_to_kelvin
assert { Temperature.new(kelvin: 292.65).to_kelvin == 292.65 }
assert { Temperature.new(celsius: 19.5).to_kelvin == 292.65 }
assert { Temperature.new(fahrenheit: 67.1).to_kelvin == 292.65 }
end
|
#test_to_s ⇒ Object
98
99
100
|
# File 'ext/cargo-vendor/magnus-0.7.1/examples/complete_object/test/temperature_test.rb', line 98
def test_to_s
assert { Temperature.new(celsius: 19.5).to_s == "19.5°C" }
end
|