Created
August 7, 2010 17:51
-
-
Save caike/513021 to your computer and use it in GitHub Desktop.
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
class NotANumberException < StandardError | |
end | |
class FizzBuzz | |
def initialize(numero) | |
raise NotANumberException unless numero.is_a? Integer | |
@numero = numero | |
end | |
def calcula() | |
valor = @numero | |
if (@numero % 15 == 0) | |
valor = "FizzBuzz" | |
elsif (@numero % 3 == 0 ) | |
valor = "Fizz" | |
elsif (@numero % 5 == 0) | |
valor = "Buzz" | |
end | |
valor | |
end | |
end |
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
require 'test/unit' | |
require 'main' | |
require 'rubygems' | |
require 'redgreen' | |
class FizzBuzzTest < Test::Unit::TestCase | |
def test_fizz_buzz_recebe_um_numero | |
fizz_buzz = FizzBuzz.new(1) | |
end | |
def test_fizz_buzz_um_retorna_um | |
fizz_buzz = FizzBuzz.new(1) | |
assert_equal 1, fizz_buzz.calcula() | |
end | |
def test_fizz_buzz_tres_retorna_fizz | |
fizz_buzz = FizzBuzz.new(3) | |
assert_equal "Fizz", fizz_buzz.calcula() | |
end | |
def test_fizz_buzz_seis_retorna_fizz | |
fizz_buzz = FizzBuzz.new(6) | |
assert_equal "Fizz", fizz_buzz.calcula() | |
end | |
def test_fizz_buzz_cinco_retorna_buzz | |
fizz_buzz = FizzBuzz.new(5) | |
assert_equal "Buzz", fizz_buzz.calcula() | |
end | |
def test_fizz_buzz_quinze_retorna_fizzbuzz | |
fizz_buzz = FizzBuzz.new(15) | |
assert_equal "FizzBuzz", fizz_buzz.calcula() | |
end | |
def test_fizz_buzz_nao_recebe_string | |
#fizz_buz = FizzBuzz.new("teste") | |
assert_raises NotANumberException do | |
FizzBuzz.new("teste") | |
end | |
end | |
def test_fizz_buzz_nao_recebe_float | |
#fizz_buz = FizzBuzz.new("teste") | |
assert_raises NotANumberException do | |
FizzBuzz.new(2.2) | |
end | |
end | |
end |
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
watch(/\.rb$/) do |filw| | |
system('clear && ruby -Itest main_test.rb') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment