Files
python/exercises/practice/proverb/proverb_test.py

95 lines
3.3 KiB
Python
Raw Normal View History

2014-04-10 22:10:22 -03:00
import unittest
2022-12-04 16:21:18 +01:00
from proverb import (
proverb,
)
2022-12-04 16:21:18 +01:00
# Tests adapted from `problem-specifications//canonical-data.json`
# 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
2014-04-10 22:10:22 -03:00
class ProverbTest(unittest.TestCase):
def test_zero_pieces(self):
2022-12-04 21:37:27 +01:00
input_data = []
self.assertEqual(proverb(*input_data, qualifier=None), [])
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
)
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.",
],
)
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.",
],
)
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.",
],
)