forked from alexch/learn_ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
113 lines (91 loc) · 3.64 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<html>
<head>
<title>Test-First Teaching: learn_ruby: temperature</title>
<link href="../assets/style.css" media="screen" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="header">
<h1><a href="http://testfirst.org">TestFirst.org</a></h1>
<h2>the home of test-first teaching</h2>
</div>
<div class="nav">
<h2><a href="../index.html">learn_ruby</a></h2>
<b>Labs:</b>
<ul>
<li><a href="../00_hello/index.html">00 Hello</a></li>
<li>01 Temperature</li>
<li><a href="../02_calculator/index.html">02 Calculator</a></li>
<li><a href="../03_simon_says/index.html">03 Simon Says</a></li>
<li><a href="../04_pig_latin/index.html">04 Pig Latin</a></li>
<li><a href="../05_silly_blocks/index.html">05 Silly Blocks</a></li>
<li><a href="../06_performance_monitor/index.html">06 Performance Monitor</a></li>
<li><a href="../07_hello_friend/index.html">07 Hello Friend</a></li>
<li><a href="../08_book_titles/index.html">08 Book Titles</a></li>
<li><a href="../09_timer/index.html">09 Timer</a></li>
<li><a href="../10_temperature_object/index.html">10 Temperature Object</a></li>
<li><a href="../11_dictionary/index.html">11 Dictionary</a></li>
<li><a href="../12_rpn_calculator/index.html">12 Rpn Calculator</a></li>
<li><a href="../13_xml_document/index.html">13 Xml Document</a></li>
<li><a href="../14_array_extensions/index.html">14 Array Extensions</a></li>
<li><a href="../15_in_words/index.html">15 In Words</a></li>
</ul>
</div>
<h1>temperature</h1>
<div class="content"><div class="rspec_file"> <div class="intro"><h1>Topics:</h1>
<ul>
<li>functions</li>
<li>floating-point math</li>
</ul>
<h1>Hints</h1>
<p>Remember that one degree fahrenheit is 5/9 of one degree celsius, and that the freezing point of water is 0 degrees celsius but 32 degrees fahrenheit.</p>
<p>In integer math, there <strong>are no fractions</strong>. So if you are using integer literals, you will be using integer math, which means, for example...</p>
<p> 1 / 2 => 0</p>
<p>In floating point math, there <strong>are</strong> fractions. So...</p>
<p> 1.0 / 2.0 => 0.5</p>
</div>
<div class="tests">
<h1>Tests</h1>
<a class="raw_file" href="temperature_spec.rb">temperature_spec.rb</a>
<pre>
require "temperature"
describe "temperature conversion functions" do
describe "#ftoc" do
it "converts freezing temperature" do
ftoc(32).should == 0
end
it "converts boiling temperature" do
ftoc(212).should == 100
end
it "converts body temperature" do
ftoc(98.6).should == 37
end
it "converts arbitrary temperature" do
ftoc(68).should == 20
end
end
describe "#ctof" do
it "converts freezing temperature" do
ctof(0).should == 32
end
it "converts boiling temperature" do
ctof(100).should == 212
end
it "converts arbitrary temperature" do
ctof(20).should == 68
end
it "converts body temperature" do
ctof(37).should be_within(0.1).of(98.6)
# Why do we need to use be_within?
# See http://www.ruby-forum.com/topic/169330
# and http://en.wikipedia.org/wiki/IEEE_754-2008
# and http://en.wikipedia.org/wiki/Double_precision_floating-point_format
# Also, try "puts 0.5 - 0.4 - 0.1" -- pretty crazy, right?
end
end
end</pre>
</div>
</div>
</div>
<div class="footer"><a href="http://testfirst.org">TestFirst.org</a></div>
</body>
</html>