Skip to content

Commit 538e2d9

Browse files
authored
Changed test error messages to sync with runner changes. Other misc. changes and typo corrections. (#3523)
[no important files changed]
1 parent b966f79 commit 538e2d9

File tree

4 files changed

+90
-80
lines changed

4 files changed

+90
-80
lines changed

concepts/comparisons/about.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Numeric types are (mostly) an exception to this type matching rule.
2929
An `integer` **can** be considered equal to a `float` (_or an [`octal`][octal] equal to a [`hexadecimal`][hex]_), as long as the types can be implicitly converted for comparison.
3030

3131
For the other numeric types ([complex][complex numbers], [decimal][decimal numbers], [fractions][rational numbers]), comparison operators are defined where they "make sense" (_where implicit conversion does not change the outcome_), but throw a `TypeError` if the underlying objects cannot be accurately converted for comparison.
32-
For more information on the rules that python uses for numeric conversion, see [arithmetic conversions][arithmetic conversions] in the Python documentation.
32+
For more information on the rules that Python uses for numeric conversion, see [arithmetic conversions][arithmetic conversions] in the Python documentation.
3333

3434
```python
3535
>>> import fractions
@@ -47,7 +47,8 @@ True
4747
>>> 6/3 == 0b10
4848
True
4949

50-
# An int can be converted to a complex number with a 0 imaginary part.
50+
# An int can be converted to a complex
51+
# number with a 0 imaginary part.
5152
>>> 17 == complex(17)
5253
True
5354

@@ -60,8 +61,8 @@ True
6061
```
6162

6263
Any ordered comparison of a number to a `NaN` (_not a number_) type is `False`.
63-
A confusing side-effect of Python's `NaN` definition is that `NaN` never compares equal to `NaN`.
64-
If you are curious as to why `Nan` was defined this way in Python, this [Stack Overflow Post on NaN][so nan post] around the setting of the international standard is an interesting read.
64+
A confusing side effect of Python's `NaN` definition is that `NaN` never compares equal to `NaN`.
65+
If you are curious as to why `NaN` was defined this way in Python, this [Stack Overflow Post on NaN][so nan post] around the setting of the international standard is an interesting read.
6566

6667
```python
6768
>>> x = float('NaN')
@@ -188,7 +189,7 @@ See the Python reference docs on [value comparisons][value comparisons none] and
188189
>>> my_fav_numbers is your_fav_numbers
189190
True
190191

191-
# The returned id will differ by system and python version.
192+
# The returned id will differ by system and Python version.
192193
>>> id(my_fav_numbers)
193194
4517478208
194195

concepts/comparisons/links.json

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,19 @@
11
[
2-
{
3-
"url": "https://docs.python.org/3/reference/expressions.html#comparisons",
4-
"description": "Comparisons in Python (Python language reference)"
5-
},
62
{
73
"url": "https://www.tutorialspoint.com/python/python_basic_operators.htm",
84
"description": "Python basic operators on Tutorials Point"
95
},
106
{
11-
"url": "https://data-flair.training/blogs/python-comparison-operators/",
12-
"description": "Python comparison operators on Data Flair"
13-
},
14-
{
15-
"url": "https://www.python.org/dev/peps/pep-0207/",
16-
"description": "PEP 207 to allow Operator Overloading for Comparison"
7+
"url": "https://docs.python.org/3/reference/expressions.html#comparisons",
8+
"description": "Comparisons in Python (Python language reference)"
179
},
1810
{
1911
"url": "https://docs.python.org/3/reference/expressions.html#is-not",
2012
"description": "Identity comparisons in Python (Python language reference)"
2113
},
2214
{
23-
"url": "https://docs.python.org/3/library/operator.html",
24-
"description": "Operators (Python Docs)"
15+
"url": "https://docs.python.org/3/reference/expressions.html#value-comparisons",
16+
"description": "Value comparisons in Python (Python language reference)"
2517
},
2618
{
2719
"url": "https://docs.python.org/3/library/stdtypes.html#typesnumeric",
@@ -44,11 +36,11 @@
4436
"description": "Python Object Model (Python docs)"
4537
},
4638
{
47-
"url": "https://docs.python.org/3/reference/datamodel.html#customization",
48-
"description": "Basic Customization (Python language reference)"
39+
"url": "https://www.python.org/dev/peps/pep-0207/",
40+
"description": "PEP 207 to allow Operator Overloading for Comparison"
4941
},
5042
{
51-
"url": "https://docs.python.org/3/reference/expressions.html#value-comparisons",
52-
"description": "Value comparisons in Python (Python language reference)"
43+
"url": "https://docs.python.org/3/reference/datamodel.html#customization",
44+
"description": "Basic Customization (Python language reference)"
5345
}
5446
]

exercises/concept/black-jack/.docs/introduction.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ True
5959
```
6060

6161
Any ordered comparison of a number to a `NaN` (_not a number_) type is `False`.
62-
A confusing side-effect of Python's `NaN` definition is that `NaN` never compares equal to `NaN`.
62+
A confusing side effect of Python's `NaN` definition is that `NaN` never compares equal to `NaN`.
6363

6464
```python
6565
>>> x = float('NaN')
@@ -186,7 +186,6 @@ The operators `in` and `not in` test for _membership_.
186186
For string and bytes types, `<name> in <fullname>` is `True` _**if and only if**_ `<name>` is a substring of `<fullname>`.
187187

188188
```python
189-
>>>
190189
# A set of lucky numbers.
191190
>>> lucky_numbers = {11, 22, 33}
192191
>>> 22 in lucky_numbers
@@ -196,7 +195,9 @@ True
196195
False
197196

198197
# A dictionary of employee information.
199-
>>> employee = {'name': 'John Doe', 'id': 67826, 'age': 33, 'title': 'ceo'}
198+
>>> employee = {'name': 'John Doe',
199+
'id': 67826, 'age': 33,
200+
'title': 'ceo'}
200201

201202
# Checking for the membership of certain keys.
202203
>>> 'age' in employee

exercises/concept/black-jack/black_jack_test.py

Lines changed: 72 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -15,84 +15,100 @@ class BlackJackTest(unittest.TestCase):
1515

1616
@pytest.mark.task(taskno=1)
1717
def test_value_of_card(self):
18-
data = [
19-
('2', 2), ('5', 5), ('8', 8),
20-
('A', 1), ('10', 10), ('J', 10),
21-
('Q', 10), ('K', 10)]
18+
test_data = [('2', 2), ('5', 5), ('8', 8),
19+
('A', 1), ('10', 10), ('J', 10),
20+
('Q', 10), ('K', 10)]
2221

23-
for variant, (card, value) in enumerate(data, 1):
24-
with self.subTest(f'variation #{variant}', input=card, output=value):
25-
error_msg = f'Expected {value} as the value of {card}.'
22+
for variant, (card, expected) in enumerate(test_data, 1):
23+
with self.subTest(f'variation #{variant}', card=card, expected=expected):
24+
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.')
28+
29+
self.assertEqual(actual_result, expected, msg=error_msg)
2630

27-
self.assertEqual(value_of_card(card), value, msg=error_msg)
2831

2932
@pytest.mark.task(taskno=2)
3033
def test_higher_card(self):
31-
data = [
32-
('A', 'A', ('A', 'A')),
33-
('10', 'J', ('10', 'J')),
34-
('3', 'A', '3'),
35-
('3', '6', '6'),
36-
('Q', '10', ('Q', '10')),
37-
('4', '4', ('4', '4')),
38-
('9', '10', '10'),
39-
('6', '9', '9'),
40-
('4', '8', '8')]
41-
42-
for variant, (card_one, card_two, result) in enumerate(data, 1):
43-
with self.subTest(f'variation #{variant}', card_one=card_one, card_two=card_two, output=result):
44-
error_msg = f'Expected {result} as the higher value of the cards {card_one, card_two}.'
45-
46-
self.assertEqual(higher_card(card_one, card_two), result, msg=error_msg)
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')]
43+
44+
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):
46+
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}.')
50+
51+
self.assertEqual(actual_result, expected, msg=error_msg)
4752

4853
@pytest.mark.task(taskno=3)
4954
def test_value_of_ace(self):
50-
data = [
51-
('2', '3', 11), ('3', '6', 11), ('5', '2', 11),
52-
('8', '2', 11), ('5', '5', 11), ('Q', 'A', 1),
53-
('10', '2', 1), ('7', '8', 1), ('J', '9', 1),
54-
('K', 'K', 1), ('2', 'A', 1), ('A', '2', 1)]
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)]
5559

56-
for variant, (card_one, card_two, ace_value) in enumerate(data, 1):
60+
for variant, (card_one, card_two, ace_value) in enumerate(test_data, 1):
5761
with self.subTest(f'variation #{variant}', card_one=card_one, card_two=card_two, ace_value=ace_value):
58-
error_msg = f'Expected {ace_value} as the value of an ace card when the hand has {card_one, card_two}.'
62+
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}.')
5967

6068
self.assertEqual(value_of_ace(card_one, card_two), ace_value, msg=error_msg)
6169

6270
@pytest.mark.task(taskno=4)
6371
def test_is_blackjack(self):
64-
data = [
65-
(('A', 'K'), True), (('10', 'A'), True),
66-
(('10', '9'), False), (('A', 'A'), False),
67-
(('4', '7'), False), (('9', '2'), False),
68-
(('Q', 'K'), False)]
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)]
6976

70-
for variant, (hand, blackjack) in enumerate(data, 1):
71-
with self.subTest(f'variation #{variant}', input=hand, output=blackjack):
72-
error_msg = f'Hand {hand} {"is" if blackjack else "is not"} a blackjack.'
77+
for variant, (hand, expected) in enumerate(test_data, 1):
78+
with self.subTest(f'variation #{variant}', hand=hand, expected=expected):
79+
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.')
7383

74-
self.assertEqual(is_blackjack(*hand), blackjack, msg=error_msg)
84+
self.assertEqual(actual_result, expected, msg=error_msg)
7585

7686
@pytest.mark.task(taskno=5)
7787
def test_can_split_pairs(self):
78-
data = [
79-
(('Q', 'K'), True), (('6', '6'), True), (('A', 'A'), True),
80-
(('10', 'A'), False), (('10', '9'), False)]
88+
test_data = [(('Q', 'K'), True), (('6', '6'), True),
89+
(('A', 'A'), True),(('10', 'A'), False),
90+
(('10', '9'), False)]
8191

82-
for variant, (hand, split_pairs) in enumerate(data, 1):
83-
with self.subTest(f'variation #{variant}', input=hand, output=split_pairs):
84-
error_msg = f'Hand {hand} {"can" if split_pairs else "cannot"} be split into pairs.'
92+
for variant, (hand, expected) in enumerate(test_data, 1):
93+
with self.subTest(f'variation #{variant}', input=hand, expected=expected):
94+
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.')
8598

86-
self.assertEqual(can_split_pairs(*hand), split_pairs, msg=error_msg)
99+
self.assertEqual(actual_result, expected, msg=error_msg)
87100

88101
@pytest.mark.task(taskno=6)
89102
def test_can_double_down(self):
90-
data = [
91-
(('A', '9'), True), (('K', 'A'), True), (('4', '5'), True),
92-
(('A', 'A'), False), (('10', '2'), False), (('10', '9'), False)]
93-
94-
for variant, (hand, double_down) in enumerate(data, 1):
95-
with self.subTest(f'variation #{variant}', input=hand, output=double_down):
96-
error_msg = f'Hand {hand} {"can" if double_down else "cannot"} be doubled down.'
97-
98-
self.assertEqual(can_double_down(*hand), double_down, msg=error_msg)
103+
test_data = [(('A', '9'), True), (('K', 'A'), True),
104+
(('4', '5'), True),(('A', 'A'), False),
105+
(('10', '2'), False), (('10', '9'), False)]
106+
107+
for variant, (hand, expected) in enumerate(test_data, 1):
108+
with self.subTest(f'variation #{variant}', hand=hand, expected=expected):
109+
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.')
113+
114+
self.assertEqual(actual_result, expected, msg=error_msg)

0 commit comments

Comments
 (0)