Skip to content

Instantly share code, notes, and snippets.

@jaksonmoura
Created October 3, 2011 15:59
Show Gist options
  • Select an option

  • Save jaksonmoura/1259445 to your computer and use it in GitHub Desktop.

Select an option

Save jaksonmoura/1259445 to your computer and use it in GitHub Desktop.
Bissexto
class Bissexto
def bissexto(ano)
if inteiro(ano)
if ano % 4 == 0 && ano % 100 != 0 || ano % 400 == 0
return true
end
return false
else
return nil
end
end
def inteiro(int)
return int.is_a? Integer
end
end
require 'test/unit'
require './Bissexto'
class TestBissexto < Test::Unit::TestCase
def setup
@b = Bissexto.new
end
def teardown
@b = nil
end
#
def test_ano_int
assert_equal(true, @b.inteiro(1), "É inteiro!")
end
#
def test_bissexto
assert_equal(true, @b.bissexto(1600))
assert_equal(true, @b.bissexto(1732))
assert_equal(true, @b.bissexto(1888))
assert_equal(true, @b.bissexto(1944))
assert_equal(true, @b.bissexto(2008))
assert_equal(false, @b.bissexto(1742))
assert_equal(false, @b.bissexto(1889))
assert_equal(false, @b.bissexto(1951))
assert_equal(false, @b.bissexto(2011))
assert_equal(nil, @b.bissexto("oi!"))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment