2013-08-02 12:03:27 -05:00
|
|
|
import unittest
|
|
|
|
|
|
2021-01-31 16:49:12 -05:00
|
|
|
from leap import (
|
|
|
|
|
leap_year,
|
|
|
|
|
)
|
2014-06-11 15:06:22 +02:00
|
|
|
|
2020-10-15 12:46:24 -04:00
|
|
|
# Tests adapted from `problem-specifications//canonical-data.json`
|
2013-08-02 12:03:27 -05:00
|
|
|
|
2019-04-03 14:43:14 +01:00
|
|
|
|
2018-06-13 09:12:09 -04:00
|
|
|
class LeapTest(unittest.TestCase):
|
2019-08-16 11:41:55 -04:00
|
|
|
def test_year_not_divisible_by_4_in_common_year(self):
|
2019-05-30 06:10:31 -07:00
|
|
|
self.assertIs(leap_year(2015), False)
|
2013-08-02 12:03:27 -05:00
|
|
|
|
2019-08-16 11:41:55 -04:00
|
|
|
def test_year_divisible_by_2_not_divisible_by_4_in_common_year(self):
|
2019-05-30 06:10:31 -07:00
|
|
|
self.assertIs(leap_year(1970), False)
|
2019-03-25 09:02:07 -05:00
|
|
|
|
2019-08-16 11:41:55 -04:00
|
|
|
def test_year_divisible_by_4_not_divisible_by_100_in_leap_year(self):
|
2019-05-30 06:10:31 -07:00
|
|
|
self.assertIs(leap_year(1996), True)
|
2014-04-22 21:58:09 -06:00
|
|
|
|
2019-09-19 11:00:28 -04:00
|
|
|
def test_year_divisible_by_4_and_5_is_still_a_leap_year(self):
|
|
|
|
|
self.assertIs(leap_year(1960), True)
|
|
|
|
|
|
2019-08-16 11:41:55 -04:00
|
|
|
def test_year_divisible_by_100_not_divisible_by_400_in_common_year(self):
|
2019-05-30 06:10:31 -07:00
|
|
|
self.assertIs(leap_year(2100), False)
|
2014-04-22 21:58:09 -06:00
|
|
|
|
2019-09-19 11:00:28 -04:00
|
|
|
def test_year_divisible_by_100_but_not_by_3_is_still_not_a_leap_year(self):
|
|
|
|
|
self.assertIs(leap_year(1900), False)
|
|
|
|
|
|
2021-01-31 16:49:12 -05:00
|
|
|
def test_year_divisible_by_400_is_leap_year(self):
|
2019-05-30 06:10:31 -07:00
|
|
|
self.assertIs(leap_year(2000), True)
|
2013-08-02 12:03:27 -05:00
|
|
|
|
2019-09-19 11:00:28 -04:00
|
|
|
def test_year_divisible_by_400_but_not_by_125_is_still_a_leap_year(self):
|
|
|
|
|
self.assertIs(leap_year(2400), True)
|
|
|
|
|
|
2019-08-16 11:41:55 -04:00
|
|
|
def test_year_divisible_by_200_not_divisible_by_400_in_common_year(self):
|
2019-05-30 06:10:31 -07:00
|
|
|
self.assertIs(leap_year(1800), False)
|
2018-11-01 16:45:46 +01:00
|
|
|
|
2016-11-29 09:44:47 +01:00
|
|
|
|
2019-08-16 11:41:55 -04:00
|
|
|
if __name__ == "__main__":
|
2013-08-02 12:03:27 -05:00
|
|
|
unittest.main()
|