Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Added a furlongs to km method with two additional tests. #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion furlong.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
class Furlong

KM_PER_MILE = 1.60934
FURLONG_PER_KM = 0.201168
def miles_to_kilometers(miles)
miles * KM_PER_MILE
end
end

def furlongs_to_kilometers(furlong)
furlong * FURLONG_PER_KM
end
end
12 changes: 10 additions & 2 deletions furlong_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@
describe Furlong do

let(:calculator) { Furlong.new }

it "converts 1 mile to 1.60934 km" do
subject.miles_to_kilometers(1).should be_within(0.0001).of(1.60934)
end

it "converts a marathon: 26.219 miles to 42.194988 km" do
subject.miles_to_kilometers(26.219).should be_within(0.001).of(42.194988)
end
end

it "converts 1 furlong to 0.201168 km" do
subject.furlongs_to_kilometers(1).should be_within(0.0001).of(0.201168)
end

it "converts 5 furlongs to approx. a km" do
subject.furlongs_to_kilometers(5).should be_within(0.0001).of(1.00584)
end
end