Python – Dojo – Bissextile Year

This week we are starting to do Dojo’s session in the company that I am working. To do a little warm up the first Dojo Exercise was to identify when a year is Bissextile (see http://en.wikipedia.org/wiki/Leap_year).

bissexto-test.py

import unittest
from bissexto import bissexto

class bissexto_test(unittest.TestCase):
    def test_bissexto(self):
        self.assertEqual(bissexto(1600),True)
        self.assertEqual(bissexto(1732),True)
        self.assertEqual(bissexto(1888),True)
        self.assertEqual(bissexto(1944),True)
        self.assertEqual(bissexto(2008),True)

    def test_nao_bissexto(self):
        self.assertEqual(bissexto(1742),False)
        self.assertEqual(bissexto(1889),False)
        self.assertEqual(bissexto(1951),False)
        self.assertEqual(bissexto(2011),False)

if __name__ == "__main__":
    unittest.main()

 
bissexto.py

# -*- coding: utf-8 -*-

def bissexto(year):
    if year % 400 == 0 or (year % 4 == 0 and year % 100 != 0):
        return True
    else:
        return False

if __name__ == "__main__":
    bissexto(2000)

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *