Skip to content

Commit 6b8d98e

Browse files
pranasziaukasBethanyG
authored andcommitted
Improve tests of card-games exercise
1 parent a29bde8 commit 6b8d98e

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

exercises/concept/card-games/.meta/exemplar.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,14 @@ def approx_average_is_average(hand):
5252
:return: bool - is approximate average the same as true average?
5353
"""
5454

55-
return card_average([hand[0], hand[-1]]) == card_average(hand)
55+
real_average = card_average(hand)
56+
if card_average([hand[0], hand[-1]]) == real_average:
57+
is_same = True
58+
elif hand[len(hand) // 2] == real_average:
59+
is_same = True
60+
else:
61+
is_same = False
62+
return is_same
5663

5764

5865
def average_even_is_average_odd(hand):

exercises/concept/card-games/lists_test.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ def test_empty(self):
6060
want = []
6161

6262
self.assertEqual(concatenate_rounds(rounds_1, rounds_2),
63-
want,
64-
msg=f'Expected {want} but got an incorrect result.'
65-
)
63+
want,
64+
msg=f'Expected {want} but got an incorrect result.'
65+
)
6666

6767
@pytest.mark.task(taskno=2)
6868
def test_other(self):
@@ -209,6 +209,18 @@ def test_instructions_example_3(self):
209209
msg=f'Expected {want} but got an incorrect result: {got!r}'
210210
)
211211

212+
@pytest.mark.task(taskno=5)
213+
def test_median_true(self):
214+
hand = [1, 2, 4, 5, 8]
215+
want = True
216+
got = approx_average_is_average(hand)
217+
218+
self.assertEqual(
219+
want,
220+
got,
221+
msg=f'Expected {want} but got an incorrect result: {got!r}'
222+
)
223+
212224
@pytest.mark.task(taskno=5)
213225
def test_other_true(self):
214226
hand = [2, 3, 4]

0 commit comments

Comments
 (0)