Skip to content

Instantly share code, notes, and snippets.

@elliotcm
Created February 12, 2011 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elliotcm/823763 to your computer and use it in GitHub Desktop.
Save elliotcm/823763 to your computer and use it in GitHub Desktop.
require 'fixnum'
describe Fixnum, 'when converting to Roman numerals' do
context "up to 5" do
it "represents units with I" do
1.to_roman_numerals.should == 'I'
2.to_roman_numerals.should == 'II'
3.to_roman_numerals.should == 'III'
end
it 'represents 4 with IV' do
4.to_roman_numerals.should == 'IV'
end
end
context "at 5" do
it "is represented by V" do
5.to_roman_numerals.should == 'V'
end
end
context "beyond 5" do
it "appends extra units to the end" do
6.to_roman_numerals.should == 'VI'
7.to_roman_numerals.should == 'VII'
8.to_roman_numerals.should == 'VIII'
end
it "represents 9 with IX" do
9.to_roman_numerals.should == 'IX'
end
end
context "10" do
it "is represented by X" do
10.to_roman_numerals.should == 'X'
end
end
context "beyond 10" do
it "appends fives and units to the end" do
11.to_roman_numerals.should == 'XI'
14.to_roman_numerals.should == 'XIV'
15.to_roman_numerals.should == 'XV'
16.to_roman_numerals.should == 'XVI'
end
it "represents 19 with IXX" do
19.to_roman_numerals.should == 'IXX'
end
end
context "beyond 20" do
it "represented by multiples of X, appending fives and units to the end" do
21.to_roman_numerals.should == 'XXI'
25.to_roman_numerals.should == 'XXV'
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment