Skip to content

Commit 2e407c7

Browse files
authored
[Tisbury Treasure Hunt]: Modified Test Error Messages & Touched Up Docs (#3543)
* Added error messages for tests and touched up docs. * Corrected username in config.json. [no important files changed]
1 parent cb35445 commit 2e407c7

File tree

5 files changed

+54
-31
lines changed

5 files changed

+54
-31
lines changed

concepts/tuples/introduction.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ The elements of a tuple can be iterated over using the `for item in <tuple>` con
77
If both element index and value are needed, `for index, item in enumerate(<tuple>)` can be used.
88
Like any sequence, elements within `tuples` can be accessed via _bracket notation_ using a `0-based index` number from the left or a `-1-based index` number from the right.
99

10-
[tuple]: https://docs.python.org/3/library/stdtypes.html#tuple
1110
[common sequence operations]: https://docs.python.org/3/library/stdtypes.html#common-sequence-operations
12-
[mutable sequence operations]: https://docs.python.org/3/library/stdtypes.html#mutable-sequence-types
11+
[mutable sequence operations]: https://docs.python.org/3/library/stdtypes.html#mutable-sequence-types
12+
[tuple]: https://docs.python.org/3/library/stdtypes.html#tuple

exercises/concept/tisbury-treasure-hunt/.docs/hints.md

+10-9
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
## General
44

55

6-
[Tuples][tuples] are immutable [sequence Types][sequence types] that can contain any data type.
7-
Tuples are [iterable][iterable], and elements within tuples can be accessed via [bracket notation][bracket notation], using a zero-based index from the left, or -1 from the right.
8-
Other [Common Sequence Operations][common sequence operations] can also be used when working with tuples.
6+
- [Tuples][tuples] are immutable [sequence Types][sequence types] that can contain any data type.
7+
- Tuples are [iterable][iterable]. If you need indexes as well as values, use [`enumerate()`][enumerate]
8+
- Elements within tuples can be accessed via [bracket notation][bracket notation], using a zero-based index from the left, or -1 from the right. Other [Common Sequence Operations][common sequence operations] can also be used when working with tuples.
99

1010
## 1. Extract coordinates
1111

@@ -35,14 +35,15 @@ Other [Common Sequence Operations][common sequence operations] can also be used
3535
- There are multiple textual formatting options available via Pythons [`format specification mini-language`][format specification mini-language].
3636

3737

38-
[tuples]: https://docs.python.org/3/tutorial/datastructures.html#tuples-and-sequences
39-
[sequence types]: https://docs.python.org/3/library/stdtypes.html#typesseq
40-
[iterable]: https://docs.python.org/3/glossary.html#term-iterable
4138
[bracket notation]: https://stackoverflow.com/questions/30250282/whats-the-difference-between-the-square-bracket-and-dot-notations-in-python
42-
[common sequence operations]: https://docs.python.org/3/library/stdtypes.html#common-sequence-operations
43-
[class tuple]: https://docs.python.org/3/library/stdtypes.html#tuple
4439
[class str]: https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str
45-
[str.format]: https://docs.python.org/3/library/stdtypes.html#str.format
40+
[class tuple]: https://docs.python.org/3/library/stdtypes.html#tuple
41+
[common sequence operations]: https://docs.python.org/3/library/stdtypes.html#common-sequence-operations
42+
[enumerate]: https://docs.python.org/3/library/functions.html#enumerate
4643
[f-strings]: https://docs.python.org/3/tutorial/inputoutput.html#formatted-string-literals
4744
[format specification mini-language]: https://docs.python.org/3/library/string.html#format-specification-mini-language
45+
[iterable]: https://docs.python.org/3/glossary.html#term-iterable
46+
[sequence types]: https://docs.python.org/3/library/stdtypes.html#typesseq
47+
[str.format]: https://docs.python.org/3/library/stdtypes.html#str.format
4848
[testing membership]: https://docs.python.org/3/reference/expressions.html#membership-test-operations
49+
[tuples]: https://docs.python.org/3/tutorial/datastructures.html#tuples-and-sequences

exercises/concept/tisbury-treasure-hunt/.docs/introduction.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
In Python, a [tuple][tuple] is an _immutable_ collection of items in _sequence_.
44
Like most collections, `tuples` can hold any (or multiple) data type(s) -- including other `tuples`.
55
Tuples support all [common sequence operations][common sequence operations], but **do not** support [mutable sequence operations][mutable sequence operations].
6+
67
The elements of a tuple can be iterated over using the `for item in <tuple>` construct.
78
If both element index and value are needed, `for index, item in enumerate(<tuple>)` can be used.
89
Like any sequence, elements within `tuples` can be accessed via _bracket notation_ using a `0-based index` number from the left or a `-1-based index` number from the right.
10+
Tuples can also be copied in whole or in part using slice notation (_`<tuple>[<start>:<stop>:<step>]`_).
911

1012

1113
## Tuple Construction
@@ -140,5 +142,5 @@ True
140142
```
141143

142144
[common sequence operations]: https://docs.python.org/3/library/stdtypes.html#common-sequence-operations
145+
[mutable sequence operations]: https://docs.python.org/3/library/stdtypes.html#mutable-sequence-types
143146
[tuple]: https://docs.python.org/3/library/stdtypes.html#tuple
144-
[mutable sequence operations]: https://docs.python.org/3/library/stdtypes.html#mutable-sequence-types

exercises/concept/tisbury-treasure-hunt/.meta/config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"authors": [
3-
"bethanyg"
3+
"BethanyG"
44
],
55
"files": {
66
"solution": [

exercises/concept/tisbury-treasure-hunt/tuples_test.py

+38-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import unittest
22
import pytest
3-
from tuples import get_coordinate, convert_coordinate, compare_records, create_record, clean_up
3+
from tuples import (get_coordinate,
4+
convert_coordinate,
5+
compare_records,
6+
create_record,
7+
clean_up)
48

59

610
class TisburyTreasureTest(unittest.TestCase):
@@ -22,15 +26,20 @@ def test_get_coordinate(self):
2226
('Silver Seahorse', '4E')]
2327

2428
result_data = ['2A', '4B', '1C', '6D', '7E', '7F', '6A', '8A', '5B', '8C', '1F', '3D', '4E']
25-
number_of_variants = range(1, len(input_data) + 1)
2629

27-
for variant, item, result in zip(number_of_variants, input_data, result_data):
28-
with self.subTest(f'variation #{variant}', item=item, result=result):
29-
self.assertEqual(get_coordinate(item), result)
30+
for variant, (item, expected) in enumerate(zip(input_data, result_data), start=1):
31+
with self.subTest(f'variation #{variant}', item=item, expected=expected):
32+
actual_result = get_coordinate(item)
33+
error_message = (f'Called get_coordinate({item}). '
34+
f'The function returned "{actual_result}", but '
35+
f'the tests expected "{expected}" as the coordinates.')
36+
37+
self.assertEqual(actual_result, expected, msg=error_message)
3038

3139
@pytest.mark.task(taskno=2)
3240
def test_convert_coordinate(self):
33-
input_data = ['2A', '4B', '1C', '6D', '7E', '7F', '6A', '8A', '5B', '8C', '1F', '3D', '4E']
41+
input_data = ['2A', '4B', '1C', '6D', '7E', '7F',
42+
'6A', '8A', '5B', '8C', '1F', '3D', '4E']
3443
result_data = [('2', 'A'),
3544
('4', 'B'),
3645
('1', 'C'),
@@ -45,11 +54,14 @@ def test_convert_coordinate(self):
4554
('3', 'D'),
4655
('4', 'E')]
4756

48-
number_of_variants = range(1, len(input_data) + 1)
57+
for variant, (item, expected) in enumerate(zip(input_data, result_data), start=1):
58+
with self.subTest(f'variation #{variant}', item=item, expected=expected):
59+
actual_result = convert_coordinate(item)
60+
error_message = (f'Called convert_coordinate({item}). '
61+
f'The function returned {actual_result}, but the '
62+
f'tests expected {expected} as the converted coordinate.')
4963

50-
for variant, item, result in zip(number_of_variants, input_data, result_data):
51-
with self.subTest(f'variation #{variant}', item=item, result=result):
52-
self.assertEqual(convert_coordinate(item), result)
64+
self.assertEqual(actual_result, expected, msg=error_message)
5365

5466
@pytest.mark.task(taskno=3)
5567
def test_compare_records(self):
@@ -66,11 +78,15 @@ def test_compare_records(self):
6678
(('Carved Wooden Elephant', '8C'), ('Abandoned Lighthouse', ('4', 'B'), 'Blue'))
6779
]
6880
result_data = [True, True, True, True, True, False, False, False, False, False]
69-
number_of_variants = range(1, len(input_data) + 1)
7081

71-
for variant, item, result in zip(number_of_variants, input_data, result_data):
72-
with self.subTest(f'variation #{variant}', item=item, result=result):
73-
self.assertEqual(compare_records(item[0], item[1]), result)
82+
for variant, (item, expected) in enumerate(zip(input_data, result_data), start=1):
83+
with self.subTest(f'variation #{variant}', item=item, expected=expected):
84+
actual_result = compare_records(item[0], item[1])
85+
error_message = (f'Called compare_records({item[0]}, {item[1]}). '
86+
f'The function returned {actual_result}, but the '
87+
f'tests expected {expected}.')
88+
89+
self.assertEqual(actual_result, expected, msg=error_message)
7490

7591
@pytest.mark.task(taskno=4)
7692
def test_create_record(self):
@@ -99,11 +115,15 @@ def test_create_record(self):
99115
'not a match'
100116
]
101117

102-
number_of_variants = range(1, len(input_data) + 1)
118+
for variant, (item, expected) in enumerate(zip(input_data, result_data), start=1):
119+
with self.subTest(f'variation #{variant}', item=item, expected=expected):
120+
actual_result = create_record(item[0], item[1])
121+
error_message = (f'Called create_record({item[0]},{item[1]}). '
122+
f'The function returned '
123+
f'{actual_result}, but the tests expected '
124+
f'{expected} for the record.')
103125

104-
for variant, item, result in zip(number_of_variants, input_data, result_data):
105-
with self.subTest(f'variation #{variant}', item=item, result=result):
106-
self.assertEqual(create_record(item[0], item[1]), result)
126+
self.assertEqual(actual_result, expected, msg=error_message)
107127

108128
@pytest.mark.task(taskno=5)
109129
def test_clean_up(self):

0 commit comments

Comments
 (0)