Skip to content

Commit 9c4809a

Browse files
Fix broken f-strings, using black
1 parent 1b09527 commit 9c4809a

File tree

200 files changed

+11013
-3399
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

200 files changed

+11013
-3399
lines changed

exercises/concept/black-jack/.meta/exemplar.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ def value_of_card(card):
1616
3. '2' - '10' = numerical value.
1717
"""
1818

19-
if card in ('JQK'):
19+
if card in ("JQK"):
2020
value = 10
2121

22-
elif card == 'A':
22+
elif card == "A":
2323
value = 1
2424

2525
else:
@@ -65,8 +65,8 @@ def value_of_ace(card_one, card_two):
6565
3. '2' - '10' = numerical value.
6666
"""
6767

68-
card_one_value = 11 if card_one == 'A' else value_of_card(card_one)
69-
card_two_value = 11 if card_two == 'A' else value_of_card(card_two)
68+
card_one_value = 11 if card_one == "A" else value_of_card(card_one)
69+
card_two_value = 11 if card_two == "A" else value_of_card(card_two)
7070

7171
ace_value = 1 if 11 + (card_one_value + card_two_value) > 21 else 11
7272

@@ -84,7 +84,9 @@ def is_blackjack(card_one, card_two):
8484
3. '2' - '10' = numerical value.
8585
"""
8686

87-
return (card_one == 'A' or card_two == 'A') and (value_of_card(card_one) == 10 or value_of_card(card_two) == 10)
87+
return (card_one == "A" or card_two == "A") and (
88+
value_of_card(card_one) == 10 or value_of_card(card_two) == 10
89+
)
8890

8991

9092
def can_split_pairs(card_one, card_two):

exercises/concept/black-jack/black_jack_test.py

Lines changed: 116 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2,113 +2,169 @@
22
import pytest
33

44
from black_jack import (
5-
value_of_card,
6-
higher_card,
7-
value_of_ace,
8-
is_blackjack,
9-
can_split_pairs,
10-
can_double_down
11-
)
5+
value_of_card,
6+
higher_card,
7+
value_of_ace,
8+
is_blackjack,
9+
can_split_pairs,
10+
can_double_down,
11+
)
1212

1313

1414
class BlackJackTest(unittest.TestCase):
1515

1616
@pytest.mark.task(taskno=1)
1717
def test_value_of_card(self):
18-
test_data = [('2', 2), ('5', 5), ('8', 8),
19-
('A', 1), ('10', 10), ('J', 10),
20-
('Q', 10), ('K', 10)]
18+
test_data = [
19+
("2", 2),
20+
("5", 5),
21+
("8", 8),
22+
("A", 1),
23+
("10", 10),
24+
("J", 10),
25+
("Q", 10),
26+
("K", 10),
27+
]
2128

2229
for variant, (card, expected) in enumerate(test_data, 1):
23-
with self.subTest(f'variation #{variant}', card=card, expected=expected):
30+
with self.subTest(f"variation #{variant}", card=card, expected=expected):
2431
actual_result = value_of_card(card)
25-
error_msg = (f'Called value_of_card({card}). '
26-
f'The function returned {actual_result} as the value of the {card} card, '
27-
f'but the test expected {expected} as the {card} card value.')
32+
error_msg = (
33+
f"Called value_of_card({card}). "
34+
f"The function returned {actual_result} as the value of the {card} card, "
35+
f"but the test expected {expected} as the {card} card value."
36+
)
2837

2938
self.assertEqual(actual_result, expected, msg=error_msg)
3039

31-
3240
@pytest.mark.task(taskno=2)
3341
def test_higher_card(self):
34-
test_data = [('A', 'A', ('A', 'A')),
35-
('10', 'J', ('10', 'J')),
36-
('3', 'A', '3'),
37-
('3', '6', '6'),
38-
('Q', '10', ('Q', '10')),
39-
('4', '4', ('4', '4')),
40-
('9', '10', '10'),
41-
('6', '9', '9'),
42-
('4', '8', '8')]
42+
test_data = [
43+
("A", "A", ("A", "A")),
44+
("10", "J", ("10", "J")),
45+
("3", "A", "3"),
46+
("3", "6", "6"),
47+
("Q", "10", ("Q", "10")),
48+
("4", "4", ("4", "4")),
49+
("9", "10", "10"),
50+
("6", "9", "9"),
51+
("4", "8", "8"),
52+
]
4353

4454
for variant, (card_one, card_two, expected) in enumerate(test_data, 1):
45-
with self.subTest(f'variation #{variant}', card_one=card_one, card_two=card_two, expected=expected):
55+
with self.subTest(
56+
f"variation #{variant}",
57+
card_one=card_one,
58+
card_two=card_two,
59+
expected=expected,
60+
):
4661
actual_result = higher_card(card_one, card_two)
47-
error_msg = (f'Called higher_card({card_one}, {card_two}). '
48-
f'The function returned {actual_result}, '
49-
f'but the test expected {expected} as the result for the cards {card_one, card_two}.')
62+
error_msg = (
63+
f"Called higher_card({card_one}, {card_two}). "
64+
f"The function returned {actual_result}, "
65+
f"but the test expected {expected} as the result for the cards {card_one, card_two}."
66+
)
5067

5168
self.assertEqual(actual_result, expected, msg=error_msg)
5269

5370
@pytest.mark.task(taskno=3)
5471
def test_value_of_ace(self):
55-
test_data = [('2', '3', 11), ('3', '6', 11), ('5', '2', 11),
56-
('8', '2', 11), ('5', '5', 11), ('Q', 'A', 1),
57-
('10', '2', 1), ('7', '8', 1), ('J', '9', 1),
58-
('K', 'K', 1), ('2', 'A', 1), ('A', '2', 1)]
72+
test_data = [
73+
("2", "3", 11),
74+
("3", "6", 11),
75+
("5", "2", 11),
76+
("8", "2", 11),
77+
("5", "5", 11),
78+
("Q", "A", 1),
79+
("10", "2", 1),
80+
("7", "8", 1),
81+
("J", "9", 1),
82+
("K", "K", 1),
83+
("2", "A", 1),
84+
("A", "2", 1),
85+
]
5986

6087
for variant, (card_one, card_two, ace_value) in enumerate(test_data, 1):
61-
with self.subTest(f'variation #{variant}', card_one=card_one, card_two=card_two, ace_value=ace_value):
88+
with self.subTest(
89+
f"variation #{variant}",
90+
card_one=card_one,
91+
card_two=card_two,
92+
ace_value=ace_value,
93+
):
6294
actual_result = value_of_ace(card_one, card_two)
63-
error_msg = (f'Called value_of_ace({card_one}, {card_two}). '
64-
f'The function returned {actual_result}, '
65-
f'but the test expected {ace_value} as the value of an ace card '
66-
f'when the hand includes {card_one, card_two}.')
95+
error_msg = (
96+
f"Called value_of_ace({card_one}, {card_two}). "
97+
f"The function returned {actual_result}, "
98+
f"but the test expected {ace_value} as the value of an ace card "
99+
f"when the hand includes {card_one, card_two}."
100+
)
67101

68-
self.assertEqual(value_of_ace(card_one, card_two), ace_value, msg=error_msg)
102+
self.assertEqual(
103+
value_of_ace(card_one, card_two), ace_value, msg=error_msg
104+
)
69105

70106
@pytest.mark.task(taskno=4)
71107
def test_is_blackjack(self):
72-
test_data = [(('A', 'K'), True), (('10', 'A'), True),
73-
(('10', '9'), False), (('A', 'A'), False),
74-
(('4', '7'), False), (('9', '2'), False),
75-
(('Q', 'K'), False)]
108+
test_data = [
109+
(("A", "K"), True),
110+
(("10", "A"), True),
111+
(("10", "9"), False),
112+
(("A", "A"), False),
113+
(("4", "7"), False),
114+
(("9", "2"), False),
115+
(("Q", "K"), False),
116+
]
76117

77118
for variant, (hand, expected) in enumerate(test_data, 1):
78-
with self.subTest(f'variation #{variant}', hand=hand, expected=expected):
119+
with self.subTest(f"variation #{variant}", hand=hand, expected=expected):
79120
actual_result = is_blackjack(*hand)
80-
error_msg = (f'Called is_blackjack({hand[0]}, {hand[1]}). '
81-
f'The function returned {actual_result}, '
82-
f'but hand {hand} {"is" if expected else "is not"} a blackjack.')
121+
error_msg = (
122+
f"Called is_blackjack({hand[0]}, {hand[1]}). "
123+
f"The function returned {actual_result}, "
124+
f'but hand {hand} {"is" if expected else "is not"} a blackjack.'
125+
)
83126

84127
self.assertEqual(actual_result, expected, msg=error_msg)
85128

86129
@pytest.mark.task(taskno=5)
87130
def test_can_split_pairs(self):
88-
test_data = [(('Q', 'K'), True), (('6', '6'), True),
89-
(('A', 'A'), True),(('10', 'A'), False),
90-
(('10', '9'), False)]
131+
test_data = [
132+
(("Q", "K"), True),
133+
(("6", "6"), True),
134+
(("A", "A"), True),
135+
(("10", "A"), False),
136+
(("10", "9"), False),
137+
]
91138

92139
for variant, (hand, expected) in enumerate(test_data, 1):
93-
with self.subTest(f'variation #{variant}', input=hand, expected=expected):
140+
with self.subTest(f"variation #{variant}", input=hand, expected=expected):
94141
actual_result = can_split_pairs(*hand)
95-
error_msg = (f'Called can_split_pairs({hand[0]}, {hand[1]}). '
96-
f'The function returned {actual_result}, '
97-
f'but hand {hand} {"can" if expected else "cannot"} be split into pairs.')
142+
error_msg = (
143+
f"Called can_split_pairs({hand[0]}, {hand[1]}). "
144+
f"The function returned {actual_result}, "
145+
f'but hand {hand} {"can" if expected else "cannot"} be split into pairs.'
146+
)
98147

99148
self.assertEqual(actual_result, expected, msg=error_msg)
100149

101150
@pytest.mark.task(taskno=6)
102151
def test_can_double_down(self):
103-
test_data = [(('A', '9'), True), (('K', 'A'), True),
104-
(('4', '5'), True),(('A', 'A'), False),
105-
(('10', '2'), False), (('10', '9'), False)]
152+
test_data = [
153+
(("A", "9"), True),
154+
(("K", "A"), True),
155+
(("4", "5"), True),
156+
(("A", "A"), False),
157+
(("10", "2"), False),
158+
(("10", "9"), False),
159+
]
106160

107161
for variant, (hand, expected) in enumerate(test_data, 1):
108-
with self.subTest(f'variation #{variant}', hand=hand, expected=expected):
162+
with self.subTest(f"variation #{variant}", hand=hand, expected=expected):
109163
actual_result = can_double_down(*hand)
110-
error_msg = (f'Called can_double_down({hand[0]}, {hand[1]}). '
111-
f'The function returned {actual_result}, '
112-
f'but hand {hand} {"can" if expected else "cannot"} be doubled down.')
164+
error_msg = (
165+
f"Called can_double_down({hand[0]}, {hand[1]}). "
166+
f"The function returned {actual_result}, "
167+
f'but hand {hand} {"can" if expected else "cannot"} be doubled down.'
168+
)
113169

114170
self.assertEqual(actual_result, expected, msg=error_msg)

0 commit comments

Comments
 (0)