Skip to content

Instantly share code, notes, and snippets.

@fsouza
Created November 20, 2010 13:17
Show Gist options
  • Save fsouza/707815 to your computer and use it in GitHub Desktop.
Save fsouza/707815 to your computer and use it in GitHub Desktop.
class Lcd
def gera_display(numero)
array = []
numero.to_s.each_char do |num|
array << self.gera_matriz(num.to_i)
end
retorno = "\n"
3.times do |i|
array.each do |item|
retorno << item[i][0] + item[i][1] + item[i][2]
end
retorno << "\n"
end
retorno
end
def gera_matriz(numero)
case numero
when 0
[
[' ', '_', ' '],
['|', ' ', '|'],
['|', '_', '|']
]
when 1
[
[' ', ' ', ' '],
[' ', ' ', '|'],
[' ', ' ', '|']
]
when 2
[
[' ', '_', ' '],
[' ', '_', '|'],
['|', '_', ' ']
]
when 3
[
[' ', '_', ' '],
[' ', '_', '|'],
[' ', '_', '|']
]
when 4
[
[' ', ' ', ' '],
['|', '_', '|'],
[' ', ' ', '|']
]
when 5
[
[' ', '_', ' '],
['|', '_', ' '],
[' ', '_', '|']
]
when 6
[
[' ', '_', ' '],
['|', '_', ' '],
['|', '_', '|']
]
when 7
[
[' ', '_', ' '],
[' ', ' ', '|'],
[' ', ' ', '|']
]
when 8
[
[' ', '_', ' '],
['|', '_', '|'],
['|', '_', '|']
]
when 9
[
[' ', '_', ' '],
['|', '_', '|'],
[' ', '_', '|']
]
end
end
end
require 'rspec'
require 'lcd'
describe Lcd do
before :each do
@lcd = Lcd.new
end
it 'deveria retornar uma matriz quando informar 8' do
@lcd.gera_matriz(8).should == [
[' ', '_', ' '],
['|', '_', '|'],
['|', '_', '|']
]
end
it 'deveria retornar uma matriz informar 1' do
@lcd.gera_matriz(1).should == [
[' ', ' ', ' '],
[' ', ' ', '|'],
[' ', ' ', '|']
]
end
it 'deveria retornar uma matriz informar 3' do
@lcd.gera_matriz(3).should == [
[' ', '_', ' '],
[' ', '_', '|'],
[' ', '_', '|']
]
end
it 'deveria retornar uma matriz informar 7' do
@lcd.gera_matriz(7).should == [
[' ', '_', ' '],
[' ', ' ', '|'],
[' ', ' ', '|']
]
end
it 'deveria retornar a string abaixo quando informar 123456789' do
@lcd.gera_display(123456789).should == '
_ _ _ _ _ _ _
| _| _||_||_ |_ ||_||_|
||_ _| | _||_| ||_| _|
'
end
it 'deveria retornar a string abaixo quando informar 490067715' do
@lcd.gera_display(490067715).should == '
_ _ _ _ _ _ _
|_||_|| || ||_ | | ||_
| _||_||_||_| | | | _|
'
end
it 'deveria retornar a string abaixo quando informar 777777177' do
@lcd.gera_display(777777177).should == '
_ _ _ _ _ _ _ _
| | | | | | | | |
| | | | | | | | |
'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment