Skip to content

Commit

Permalink
Merge pull request #774 from pganssle/add_mlk_day_solution
Browse files Browse the repository at this point in the history
Add solution to Martin Luther King Day exercise
  • Loading branch information
pganssle committed Oct 25, 2018
2 parents 937773a + 09a6f41 commit d9aaa11
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/exercises/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ If you are interested in helping improve the documentation of ``dateutil``, it i
:local:


.. _mlk-day-exercise:

Martin Luther King Day
--------------------------------

Expand Down Expand Up @@ -66,6 +68,7 @@ To solve this exercise, copy-paste this script into a document, change anything

</details>

A solution to this problem is provided :doc:`here <solutions/mlk-day-rrule>`.


Next Monday meeting
Expand Down
11 changes: 11 additions & 0 deletions docs/exercises/solutions/mlk-day-rrule.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
:orphan:

Martin Luther King Day: Solution
================================

Presented here is a solution to the :ref:`Martin Luther King Day exercises <mlk-day-exercise>`.


.. include:: mlk_day_rrule_solution.py
:code: python3

40 changes: 40 additions & 0 deletions docs/exercises/solutions/mlk_day_rrule_solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# ------- YOUR CODE -------------#
from dateutil import rrule
from datetime import datetime

MLK_DAY = rrule.rrule(
dtstart=datetime(1986, 1, 20), # First celebration
freq=rrule.YEARLY, # Occurs once per year
bymonth=1, # In January
byweekday=rrule.MO(+3), # On the 3rd Monday
)

# -------------------------------#

from datetime import datetime

MLK_TEST_CASES = [
((datetime(1970, 1, 1), datetime(1980, 1, 1)),
[]),
((datetime(1980, 1, 1), datetime(1989, 1, 1)),
[datetime(1986, 1, 20),
datetime(1987, 1, 19),
datetime(1988, 1, 18)]),
((datetime(2017, 2, 1), datetime(2022, 2, 1)),
[datetime(2018, 1, 15, 0, 0),
datetime(2019, 1, 21, 0, 0),
datetime(2020, 1, 20, 0, 0),
datetime(2021, 1, 18, 0, 0),
datetime(2022, 1, 17, 0, 0)]
),
]


def test_mlk_day():
for (between_args, expected) in MLK_TEST_CASES:
assert MLK_DAY.between(*between_args) == expected


if __name__ == "__main__":
test_mlk_day()
print('Success!')
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ universal = 1
license_file = LICENSE

[tool:pytest]
python_files=
test_*.py
*_test.py
*_solution.py
xfail_strict = true
filterwarnings =
error
Expand Down

0 comments on commit d9aaa11

Please sign in to comment.