Skip to content

Instantly share code, notes, and snippets.

@alexch
Forked from anonymous/gist:173973
Created August 24, 2009 17:28
Show Gist options
  • Save alexch/173975 to your computer and use it in GitHub Desktop.
Save alexch/173975 to your computer and use it in GitHub Desktop.
class Temperature
def ftoc(f)
(f-32) * (5.0/9.0)
end
def ctof(c)
c * (9.0/5.0) + 32
end
end
require "#{File.dirname(__FILE__)}/temperature"
describe Temperature do
before do
@temperature = Temperature.new
end
describe "#ftoc" do
it "converts freezing temperature" do
@temperature.ftoc(32).should == 0
end
it "converts boiling temperature" do
@temperature.ftoc(212).should == 100
end
it "converts body temperature" do
@temperature.ftoc(98.6).should == 37
end
it "converts arbitrary temperature" do
@temperature.ftoc(68).should == 20
end
end
describe "#ctof" do
it "converts freezing temperature" do
@temperature.ctof(0).should == 32
end
it "converts boiling temperature" do
@temperature.ctof(100).should == 212
end
it "converts arbitrary temperature" do
@temperature.ctof(20).should == 68
end
it "converts body temperature" do
t = @temperature.ctof(37)
(t*10).round.should == 986 # see http://www.ruby-forum.com/topic/169330#742994
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment