Skip to content

Commit d955d62

Browse files
committed
new extra
1 parent 6acbf92 commit d955d62

File tree

5 files changed

+216
-1
lines changed

5 files changed

+216
-1
lines changed

22_tictactoe/itictactoe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def format_board(board: List[str]) -> str:
7979
cells_tmpl = '| {} | {} | {} |'
8080
return '\n'.join([
8181
bar,
82-
cells_tmpl.format(*cells[0:3]), bar,
82+
cells_tmpl.format(*cells[:3]), bar,
8383
cells_tmpl.format(*cells[3:6]), bar,
8484
cells_tmpl.format(*cells[6:]), bar
8585
])

extra/05_days/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.PHONY: test pdf
2+
3+
pdf:
4+
asciidoctor-pdf -o README.pdf README.adoc
5+
6+
test:
7+
pytest -xv test.py

extra/05_days/README.adoc

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
= Seven Days of the Week
2+
3+
For this exercise, we'll draw inspiration from the song "Seven Days of the Week" by They Might Be Giants.
4+
You can enjoy the official video here:
5+
6+
https://www.youtube.com/watch?v=geTSBFb_GR4
7+
8+
Your program will accept one or more positional arguments which may or may not name a day of the week.
9+
For each day, you should print the appropriate line from the following list:
10+
11+
* On Mondays I never go to work
12+
* On Tuesdays I stay at home
13+
* On Wednesdays I never feel inclined
14+
* On Thursdays, it's a holiday
15+
* And Fridays I detest
16+
* Oh, it's much too late on a Saturday
17+
* And Sunday is the day of rest
18+
19+
For example, it should handle one day:
20+
21+
----
22+
$ ./days.py Monday
23+
On Mondays I never go to work
24+
----
25+
26+
Or several:
27+
28+
----
29+
$ ./days.py Tuesday Wednesday Friday
30+
On Tuesdays I stay at home
31+
On Wednesdays I never feel inclined
32+
And Fridays I detest
33+
----
34+
35+
If any argument does not name a day of the week, print 'Can't find "{day}"':
36+
37+
----
38+
$ ./days.py Tuesday Odinsday Saturday
39+
On Tuesdays I stay at home
40+
Can't find "Odinsday"
41+
Oh, it's much too late on a Saturday
42+
----
43+
44+
If run with no arguments, it should print a short usage:
45+
46+
----
47+
$ ./days.py
48+
usage: days.py [-h] str [str ...]
49+
days.py: error: the following arguments are required: str
50+
----
51+
52+
And it should respond to `-h` or `--help` with a longer usage:
53+
54+
----
55+
$ ./days.py -h
56+
usage: days.py [-h] str [str ...]
57+
58+
What to do on each day
59+
60+
positional arguments:
61+
str Days of the week
62+
63+
optional arguments:
64+
-h, --help show this help message and exit
65+
----
66+
67+
Your program should pass all tests:
68+
69+
----
70+
$ make test
71+
pytest -xv test.py
72+
============================= test session starts ==============================
73+
...
74+
collected 12 items
75+
76+
test.py::test_exists PASSED [ 8%]
77+
test.py::test_usage PASSED [ 16%]
78+
test.py::test_monday PASSED [ 25%]
79+
test.py::test_tuesday PASSED [ 33%]
80+
test.py::test_wednesday PASSED [ 41%]
81+
test.py::test_thursday PASSED [ 50%]
82+
test.py::test_friday PASSED [ 58%]
83+
test.py::test_saturday PASSED [ 66%]
84+
test.py::test_sunday PASSED [ 75%]
85+
test.py::test_lower PASSED [ 83%]
86+
test.py::test_monday_tuesday PASSED [ 91%]
87+
test.py::test_mix PASSED [100%]
88+
89+
============================== 12 passed in 0.93s ==============================
90+
----

extra/05_days/README.pdf

47.1 KB
Binary file not shown.

extra/05_days/test.py

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#!/usr/bin/env python3
2+
"""tests for days.py"""
3+
4+
import os
5+
import random
6+
import re
7+
import string
8+
from subprocess import getstatusoutput
9+
10+
prg = './days.py'
11+
12+
13+
# --------------------------------------------------
14+
def test_exists():
15+
"""exists"""
16+
17+
assert os.path.isfile(prg)
18+
19+
20+
# --------------------------------------------------
21+
def test_usage():
22+
"""usage"""
23+
24+
for flag in ['-h', '--help']:
25+
rv, out = getstatusoutput(f'{prg} {flag}')
26+
assert rv == 0
27+
assert out.lower().startswith('usage')
28+
29+
30+
# --------------------------------------------------
31+
def run_day(day, expected):
32+
"""Run a day"""
33+
34+
rv, out = getstatusoutput(f'{prg} {day}')
35+
assert rv == 0
36+
assert out == expected
37+
38+
39+
# --------------------------------------------------
40+
def test_monday():
41+
"""Monday"""
42+
43+
run_day('Monday', 'On Mondays I never go to work')
44+
45+
46+
# --------------------------------------------------
47+
def test_tuesday():
48+
"""Tuesday"""
49+
50+
run_day('Tuesday', 'On Tuesdays I stay at home')
51+
52+
53+
# --------------------------------------------------
54+
def test_wednesday():
55+
"""Wednesday"""
56+
57+
run_day('Wednesday', 'On Wednesdays I never feel inclined')
58+
59+
60+
# --------------------------------------------------
61+
def test_thursday():
62+
"""Thursday"""
63+
64+
run_day('Thursday', "On Thursdays, it's a holiday")
65+
66+
67+
# --------------------------------------------------
68+
def test_friday():
69+
"""Friday"""
70+
71+
run_day('Friday', 'And Fridays I detest')
72+
73+
74+
# --------------------------------------------------
75+
def test_saturday():
76+
"""Saturday"""
77+
78+
run_day('Saturday', "Oh, it's much too late on a Saturday")
79+
80+
81+
# --------------------------------------------------
82+
def test_sunday():
83+
"""Sunday"""
84+
85+
run_day('Sunday', 'And Sunday is the day of rest')
86+
87+
88+
# --------------------------------------------------
89+
def test_lower():
90+
"""monday"""
91+
92+
for day in [
93+
'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday',
94+
'sunday'
95+
]:
96+
rv, out = getstatusoutput(f'{prg} {day}')
97+
assert rv == 0
98+
assert out == f'Can\'t find "{day}"'
99+
100+
101+
# --------------------------------------------------
102+
def test_monday_tuesday():
103+
"""Monday Tuesday"""
104+
105+
run_day(
106+
'Monday Tuesday', '\n'.join(
107+
['On Mondays I never go to work', 'On Tuesdays I stay at home']))
108+
109+
110+
# --------------------------------------------------
111+
def test_mix():
112+
"""Mix good and bad"""
113+
114+
run_day(
115+
'Sunday Odinsday Thorsday Friday', '\n'.join([
116+
'And Sunday is the day of rest', "Can't find \"Odinsday\"",
117+
"Can't find \"Thorsday\"", 'And Fridays I detest'
118+
]))

0 commit comments

Comments
 (0)