Skip to content

Commit 5bd9b68

Browse files
committed
Spanish article selector
1 parent 93fe2b0 commit 5bd9b68

File tree

4 files changed

+140
-0
lines changed

4 files changed

+140
-0
lines changed

extra/03_spanish/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/03_spanish/README.adoc

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
= Spanish article selector
2+
3+
Write a Python program called `article.py` that will choose the correct article for word given as a single positional argument.
4+
Although there are exceptions, Spanish tends to use "el" for words ending in "o" and "la" otherwise.
5+
The entire output will be in the form:
6+
7+
----
8+
Me gusto {article} {word}.
9+
----
10+
11+
For example, if the input is "chico", the article should be "el":
12+
13+
----
14+
$ ./article.py chico
15+
Me gusto el chico.
16+
----
17+
18+
And "la" for "chica":
19+
20+
----
21+
$ ./article.py chica
22+
Me gusto la chica.
23+
----
24+
25+
It should print a brief usage if provided with no arguments:
26+
27+
----
28+
$ ./article.py
29+
usage: article.py [-h] str
30+
article.py: error: the following arguments are required: str
31+
----
32+
33+
And a longer usage for the `-h` or `--help` flags:
34+
35+
----
36+
$ ./article.py -h
37+
usage: article.py [-h] str
38+
39+
Choose the correct Spanish article
40+
41+
positional arguments:
42+
str Input text
43+
44+
optional arguments:
45+
-h, --help show this help message and exit
46+
----
47+
48+
49+
It should pass all the tests:
50+
51+
----
52+
$ make test
53+
pytest -xv test.py
54+
============================= test session starts ==============================
55+
...
56+
collected 6 items
57+
58+
test.py::test_exists PASSED [ 16%]
59+
test.py::test_usage PASSED [ 33%]
60+
test.py::test_masculine_lower PASSED [ 50%]
61+
test.py::test_masculine_upper PASSED [ 66%]
62+
test.py::test_feminine_lower PASSED [ 83%]
63+
test.py::test_feminine_upper PASSED [100%]
64+
65+
============================== 6 passed in 0.33s ===============================
66+
----

extra/03_spanish/README.pdf

39.6 KB
Binary file not shown.

extra/03_spanish/test.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env python3
2+
"""tests for article.py"""
3+
4+
import os
5+
import random
6+
import re
7+
import string
8+
from subprocess import getstatusoutput
9+
10+
prg = './article.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 test_masculine_lower():
32+
"""masculine_lower"""
33+
34+
word = random.choice('chico teatro cartero'.split())
35+
rv, out = getstatusoutput(f'{prg} {word}')
36+
assert rv == 0
37+
assert out == f'Me gusto el {word}.'
38+
39+
40+
# --------------------------------------------------
41+
def test_masculine_upper():
42+
"""masculine_upper"""
43+
44+
word = random.choice('CHICO TEATRO CARTERO'.split())
45+
rv, out = getstatusoutput(f'{prg} {word}')
46+
assert rv == 0
47+
assert out == f'Me gusto el {word}.'
48+
49+
50+
# --------------------------------------------------
51+
def test_feminine_lower():
52+
"""feminine_lower"""
53+
54+
word = random.choice('chica gata abuela'.split())
55+
rv, out = getstatusoutput(f'{prg} {word}')
56+
assert rv == 0
57+
assert out == f'Me gusto la {word}.'
58+
59+
60+
# --------------------------------------------------
61+
def test_feminine_upper():
62+
"""feminine_upper"""
63+
64+
word = random.choice('CHICA GATA ABUELA'.split())
65+
rv, out = getstatusoutput(f'{prg} {word}')
66+
assert rv == 0
67+
assert out == f'Me gusto la {word}.'

0 commit comments

Comments
 (0)