Skip to content

Commit

Permalink
[Tisbury Treasure Hunt]: Modified Test Error Messages & Touched Up Do…
Browse files Browse the repository at this point in the history
…cs (#3543)

* Added error messages for tests and touched up docs.
* Corrected username in config.json.
[no important files changed]
  • Loading branch information
BethanyG authored Nov 7, 2023
1 parent cb35445 commit 2e407c7
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 31 deletions.
4 changes: 2 additions & 2 deletions concepts/tuples/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ The elements of a tuple can be iterated over using the `for item in <tuple>` con
If both element index and value are needed, `for index, item in enumerate(<tuple>)` can be used.
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.

[tuple]: https://docs.python.org/3/library/stdtypes.html#tuple
[common sequence operations]: https://docs.python.org/3/library/stdtypes.html#common-sequence-operations
[mutable sequence operations]: https://docs.python.org/3/library/stdtypes.html#mutable-sequence-types
[mutable sequence operations]: https://docs.python.org/3/library/stdtypes.html#mutable-sequence-types
[tuple]: https://docs.python.org/3/library/stdtypes.html#tuple
19 changes: 10 additions & 9 deletions exercises/concept/tisbury-treasure-hunt/.docs/hints.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
## General


[Tuples][tuples] are immutable [sequence Types][sequence types] that can contain any data type.
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.
Other [Common Sequence Operations][common sequence operations] can also be used when working with tuples.
- [Tuples][tuples] are immutable [sequence Types][sequence types] that can contain any data type.
- Tuples are [iterable][iterable]. If you need indexes as well as values, use [`enumerate()`][enumerate]
- 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.

## 1. Extract coordinates

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


[tuples]: https://docs.python.org/3/tutorial/datastructures.html#tuples-and-sequences
[sequence types]: https://docs.python.org/3/library/stdtypes.html#typesseq
[iterable]: https://docs.python.org/3/glossary.html#term-iterable
[bracket notation]: https://stackoverflow.com/questions/30250282/whats-the-difference-between-the-square-bracket-and-dot-notations-in-python
[common sequence operations]: https://docs.python.org/3/library/stdtypes.html#common-sequence-operations
[class tuple]: https://docs.python.org/3/library/stdtypes.html#tuple
[class str]: https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str
[str.format]: https://docs.python.org/3/library/stdtypes.html#str.format
[class tuple]: https://docs.python.org/3/library/stdtypes.html#tuple
[common sequence operations]: https://docs.python.org/3/library/stdtypes.html#common-sequence-operations
[enumerate]: https://docs.python.org/3/library/functions.html#enumerate
[f-strings]: https://docs.python.org/3/tutorial/inputoutput.html#formatted-string-literals
[format specification mini-language]: https://docs.python.org/3/library/string.html#format-specification-mini-language
[iterable]: https://docs.python.org/3/glossary.html#term-iterable
[sequence types]: https://docs.python.org/3/library/stdtypes.html#typesseq
[str.format]: https://docs.python.org/3/library/stdtypes.html#str.format
[testing membership]: https://docs.python.org/3/reference/expressions.html#membership-test-operations
[tuples]: https://docs.python.org/3/tutorial/datastructures.html#tuples-and-sequences
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
In Python, a [tuple][tuple] is an _immutable_ collection of items in _sequence_.
Like most collections, `tuples` can hold any (or multiple) data type(s) -- including other `tuples`.
Tuples support all [common sequence operations][common sequence operations], but **do not** support [mutable sequence operations][mutable sequence operations].

The elements of a tuple can be iterated over using the `for item in <tuple>` construct.
If both element index and value are needed, `for index, item in enumerate(<tuple>)` can be used.
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.
Tuples can also be copied in whole or in part using slice notation (_`<tuple>[<start>:<stop>:<step>]`_).


## Tuple Construction
Expand Down Expand Up @@ -140,5 +142,5 @@ True
```

[common sequence operations]: https://docs.python.org/3/library/stdtypes.html#common-sequence-operations
[mutable sequence operations]: https://docs.python.org/3/library/stdtypes.html#mutable-sequence-types
[tuple]: https://docs.python.org/3/library/stdtypes.html#tuple
[mutable sequence operations]: https://docs.python.org/3/library/stdtypes.html#mutable-sequence-types
2 changes: 1 addition & 1 deletion exercises/concept/tisbury-treasure-hunt/.meta/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"authors": [
"bethanyg"
"BethanyG"
],
"files": {
"solution": [
Expand Down
56 changes: 38 additions & 18 deletions exercises/concept/tisbury-treasure-hunt/tuples_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import unittest
import pytest
from tuples import get_coordinate, convert_coordinate, compare_records, create_record, clean_up
from tuples import (get_coordinate,
convert_coordinate,
compare_records,
create_record,
clean_up)


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

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

for variant, item, result in zip(number_of_variants, input_data, result_data):
with self.subTest(f'variation #{variant}', item=item, result=result):
self.assertEqual(get_coordinate(item), result)
for variant, (item, expected) in enumerate(zip(input_data, result_data), start=1):
with self.subTest(f'variation #{variant}', item=item, expected=expected):
actual_result = get_coordinate(item)
error_message = (f'Called get_coordinate({item}). '
f'The function returned "{actual_result}", but '
f'the tests expected "{expected}" as the coordinates.')

self.assertEqual(actual_result, expected, msg=error_message)

@pytest.mark.task(taskno=2)
def test_convert_coordinate(self):
input_data = ['2A', '4B', '1C', '6D', '7E', '7F', '6A', '8A', '5B', '8C', '1F', '3D', '4E']
input_data = ['2A', '4B', '1C', '6D', '7E', '7F',
'6A', '8A', '5B', '8C', '1F', '3D', '4E']
result_data = [('2', 'A'),
('4', 'B'),
('1', 'C'),
Expand All @@ -45,11 +54,14 @@ def test_convert_coordinate(self):
('3', 'D'),
('4', 'E')]

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

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

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

for variant, item, result in zip(number_of_variants, input_data, result_data):
with self.subTest(f'variation #{variant}', item=item, result=result):
self.assertEqual(compare_records(item[0], item[1]), result)
for variant, (item, expected) in enumerate(zip(input_data, result_data), start=1):
with self.subTest(f'variation #{variant}', item=item, expected=expected):
actual_result = compare_records(item[0], item[1])
error_message = (f'Called compare_records({item[0]}, {item[1]}). '
f'The function returned {actual_result}, but the '
f'tests expected {expected}.')

self.assertEqual(actual_result, expected, msg=error_message)

@pytest.mark.task(taskno=4)
def test_create_record(self):
Expand Down Expand Up @@ -99,11 +115,15 @@ def test_create_record(self):
'not a match'
]

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

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

@pytest.mark.task(taskno=5)
def test_clean_up(self):
Expand Down

0 comments on commit 2e407c7

Please sign in to comment.