Skip to content

Commit bde4d7b

Browse files
author
Nathan Parsons
committed
proverb: Update exercise to canonical-data 1.0.0
1 parent 6ffba30 commit bde4d7b

File tree

4 files changed

+53
-60
lines changed

4 files changed

+53
-60
lines changed

exercises/proverb/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
For want of a horseshoe nail, a kingdom was lost, or so the saying goes.
44

5-
Output the full text of this proverbial rhyme:
5+
Given a list of inputs, generate the relevant proverb. For example, given the list `["nail", "shoe", "horse", "rider", "message", "battle", "kingdom"]`, you will output the full text of this proverbial rhyme:
66

77
```text
88
For want of a nail the shoe was lost.
@@ -11,8 +11,11 @@ For want of a horse the rider was lost.
1111
For want of a rider the message was lost.
1212
For want of a message the battle was lost.
1313
For want of a battle the kingdom was lost.
14-
And all for the want of a horseshoe nail.
14+
And all for the want of a nail.
1515
```
16+
17+
Note that the list of inputs may vary; your solution should be able to handle lists of arbitrary length and content. No line of the output text should be a static, unchanging string; all should vary according to the input given.
18+
1619
## Submitting Exercises
1720

1821
Note that, when trying to submit an exercise, make sure the solution is in the `exercism/python/<exerciseName>` directory.

exercises/proverb/example.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
def proverb(itens, qualifier=''):
1+
def proverb(items):
2+
if not items:
3+
return ""
24
phrases = ['For want of a {0} the {1} was lost.'.format(el1, el2)
3-
for el1, el2 in zip(itens, itens[1:])]
4-
qualifier += ' ' if qualifier else ''
5-
phrases.append('And all for the want of a {0}{1}.'.format(qualifier,
6-
itens[0]))
5+
for el1, el2 in zip(items, items[1:])]
6+
phrases.append('And all for the want of a {0}.'.format(items[0]))
77
return '\n'.join(phrases)

exercises/proverb/proverb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
def proverb(rhyme_text):
1+
def proverb(rhyme_items):
22
pass

exercises/proverb/proverb_test.py

Lines changed: 42 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,49 @@
33
from proverb import proverb
44

55

6+
# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0
7+
68
class ProverbTest(unittest.TestCase):
7-
def test_a_single_consequence(self):
8-
expected = 'For want of a nail the shoe was lost.\n'\
9-
'And all for the want of a nail.'
10-
self.assertEqual(proverb(['nail', 'shoe']), expected)
11-
12-
def test_short_list(self):
13-
expected = 'For want of a nail the shoe was lost.\n'\
14-
'For want of a shoe the horse was lost.\n'\
15-
'And all for the want of a nail.'
16-
self.assertEqual(proverb(['nail', 'shoe', 'horse']), expected)
17-
18-
def test_long_list(self):
19-
expected = 'For want of a nail the shoe was lost.\n'\
20-
'For want of a shoe the horse was lost.\n'\
21-
'For want of a horse the rider was lost.\n'\
22-
'And all for the want of a nail.'
23-
self.assertEqual(proverb(['nail', 'shoe', 'horse', 'rider']), expected)
24-
25-
def test_new_itens(self):
26-
expected = 'For want of a key the value was lost.\n'\
27-
'And all for the want of a key.'
28-
self.assertEqual(proverb(['key', 'value']), expected)
29-
30-
def test_whole_proverb(self):
31-
expected = 'For want of a nail the shoe was lost.\n'\
32-
'For want of a shoe the horse was lost.\n'\
33-
'For want of a horse the rider was lost.\n'\
34-
'For want of a rider the message was lost.\n'\
35-
'For want of a message the battle was lost.\n'\
36-
'For want of a battle the kingdom was lost.\n'\
37-
'And all for the want of a nail.'
38-
self.assertEqual(
39-
proverb([
40-
'nail', 'shoe', 'horse', 'rider', 'message', 'battle',
41-
'kingdom'
42-
]), expected)
43-
44-
def test_qualifier(self):
45-
expected = 'For want of a nail the shoe was lost.\n'\
46-
'For want of a shoe the horse was lost.\n'\
47-
'For want of a horse the rider was lost.\n'\
48-
'For want of a rider the message was lost.\n'\
49-
'For want of a message the battle was lost.\n'\
50-
'For want of a battle the kingdom was lost.\n'\
51-
'And all for the want of a horseshoe nail.'
52-
self.assertEqual(
53-
proverb(
54-
[
55-
'nail', 'shoe', 'horse', 'rider', 'message', 'battle',
56-
'kingdom'
57-
],
58-
qualifier='horseshoe'), expected)
9+
def test_zero_pieces(self):
10+
self.assertEqual(proverb([]), "")
11+
12+
def test_one_piece(self):
13+
inputs = ["nail"]
14+
expected = "And all for the want of a nail."
15+
self.assertEqual(proverb(inputs), expected)
16+
17+
def test_two_pieces(self):
18+
inputs = ["nail", "shoe"]
19+
expected = "\n".join(["For want of a nail the shoe was lost.",
20+
"And all for the want of a nail."])
21+
self.assertEqual(proverb(inputs), expected)
22+
23+
def test_three_pieces(self):
24+
inputs = ["nail", "shoe", "horse"]
25+
expected = "\n".join(["For want of a nail the shoe was lost.",
26+
"For want of a shoe the horse was lost.",
27+
"And all for the want of a nail."])
28+
self.assertEqual(proverb(inputs), expected)
29+
30+
def test_full_proverb(self):
31+
inputs = ["nail", "shoe", "horse", "rider",
32+
"message", "battle", "kingdom"]
33+
expected = "\n".join(["For want of a nail the shoe was lost.",
34+
"For want of a shoe the horse was lost.",
35+
"For want of a horse the rider was lost.",
36+
"For want of a rider the message was lost.",
37+
"For want of a message the battle was lost.",
38+
"For want of a battle the kingdom was lost.",
39+
"And all for the want of a nail."])
40+
self.assertEqual(proverb(inputs), expected)
41+
42+
def test_four_pieces_modernised(self):
43+
inputs = ["pin", "gun", "soldier", "battle"]
44+
expected = "\n".join(["For want of a pin the gun was lost.",
45+
"For want of a gun the soldier was lost.",
46+
"For want of a soldier the battle was lost.",
47+
"And all for the want of a pin."])
48+
self.assertEqual(proverb(inputs), expected)
5949

6050

6151
if __name__ == '__main__':

0 commit comments

Comments
 (0)