Created
October 3, 2011 15:59
-
-
Save jaksonmoura/1259445 to your computer and use it in GitHub Desktop.
Bissexto
This file contains hidden or 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 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 |
This file contains hidden or 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 './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