Search This Blog

02 March 2015

Python Puzzle #2

Here is the challenge #2. This one deserves more explanations.
Your team has to maintain a legacy project, and for various historical reasons, the project has not enough documentation. Features delivery is always a higher priority than the documentation update.
So, you decide it's time that every team member commits to read and improve the documentation.
The plan is to spend an hour every Monday, Wednesday and Friday to this task, each team member in turn.

you want a function, that given a start date and a number of weeks, will assign the team member to this maintenance.


import unittest
import datetime


team_members = [
    "Dilbert",
    "Wally",
    "Alice",
    "Pointy haired Boss",
    "Dogbert",
    "Asok",
    "Ted",
    "Loud Howard",
    "Carol",
    "Ratbert",
    "Catbert",
    "Dilmom",
    "Phil, prince of insufficient light",
    "Bob the dinosaur",
    "Garbageman",
    "Tina",
    "Accountig Troll",
    "Elbonian guy",
    "Mordac",
    "Topper",
    "Liz",
]


def build_rota(start_date, weeks=4):
    pass


class TestDottedToDict(unittest.TestCase):
    def setUp(self):
        self.expected = [(datetime.date(2014, 12, 26), 'Dilbert'),
                         (datetime.date(2014, 12, 29), 'Wally'),
                         (datetime.date(2014, 12, 31), 'Alice'),
                         (datetime.date(2015, 1, 2), 'Pointy haired Boss'),
                         (datetime.date(2015, 1, 5), 'Dogbert'),
                         (datetime.date(2015, 1, 7), 'Asok'),
                         (datetime.date(2015, 1, 9), 'Ted'),
                         (datetime.date(2015, 1, 12), 'Loud Howard'),
                         (datetime.date(2015, 1, 14), 'Carol'),
                         (datetime.date(2015, 1, 16), 'Ratbert'),
                         (datetime.date(2015, 1, 19), 'Catbert'),
                         (datetime.date(2015, 1, 21), 'Dilmom'),
                         (datetime.date(2015, 1, 23), 'Phil, prince of insufficient light'),
                         (datetime.date(2015, 1, 26), 'Bob the dinosaur'),
                         (datetime.date(2015, 1, 28), 'Garbageman'),
                         (datetime.date(2015, 1, 30), 'Tina'),
                         (datetime.date(2015, 2, 2), 'Accountig Troll'),
                         (datetime.date(2015, 2, 4), 'Elbonian guy'),
                         (datetime.date(2015, 2, 6), 'Mordac'),
                         (datetime.date(2015, 2, 9), 'Topper'),
                         (datetime.date(2015, 2, 11), 'Liz'),
                         (datetime.date(2015, 2, 13), 'Dilbert'),
                         (datetime.date(2015, 2, 16), 'Wally'),
                         (datetime.date(2015, 2, 18), 'Alice'),
                         (datetime.date(2015, 2, 20), 'Pointy haired Boss'),
                         (datetime.date(2015, 2, 23), 'Dogbert'),
                         (datetime.date(2015, 2, 25), 'Asok'),
                         (datetime.date(2015, 2, 27), 'Ted'),
                         (datetime.date(2015, 3, 2), 'Loud Howard'),
                         (datetime.date(2015, 3, 4), 'Carol'),
                         (datetime.date(2015, 3, 6), 'Ratbert'),
                         (datetime.date(2015, 3, 9), 'Catbert'),
                         (datetime.date(2015, 3, 11), 'Dilmom'),
                         (datetime.date(2015, 3, 13), 'Phil, prince of insufficient light'),
                         (datetime.date(2015, 3, 16), 'Bob the dinosaur'),
                         (datetime.date(2015, 3, 18), 'Garbageman'),
                         (datetime.date(2015, 3, 20), 'Tina'),
                         (datetime.date(2015, 3, 23), 'Accountig Troll'),
                         (datetime.date(2015, 3, 25), 'Elbonian guy'),
                         (datetime.date(2015, 3, 27), 'Mordac'),
                         (datetime.date(2015, 3, 30), 'Topper'),
                         (datetime.date(2015, 4, 1), 'Liz'),
                         (datetime.date(2015, 4, 3), 'Dilbert'),
                         (datetime.date(2015, 4, 6), 'Wally'),
                         (datetime.date(2015, 4, 8), 'Alice')]

    def test_rota(self):
        got = list(build_rota(datetime.date(2014, 12, 25), weeks=15))
        self.assertListEqual(got, self.expected)

Have fun!

1 comment:

  1. My attempt uses two imports and 4 LoC, while still being quite pythonic I believe :) http://pastebin.com/0u4LhgZv

    ReplyDelete