Skip to content

Instantly share code, notes, and snippets.

@jasonnoble
Created November 18, 2014 01:42
Show Gist options
  • Select an option

  • Save jasonnoble/7d4cca06ed8f052f1a3e to your computer and use it in GitHub Desktop.

Select an option

Save jasonnoble/7d4cca06ed8f052f1a3e to your computer and use it in GitHub Desktop.
Numbers to English
require 'rspec'
require_relative '../../lib/to_english'
describe Fixnum do
describe '#to_english' do
it 'returns one for 1' do
expect(1.to_english).to eq('one')
end
it 'returns two for 2' do
expect(2.to_english).to eq('two')
end
it 'returns three for 3' do
expect(3.to_english).to eq('three')
end
it 'returns four for 4' do
expect(4.to_english).to eq('four')
end
it 'returns five for 5' do
expect(5.to_english).to eq('five')
end
it 'returns six for 6' do
expect(6.to_english).to eq('six')
end
it 'returns seven for 7' do
expect(7.to_english).to eq('seven')
end
it 'returns eight for 8' do
expect(8.to_english).to eq('eight')
end
it 'returns nine for 9' do
expect(9.to_english).to eq('nine')
end
it 'returns ten for 10' do
expect(10.to_english).to eq('ten')
end
it 'returns eleven for 11' do
expect(11.to_english).to eq('eleven')
end
it 'returns twelve for 12' do
expect(12.to_english).to eq('twelve')
end
it 'returns thirteen for 13' do
expect(13.to_english).to eq('thirteen')
end
it 'returns fourteen for 14' do
expect(14.to_english).to eq('fourteen')
end
it 'returns fourteen for 15' do
expect(15.to_english).to eq('fifteen')
end
it 'returns eighteen for 18' do
expect(18.to_english).to eq('eighteen')
end
[
[20, 'twenty'],
[21, 'twenty one'],
[30, 'thirty'],
[31, 'thirty one'],
[40, 'fourty'],
[41, 'fourty one'],
[50, 'fifty'],
[51, 'fifty one'],
[60, 'sixty'],
[61, 'sixty one'],
[70, 'seventy'],
[71, 'seventy one'],
[80, 'eighty'],
[81, 'eighty one'],
[90, 'ninety'],
[91, 'ninety one'],
[100, 'one hundred'],
[101, 'one hundred one'],
].each do |number, english|
it "returns #{english} for #{number}" do
expect(number.to_english).to eq(english)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment