From 1b526b24bb39706f7b14b9a5040f59d6cdcae4f2 Mon Sep 17 00:00:00 2001 From: BethanyG Date: Fri, 13 Oct 2023 13:49:29 -0700 Subject: [PATCH 1/3] Modified test error messages to better match test runner changes. Also did touchup for links in docs. --- .../concept/meltdown-mitigation/.docs/hints.md | 16 ++++++++-------- .../meltdown-mitigation/.docs/introduction.md | 10 +++++----- .../meltdown-mitigation/.meta/design.md | 4 ++-- .../meltdown-mitigation/conditionals_test.py | 18 ++++++++++++------ 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/exercises/concept/meltdown-mitigation/.docs/hints.md b/exercises/concept/meltdown-mitigation/.docs/hints.md index 510b8bd4fb..e500bb4dcd 100644 --- a/exercises/concept/meltdown-mitigation/.docs/hints.md +++ b/exercises/concept/meltdown-mitigation/.docs/hints.md @@ -8,7 +8,7 @@ ## 1. Check for criticality -- Comparison operators and boolean operations can be combined and used with conditionals. +- Comparison operators ([comparisons][comparisons review]) and boolean operations ([concept:python/bools]()) can be combined and used with conditionals. - Conditional expressions must evaluate to `True` or `False`. - `else` can be used for a code block that will execute when all conditional tests return `False`. @@ -16,9 +16,9 @@ >>> item = 'blue' >>> item_2 = 'green' - >>> if len(item) >=3 and len(item_2) < 5: + >>> if len(item) >= 3 and len(item_2) < 5: print('Both pass the test!') - elif len(item) >=3 or len(item_2) < 5: + elif len(item) >= 3 or len(item_2) < 5: print('One passes the test!') else: print('None pass the test!') @@ -29,20 +29,20 @@ ## 2. Determine the Power output range - Comparison operators can be combined and used with conditionals. -- Any number of `elif` statements can be used as "branches". +- Any number of `elif` statements can be used as decision "branches". - Each "branch" can have a separate `return` ## 3. Fail Safe Mechanism - Comparison operators can be combined and used with conditionals. -- Any number of `elif` statements can be used as "branches". +- Any number of `elif` statements can be used as decision "branches". - Each "branch" can have a separate `return` -[python comparisons examples]: https://www.tutorialspoint.com/python/comparison_operators_example.htm [boolean operations]: https://docs.python.org/3/library/stdtypes.html#boolean-operations-and-or-not +[comparisons review]: https://www.learnpython.dev/02-introduction-to-python/090-boolean-logic/20-comparisons/ [comparisons]: https://docs.python.org/3/library/stdtypes.html#comparisons +[control flow tools]: https://docs.python.org/3/tutorial/controlflow.html [python booleans]: https://realpython.com/python-boolean/ +[python comparisons examples]: https://www.tutorialspoint.com/python/comparison_operators_example.htm [real python conditionals]: https://realpython.com/python-conditional-statements/ -[control flow tools]: https://docs.python.org/3/tutorial/controlflow.html - diff --git a/exercises/concept/meltdown-mitigation/.docs/introduction.md b/exercises/concept/meltdown-mitigation/.docs/introduction.md index da5ebbae19..fe9fff4d5d 100644 --- a/exercises/concept/meltdown-mitigation/.docs/introduction.md +++ b/exercises/concept/meltdown-mitigation/.docs/introduction.md @@ -3,9 +3,9 @@ In Python, [`if`][if statement], `elif` (_a contraction of 'else and if'_) and `else` statements are used to [control the flow][control flow tools] of execution and make decisions in a program. Unlike many other programming languages, Python versions 3.9 and below do not offer a formal case-switch statement, instead using multiple `elif` statements to serve a similar purpose. -Python 3.10 introduces a variant case-switch statement called `pattern matching`, which will be covered separately in another concept. +Python 3.10 introduces a variant case-switch statement called `structural pattern matching`, which will be covered separately in another concept. -Conditional statements use expressions that must resolve to `True` or `False` -- either by returning a `bool` directly, or by evaluating ["truthy" or "falsy"][truth value testing]. +Conditional statements use expressions that must resolve to `True` or `False` -- either by returning a `bool` type directly, or by evaluating as ["truthy" or "falsy"][truth value testing]. ```python x = 10 @@ -74,8 +74,8 @@ else: '13' ``` -[if statement]: https://docs.python.org/3/reference/compound_stmts.html#the-if-statement -[control flow tools]: https://docs.python.org/3/tutorial/controlflow.html#more-control-flow-tools -[truth value testing]: https://docs.python.org/3/library/stdtypes.html#truth-value-testing [boolean operations]: https://docs.python.org/3/library/stdtypes.html#boolean-operations-and-or-not [comparisons]: https://docs.python.org/3/library/stdtypes.html#comparisons +[control flow tools]: https://docs.python.org/3/tutorial/controlflow.html#more-control-flow-tools +[if statement]: https://docs.python.org/3/reference/compound_stmts.html#the-if-statement +[truth value testing]: https://docs.python.org/3/library/stdtypes.html#truth-value-testing diff --git a/exercises/concept/meltdown-mitigation/.meta/design.md b/exercises/concept/meltdown-mitigation/.meta/design.md index cdc482c6d0..33ef7e3b95 100644 --- a/exercises/concept/meltdown-mitigation/.meta/design.md +++ b/exercises/concept/meltdown-mitigation/.meta/design.md @@ -3,11 +3,11 @@ ## Goal -The goal of this exercise is to teach the student what is a `conditional` and how they are used in Python. +The goal of this exercise is to teach the student about `conditionals` and how they are used in Python. ## Learning objectives -- learn some general things about `control flow` in python +- learn some general things about `control flow` in Python - create a `conditional` structure to choose something, take a decision - use an `if...else` structure - use an `if..elif...else` structure diff --git a/exercises/concept/meltdown-mitigation/conditionals_test.py b/exercises/concept/meltdown-mitigation/conditionals_test.py index 9837c34302..5e48ca326c 100644 --- a/exercises/concept/meltdown-mitigation/conditionals_test.py +++ b/exercises/concept/meltdown-mitigation/conditionals_test.py @@ -30,8 +30,10 @@ def test_is_criticality_balanced(self): # pylint: disable=assignment-from-no-return actual_result = is_criticality_balanced(temp, neutrons_emitted) - failure_message = (f'Expected {expected} but returned {actual_result} ' - f'with T={temp} and neutrons={neutrons_emitted}') + failure_message = (f'Called is_criticality_balanced({temp}, {neutrons_emitted}). ' + f' The function returned {actual_result}, ' + f'but the test expected {expected} as the return value.') + self.assertEqual(actual_result, expected, failure_message) @pytest.mark.task(taskno=2) @@ -52,8 +54,10 @@ def test_reactor_efficiency(self): # pylint: disable=assignment-from-no-return actual_result = reactor_efficiency(voltage, current, theoretical_max_power) - failure_message = (f'Expected {expected} but returned {actual_result} ' - f'with voltage={voltage}, current={current}, max_pow={theoretical_max_power}') + failure_message =(f'Called reactor_efficiency({voltage}, {current}, {theoretical_max_power}). ' + f'The function returned {actual_result}, ' + f'but the test expected {expected} as the return value.') + self.assertEqual(actual_result, expected, failure_message) @pytest.mark.task(taskno=3) @@ -71,6 +75,8 @@ def test_fail_safe(self): # pylint: disable=assignment-from-no-return actual_result = fail_safe(temp, neutrons_per_second, threshold) - failure_message = (f'Expected {expected} but returned {actual_result} with T={temp}, ' - f'neutrons={neutrons_per_second}, threshold={threshold}') + failure_message = (f'Called fail_safe({temp}, {neutrons_per_second}, {threshold}). ' + f'The function returned {actual_result}, ' + f'but the test expected {expected} as the return value.') + self.assertEqual(actual_result, expected, failure_message) From e800f4ec6db613b21f5d157de7578f0fe8189469 Mon Sep 17 00:00:00 2001 From: BethanyG Date: Fri, 20 Oct 2023 13:57:21 -0700 Subject: [PATCH 2/3] Updated test error messages to be more verbose. --- .../concept/black-jack/.docs/introduction.md | 4 +- exercises/concept/black-jack/black_jack.py | 1 + .../concept/black-jack/black_jack_test.py | 128 ++++++++++-------- 3 files changed, 75 insertions(+), 58 deletions(-) diff --git a/exercises/concept/black-jack/.docs/introduction.md b/exercises/concept/black-jack/.docs/introduction.md index 207229359d..a891289494 100644 --- a/exercises/concept/black-jack/.docs/introduction.md +++ b/exercises/concept/black-jack/.docs/introduction.md @@ -59,7 +59,7 @@ True ``` Any ordered comparison of a number to a `NaN` (_not a number_) type is `False`. -A confusing side-effect of Python's `NaN` definition is that `NaN` never compares equal to `NaN`. +A confusing side effect of Python's `NaN` definition is that `NaN` never compares equal to `NaN`. ```python >>> x = float('NaN') @@ -186,7 +186,7 @@ The operators `in` and `not in` test for _membership_. For string and bytes types, ` in ` is `True` _**if and only if**_ `` is a substring of ``. ```python ->>> +>>> # A set of lucky numbers. >>> lucky_numbers = {11, 22, 33} >>> 22 in lucky_numbers diff --git a/exercises/concept/black-jack/black_jack.py b/exercises/concept/black-jack/black_jack.py index 9ce6ca5ba4..7afade0651 100644 --- a/exercises/concept/black-jack/black_jack.py +++ b/exercises/concept/black-jack/black_jack.py @@ -79,3 +79,4 @@ def can_double_down(card_one, card_two): """ pass + diff --git a/exercises/concept/black-jack/black_jack_test.py b/exercises/concept/black-jack/black_jack_test.py index 79072f95da..0962781f0a 100644 --- a/exercises/concept/black-jack/black_jack_test.py +++ b/exercises/concept/black-jack/black_jack_test.py @@ -15,84 +15,100 @@ class BlackJackTest(unittest.TestCase): @pytest.mark.task(taskno=1) def test_value_of_card(self): - data = [ - ('2', 2), ('5', 5), ('8', 8), - ('A', 1), ('10', 10), ('J', 10), - ('Q', 10), ('K', 10)] + test_data = [('2', 2), ('5', 5), ('8', 8), + ('A', 1), ('10', 10), ('J', 10), + ('Q', 10), ('K', 10)] - for variant, (card, value) in enumerate(data, 1): - with self.subTest(f'variation #{variant}', input=card, output=value): - error_msg = f'Expected {value} as the value of {card}.' + for variant, (card, expected) in enumerate(test_data, 1): + with self.subTest(f'variation #{variant}', card=card, expected=expected): + actual_result = value_of_card(card) + error_msg = (f'Called value_of_card({card}). ' + f'The function returned {actual_result} as the value of the {card} card, ' + f'but the test expected {expected} as the {card} card value.') + + self.assertEqual(actual_result, expected, msg=error_msg) - self.assertEqual(value_of_card(card), value, msg=error_msg) @pytest.mark.task(taskno=2) def test_higher_card(self): - data = [ - ('A', 'A', ('A', 'A')), - ('10', 'J', ('10', 'J')), - ('3', 'A', '3'), - ('3', '6', '6'), - ('Q', '10', ('Q', '10')), - ('4', '4', ('4', '4')), - ('9', '10', '10'), - ('6', '9', '9'), - ('4', '8', '8')] - - for variant, (card_one, card_two, result) in enumerate(data, 1): - with self.subTest(f'variation #{variant}', card_one=card_one, card_two=card_two, output=result): - error_msg = f'Expected {result} as the higher value of the cards {card_one, card_two}.' - - self.assertEqual(higher_card(card_one, card_two), result, msg=error_msg) + test_data = [('A', 'A', ('A', 'A')), + ('10', 'J', ('10', 'J')), + ('3', 'A', '3'), + ('3', '6', '6'), + ('Q', '10', ('Q', '10')), + ('4', '4', ('4', '4')), + ('9', '10', '10'), + ('6', '9', '9'), + ('4', '8', '8')] + + for variant, (card_one, card_two, expected) in enumerate(test_data, 1): + with self.subTest(f'variation #{variant}', card_one=card_one, card_two=card_two, expected=expected): + actual_result = higher_card(card_one, card_two) + error_msg = (f'Called higher_card({card_one}, {card_two}). ' + f'The function returned {actual_result}, ' + f'but the test expected {expected} as the result for the cards {card_one, card_two}.') + + self.assertEqual(actual_result, expected, msg=error_msg) @pytest.mark.task(taskno=3) def test_value_of_ace(self): - data = [ - ('2', '3', 11), ('3', '6', 11), ('5', '2', 11), - ('8', '2', 11), ('5', '5', 11), ('Q', 'A', 1), - ('10', '2', 1), ('7', '8', 1), ('J', '9', 1), - ('K', 'K', 1), ('2', 'A', 1), ('A', '2', 1)] + test_data = [('2', '3', 11), ('3', '6', 11), ('5', '2', 11), + ('8', '2', 11), ('5', '5', 11), ('Q', 'A', 1), + ('10', '2', 1), ('7', '8', 1), ('J', '9', 1), + ('K', 'K', 1), ('2', 'A', 1), ('A', '2', 1)] - for variant, (card_one, card_two, ace_value) in enumerate(data, 1): + for variant, (card_one, card_two, ace_value) in enumerate(test_data, 1): with self.subTest(f'variation #{variant}', card_one=card_one, card_two=card_two, ace_value=ace_value): - error_msg = f'Expected {ace_value} as the value of an ace card when the hand has {card_one, card_two}.' + actual_result = value_of_ace(card_one, card_two) + error_msg = (f'Called value_of_ace({card_one}, {card_two}). ' + f'The function returned {actual_result}, ' + f'but the test expected {ace_value} as the value of an ace card ' + f'when the hand includes {card_one, card_two}.') self.assertEqual(value_of_ace(card_one, card_two), ace_value, msg=error_msg) @pytest.mark.task(taskno=4) def test_is_blackjack(self): - data = [ - (('A', 'K'), True), (('10', 'A'), True), - (('10', '9'), False), (('A', 'A'), False), - (('4', '7'), False), (('9', '2'), False), - (('Q', 'K'), False)] + test_data = [(('A', 'K'), True), (('10', 'A'), True), + (('10', '9'), False), (('A', 'A'), False), + (('4', '7'), False), (('9', '2'), False), + (('Q', 'K'), False)] - for variant, (hand, blackjack) in enumerate(data, 1): - with self.subTest(f'variation #{variant}', input=hand, output=blackjack): - error_msg = f'Hand {hand} {"is" if blackjack else "is not"} a blackjack.' + for variant, (hand, expected) in enumerate(test_data, 1): + with self.subTest(f'variation #{variant}', hand=hand, expected=expected): + actual_result = is_blackjack(*hand) + error_msg = (f'Called is_blackjack({hand[0]}, {hand[1]}). ' + f'The function returned {actual_result}, ' + f'but hand {hand} {"is" if expected else "is not"} a blackjack.') - self.assertEqual(is_blackjack(*hand), blackjack, msg=error_msg) + self.assertEqual(actual_result, expected, msg=error_msg) @pytest.mark.task(taskno=5) def test_can_split_pairs(self): - data = [ - (('Q', 'K'), True), (('6', '6'), True), (('A', 'A'), True), - (('10', 'A'), False), (('10', '9'), False)] + test_data = [(('Q', 'K'), True), (('6', '6'), True), + (('A', 'A'), True),(('10', 'A'), False), + (('10', '9'), False)] - for variant, (hand, split_pairs) in enumerate(data, 1): - with self.subTest(f'variation #{variant}', input=hand, output=split_pairs): - error_msg = f'Hand {hand} {"can" if split_pairs else "cannot"} be split into pairs.' + for variant, (hand, expected) in enumerate(test_data, 1): + with self.subTest(f'variation #{variant}', input=hand, expected=expected): + actual_result = can_split_pairs(*hand) + error_msg = (f'Called can_split_pairs({hand[0]}, {hand[1]}). ' + f'The function returned {actual_result}, ' + f'but hand {hand} {"can" if expected else "cannot"} be split into pairs.') - self.assertEqual(can_split_pairs(*hand), split_pairs, msg=error_msg) + self.assertEqual(actual_result, expected, msg=error_msg) @pytest.mark.task(taskno=6) def test_can_double_down(self): - data = [ - (('A', '9'), True), (('K', 'A'), True), (('4', '5'), True), - (('A', 'A'), False), (('10', '2'), False), (('10', '9'), False)] - - for variant, (hand, double_down) in enumerate(data, 1): - with self.subTest(f'variation #{variant}', input=hand, output=double_down): - error_msg = f'Hand {hand} {"can" if double_down else "cannot"} be doubled down.' - - self.assertEqual(can_double_down(*hand), double_down, msg=error_msg) + test_data = [(('A', '9'), True), (('K', 'A'), True), + (('4', '5'), True),(('A', 'A'), False), + (('10', '2'), False), (('10', '9'), False)] + + for variant, (hand, expected) in enumerate(test_data, 1): + with self.subTest(f'variation #{variant}', hand=hand, expected=expected): + actual_result = can_double_down(*hand) + error_msg = (f'Called can_double_down({hand[0]}, {hand[1]}). ' + f'The function returned {actual_result}, ' + f'but hand {hand} {"can" if expected else "cannot"} be doubled down.') + + self.assertEqual(actual_result, expected, msg=error_msg) From f3866dd91ce9ac745663221a0e1497037e399049 Mon Sep 17 00:00:00 2001 From: BethanyG Date: Fri, 20 Oct 2023 14:07:24 -0700 Subject: [PATCH 3/3] Revert "Updated test error messages to be more verbose." This reverts commit e800f4ec6db613b21f5d157de7578f0fe8189469. --- .../concept/black-jack/.docs/introduction.md | 4 +- exercises/concept/black-jack/black_jack.py | 1 - .../concept/black-jack/black_jack_test.py | 128 ++++++++---------- 3 files changed, 58 insertions(+), 75 deletions(-) diff --git a/exercises/concept/black-jack/.docs/introduction.md b/exercises/concept/black-jack/.docs/introduction.md index a891289494..207229359d 100644 --- a/exercises/concept/black-jack/.docs/introduction.md +++ b/exercises/concept/black-jack/.docs/introduction.md @@ -59,7 +59,7 @@ True ``` Any ordered comparison of a number to a `NaN` (_not a number_) type is `False`. -A confusing side effect of Python's `NaN` definition is that `NaN` never compares equal to `NaN`. +A confusing side-effect of Python's `NaN` definition is that `NaN` never compares equal to `NaN`. ```python >>> x = float('NaN') @@ -186,7 +186,7 @@ The operators `in` and `not in` test for _membership_. For string and bytes types, ` in ` is `True` _**if and only if**_ `` is a substring of ``. ```python ->>> +>>> # A set of lucky numbers. >>> lucky_numbers = {11, 22, 33} >>> 22 in lucky_numbers diff --git a/exercises/concept/black-jack/black_jack.py b/exercises/concept/black-jack/black_jack.py index 7afade0651..9ce6ca5ba4 100644 --- a/exercises/concept/black-jack/black_jack.py +++ b/exercises/concept/black-jack/black_jack.py @@ -79,4 +79,3 @@ def can_double_down(card_one, card_two): """ pass - diff --git a/exercises/concept/black-jack/black_jack_test.py b/exercises/concept/black-jack/black_jack_test.py index 0962781f0a..79072f95da 100644 --- a/exercises/concept/black-jack/black_jack_test.py +++ b/exercises/concept/black-jack/black_jack_test.py @@ -15,100 +15,84 @@ class BlackJackTest(unittest.TestCase): @pytest.mark.task(taskno=1) def test_value_of_card(self): - test_data = [('2', 2), ('5', 5), ('8', 8), - ('A', 1), ('10', 10), ('J', 10), - ('Q', 10), ('K', 10)] + data = [ + ('2', 2), ('5', 5), ('8', 8), + ('A', 1), ('10', 10), ('J', 10), + ('Q', 10), ('K', 10)] - for variant, (card, expected) in enumerate(test_data, 1): - with self.subTest(f'variation #{variant}', card=card, expected=expected): - actual_result = value_of_card(card) - error_msg = (f'Called value_of_card({card}). ' - f'The function returned {actual_result} as the value of the {card} card, ' - f'but the test expected {expected} as the {card} card value.') - - self.assertEqual(actual_result, expected, msg=error_msg) + for variant, (card, value) in enumerate(data, 1): + with self.subTest(f'variation #{variant}', input=card, output=value): + error_msg = f'Expected {value} as the value of {card}.' + self.assertEqual(value_of_card(card), value, msg=error_msg) @pytest.mark.task(taskno=2) def test_higher_card(self): - test_data = [('A', 'A', ('A', 'A')), - ('10', 'J', ('10', 'J')), - ('3', 'A', '3'), - ('3', '6', '6'), - ('Q', '10', ('Q', '10')), - ('4', '4', ('4', '4')), - ('9', '10', '10'), - ('6', '9', '9'), - ('4', '8', '8')] - - for variant, (card_one, card_two, expected) in enumerate(test_data, 1): - with self.subTest(f'variation #{variant}', card_one=card_one, card_two=card_two, expected=expected): - actual_result = higher_card(card_one, card_two) - error_msg = (f'Called higher_card({card_one}, {card_two}). ' - f'The function returned {actual_result}, ' - f'but the test expected {expected} as the result for the cards {card_one, card_two}.') - - self.assertEqual(actual_result, expected, msg=error_msg) + data = [ + ('A', 'A', ('A', 'A')), + ('10', 'J', ('10', 'J')), + ('3', 'A', '3'), + ('3', '6', '6'), + ('Q', '10', ('Q', '10')), + ('4', '4', ('4', '4')), + ('9', '10', '10'), + ('6', '9', '9'), + ('4', '8', '8')] + + for variant, (card_one, card_two, result) in enumerate(data, 1): + with self.subTest(f'variation #{variant}', card_one=card_one, card_two=card_two, output=result): + error_msg = f'Expected {result} as the higher value of the cards {card_one, card_two}.' + + self.assertEqual(higher_card(card_one, card_two), result, msg=error_msg) @pytest.mark.task(taskno=3) def test_value_of_ace(self): - test_data = [('2', '3', 11), ('3', '6', 11), ('5', '2', 11), - ('8', '2', 11), ('5', '5', 11), ('Q', 'A', 1), - ('10', '2', 1), ('7', '8', 1), ('J', '9', 1), - ('K', 'K', 1), ('2', 'A', 1), ('A', '2', 1)] + data = [ + ('2', '3', 11), ('3', '6', 11), ('5', '2', 11), + ('8', '2', 11), ('5', '5', 11), ('Q', 'A', 1), + ('10', '2', 1), ('7', '8', 1), ('J', '9', 1), + ('K', 'K', 1), ('2', 'A', 1), ('A', '2', 1)] - for variant, (card_one, card_two, ace_value) in enumerate(test_data, 1): + for variant, (card_one, card_two, ace_value) in enumerate(data, 1): with self.subTest(f'variation #{variant}', card_one=card_one, card_two=card_two, ace_value=ace_value): - actual_result = value_of_ace(card_one, card_two) - error_msg = (f'Called value_of_ace({card_one}, {card_two}). ' - f'The function returned {actual_result}, ' - f'but the test expected {ace_value} as the value of an ace card ' - f'when the hand includes {card_one, card_two}.') + error_msg = f'Expected {ace_value} as the value of an ace card when the hand has {card_one, card_two}.' self.assertEqual(value_of_ace(card_one, card_two), ace_value, msg=error_msg) @pytest.mark.task(taskno=4) def test_is_blackjack(self): - test_data = [(('A', 'K'), True), (('10', 'A'), True), - (('10', '9'), False), (('A', 'A'), False), - (('4', '7'), False), (('9', '2'), False), - (('Q', 'K'), False)] + data = [ + (('A', 'K'), True), (('10', 'A'), True), + (('10', '9'), False), (('A', 'A'), False), + (('4', '7'), False), (('9', '2'), False), + (('Q', 'K'), False)] - for variant, (hand, expected) in enumerate(test_data, 1): - with self.subTest(f'variation #{variant}', hand=hand, expected=expected): - actual_result = is_blackjack(*hand) - error_msg = (f'Called is_blackjack({hand[0]}, {hand[1]}). ' - f'The function returned {actual_result}, ' - f'but hand {hand} {"is" if expected else "is not"} a blackjack.') + for variant, (hand, blackjack) in enumerate(data, 1): + with self.subTest(f'variation #{variant}', input=hand, output=blackjack): + error_msg = f'Hand {hand} {"is" if blackjack else "is not"} a blackjack.' - self.assertEqual(actual_result, expected, msg=error_msg) + self.assertEqual(is_blackjack(*hand), blackjack, msg=error_msg) @pytest.mark.task(taskno=5) def test_can_split_pairs(self): - test_data = [(('Q', 'K'), True), (('6', '6'), True), - (('A', 'A'), True),(('10', 'A'), False), - (('10', '9'), False)] + data = [ + (('Q', 'K'), True), (('6', '6'), True), (('A', 'A'), True), + (('10', 'A'), False), (('10', '9'), False)] - for variant, (hand, expected) in enumerate(test_data, 1): - with self.subTest(f'variation #{variant}', input=hand, expected=expected): - actual_result = can_split_pairs(*hand) - error_msg = (f'Called can_split_pairs({hand[0]}, {hand[1]}). ' - f'The function returned {actual_result}, ' - f'but hand {hand} {"can" if expected else "cannot"} be split into pairs.') + for variant, (hand, split_pairs) in enumerate(data, 1): + with self.subTest(f'variation #{variant}', input=hand, output=split_pairs): + error_msg = f'Hand {hand} {"can" if split_pairs else "cannot"} be split into pairs.' - self.assertEqual(actual_result, expected, msg=error_msg) + self.assertEqual(can_split_pairs(*hand), split_pairs, msg=error_msg) @pytest.mark.task(taskno=6) def test_can_double_down(self): - test_data = [(('A', '9'), True), (('K', 'A'), True), - (('4', '5'), True),(('A', 'A'), False), - (('10', '2'), False), (('10', '9'), False)] - - for variant, (hand, expected) in enumerate(test_data, 1): - with self.subTest(f'variation #{variant}', hand=hand, expected=expected): - actual_result = can_double_down(*hand) - error_msg = (f'Called can_double_down({hand[0]}, {hand[1]}). ' - f'The function returned {actual_result}, ' - f'but hand {hand} {"can" if expected else "cannot"} be doubled down.') - - self.assertEqual(actual_result, expected, msg=error_msg) + data = [ + (('A', '9'), True), (('K', 'A'), True), (('4', '5'), True), + (('A', 'A'), False), (('10', '2'), False), (('10', '9'), False)] + + for variant, (hand, double_down) in enumerate(data, 1): + with self.subTest(f'variation #{variant}', input=hand, output=double_down): + error_msg = f'Hand {hand} {"can" if double_down else "cannot"} be doubled down.' + + self.assertEqual(can_double_down(*hand), double_down, msg=error_msg)