Created
October 27, 2011 19:10
-
-
Save rodrigomanhaes/1320521 to your computer and use it in GitHub Desktop.
Exemplo de teste "procedural" escrito em Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Arquivo fatorial_spec.rb | |
require './fatorial' | |
describe 'fatorial' do | |
it 'calcula fatorial' do | |
fatorial(0).should == 1 | |
fatorial(1).should == 1 | |
fatorial(2).should == 2 | |
fatorial(3).should == 6 | |
fatorial(4).should == 24 | |
fatorial(5).should == 120 | |
end | |
end | |
# Arquivo fatorial.rb | |
def fatorial(n) | |
return 1 if n == 0 | |
n * fatorial(n) | |
end | |
# Para rodar: rspec fatorial_spec.rb | |
# Necessário ter instalados o Ruby e a gem rspec |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment