2023-07-15 15:27:31 -07:00
|
|
|
# These tests are auto-generated with test data from:
|
|
|
|
|
# https://github.com/exercism/problem-specifications/tree/main/exercises/proverb/canonical-data.json
|
2023-07-16 15:09:14 -07:00
|
|
|
# File last updated on 2023-07-16
|
2023-07-15 15:27:31 -07:00
|
|
|
|
2014-04-10 22:10:22 -03:00
|
|
|
import unittest
|
|
|
|
|
|
2022-12-04 16:21:18 +01:00
|
|
|
from proverb import (
|
|
|
|
|
proverb,
|
|
|
|
|
)
|
2014-06-11 15:06:22 +02:00
|
|
|
|
2022-12-04 16:21:18 +01:00
|
|
|
# PLEASE TAKE NOTE: Expected result lists for these test cases use **implicit line joining.**
|
|
|
|
|
# A new line in a result list below **does not** always equal a new list element.
|
|
|
|
|
# Check comma placement carefully!
|
2014-04-10 22:10:22 -03:00
|
|
|
|
2017-11-21 16:20:36 +00:00
|
|
|
|
2014-04-10 22:10:22 -03:00
|
|
|
class ProverbTest(unittest.TestCase):
|
2017-11-21 16:20:36 +00:00
|
|
|
def test_zero_pieces(self):
|
2022-12-04 21:37:27 +01:00
|
|
|
input_data = []
|
|
|
|
|
self.assertEqual(proverb(*input_data, qualifier=None), [])
|
2017-11-21 16:20:36 +00:00
|
|
|
|
|
|
|
|
def test_one_piece(self):
|
2022-12-04 21:37:27 +01:00
|
|
|
input_data = ["nail"]
|
2022-12-04 16:21:18 +01:00
|
|
|
self.assertEqual(
|
2022-12-04 21:37:27 +01:00
|
|
|
proverb(*input_data, qualifier=None), ["And all for the want of a nail."]
|
2022-12-04 16:21:18 +01:00
|
|
|
)
|
2017-11-21 16:20:36 +00:00
|
|
|
|
|
|
|
|
def test_two_pieces(self):
|
2022-12-04 21:37:27 +01:00
|
|
|
input_data = ["nail", "shoe"]
|
2022-12-04 16:21:18 +01:00
|
|
|
self.assertEqual(
|
2022-12-04 21:37:27 +01:00
|
|
|
proverb(*input_data, qualifier=None),
|
2022-12-04 16:21:18 +01:00
|
|
|
[
|
|
|
|
|
"For want of a nail the shoe was lost.",
|
|
|
|
|
"And all for the want of a nail.",
|
|
|
|
|
],
|
|
|
|
|
)
|
2017-11-21 16:20:36 +00:00
|
|
|
|
|
|
|
|
def test_three_pieces(self):
|
2022-12-04 21:37:27 +01:00
|
|
|
input_data = ["nail", "shoe", "horse"]
|
2022-12-04 16:21:18 +01:00
|
|
|
self.assertEqual(
|
2022-12-04 21:37:27 +01:00
|
|
|
proverb(*input_data, qualifier=None),
|
2022-12-04 16:21:18 +01:00
|
|
|
[
|
|
|
|
|
"For want of a nail the shoe was lost.",
|
|
|
|
|
"For want of a shoe the horse was lost.",
|
|
|
|
|
"And all for the want of a nail.",
|
|
|
|
|
],
|
|
|
|
|
)
|
2017-11-21 16:20:36 +00:00
|
|
|
|
|
|
|
|
def test_full_proverb(self):
|
2022-12-04 21:37:27 +01:00
|
|
|
input_data = ["nail", "shoe", "horse", "rider", "message", "battle", "kingdom"]
|
2022-12-04 16:21:18 +01:00
|
|
|
self.assertEqual(
|
2022-12-04 21:37:27 +01:00
|
|
|
proverb(*input_data, qualifier=None),
|
2022-12-04 16:21:18 +01:00
|
|
|
[
|
|
|
|
|
"For want of a nail the shoe was lost.",
|
|
|
|
|
"For want of a shoe the horse was lost.",
|
|
|
|
|
"For want of a horse the rider was lost.",
|
|
|
|
|
"For want of a rider the message was lost.",
|
|
|
|
|
"For want of a message the battle was lost.",
|
|
|
|
|
"For want of a battle the kingdom was lost.",
|
|
|
|
|
"And all for the want of a nail.",
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def test_four_pieces_modernized(self):
|
2022-12-04 21:37:27 +01:00
|
|
|
input_data = ["pin", "gun", "soldier", "battle"]
|
2022-12-04 16:21:18 +01:00
|
|
|
self.assertEqual(
|
2022-12-04 21:37:27 +01:00
|
|
|
proverb(*input_data, qualifier=None),
|
2022-12-04 16:21:18 +01:00
|
|
|
[
|
|
|
|
|
"For want of a pin the gun was lost.",
|
|
|
|
|
"For want of a gun the soldier was lost.",
|
|
|
|
|
"For want of a soldier the battle was lost.",
|
|
|
|
|
"And all for the want of a pin.",
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Track-specific tests
|
2022-12-04 21:37:27 +01:00
|
|
|
|
2022-12-04 23:48:49 +01:00
|
|
|
def test_an_optional_qualifier_can_be_added(self):
|
2022-12-04 21:37:27 +01:00
|
|
|
input_data = ["nail"]
|
2022-12-04 16:21:18 +01:00
|
|
|
self.assertEqual(
|
2022-12-04 21:37:27 +01:00
|
|
|
proverb(*input_data, qualifier="horseshoe"),
|
2022-12-04 16:21:18 +01:00
|
|
|
["And all for the want of a horseshoe nail."],
|
|
|
|
|
)
|
|
|
|
|
|
2022-12-04 23:48:49 +01:00
|
|
|
def test_an_optional_qualifier_in_the_final_consequences(self):
|
2022-12-04 21:37:27 +01:00
|
|
|
input_data = ["nail", "shoe", "horse", "rider", "message", "battle", "kingdom"]
|
2022-12-04 16:21:18 +01:00
|
|
|
self.assertEqual(
|
2022-12-04 21:37:27 +01:00
|
|
|
proverb(*input_data, qualifier="horseshoe"),
|
2022-12-04 16:21:18 +01:00
|
|
|
[
|
|
|
|
|
"For want of a nail the shoe was lost.",
|
|
|
|
|
"For want of a shoe the horse was lost.",
|
|
|
|
|
"For want of a horse the rider was lost.",
|
|
|
|
|
"For want of a rider the message was lost.",
|
|
|
|
|
"For want of a message the battle was lost.",
|
|
|
|
|
"For want of a battle the kingdom was lost.",
|
|
|
|
|
"And all for the want of a horseshoe nail.",
|
|
|
|
|
],
|
|
|
|
|
)
|