|
3 | 3 | from proverb import proverb
|
4 | 4 |
|
5 | 5 |
|
| 6 | +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0 |
| 7 | + |
6 | 8 | 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) |
59 | 49 |
|
60 | 50 |
|
61 | 51 | if __name__ == '__main__':
|
|
0 commit comments