2017-08-15

This commit is contained in:
2017-08-15 09:55:28 -05:00
parent 549ba5084e
commit 4a9b690bb2
28 changed files with 1153 additions and 18 deletions

1
python/leap/.cache/v/cache/lastfailed vendored Normal file
View File

@@ -0,0 +1 @@
{}

44
python/leap/README.md Normal file
View File

@@ -0,0 +1,44 @@
# Leap
Given a year, report if it is a leap year.
The tricky thing here is that a leap year in the Gregorian calendar occurs:
```plain
on every year that is evenly divisible by 4
except every year that is evenly divisible by 100
unless the year is also evenly divisible by 400
```
For example, 1997 is not a leap year, but 1996 is. 1900 is not a leap
year, but 2000 is.
If your language provides a method in the standard library that does
this look-up, pretend it doesn't exist and implement it yourself.
## Notes
Though our exercise adopts some very simple rules, there is more to
learn!
For a delightful, four minute explanation of the whole leap year
phenomenon, go watch [this youtube video][video].
[video]: http://www.youtube.com/watch?v=xX96xng7sAE
### Submitting Exercises
Note that, when trying to submit an exercise, make sure the solution is in the `exercism/python/<exerciseName>` directory.
For example, if you're submitting `bob.py` for the Bob exercise, the submit command would be something like `exercism submit <path_to_exercism_dir>/python/bob/bob.py`.
For more detailed information about running tests, code style and linting,
please see the [help page](http://exercism.io/languages/python).
## Source
JavaRanch Cattle Drive, exercise 3 [http://www.javaranch.com/leap.jsp](http://www.javaranch.com/leap.jsp)
## Submitting Incomplete Solutions
It's possible to submit an incomplete solution so you can see how others have completed the exercise.

Binary file not shown.

2
python/leap/leap.py Normal file
View File

@@ -0,0 +1,2 @@
def is_leap_year(yr):
return yr % 4 == 0 and (yr % 100 != 0 or yr % 400 == 0)

23
python/leap/leap_test.py Normal file
View File

@@ -0,0 +1,23 @@
import unittest
from leap import is_leap_year
# test cases adapted from `x-common//canonical-data.json` @ version: 1.0.0
class YearTest(unittest.TestCase):
def test_year_not_divisible_by_4(self):
self.assertFalse(is_leap_year(2015))
def test_year_divisible_by_4_not_divisible_by_100(self):
self.assertTrue(is_leap_year(2016))
def test_year_divisible_by_100_not_divisible_by_400(self):
self.assertFalse(is_leap_year(2100))
def test_year_divisible_by_400(self):
self.assertTrue(is_leap_year(2000))
if __name__ == '__main__':
unittest.main()