Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion exercises/high-scores/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Manage a game player's High Score list.

Your task is to build a high-score component of the classic Frogger game, one of the highest selling and addictive games of all time, and a classic of the arcade era. Your task is to write methods that return the highest score from the list, the last added score, the three highest scores, and a report on the difference between the last and the highest scores.
Your task is to build a high-score component of the classic Frogger game, one of the highest selling and addictive games of all time, and a classic of the arcade era. Your task is to write methods that return the highest score from the list, the last added score and the three highest scores.

## Submitting Exercises

Expand Down
11 changes: 1 addition & 10 deletions exercises/high-scores/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,5 @@ def latest(self):
def personal_best(self):
return max(self.scores)

def personal_top(self):
def personal_top_three(self):
return sorted(self.scores, reverse=True)[:3]

def report(self):
difference = self.personal_best() - self.latest()
result_qualifier = (
"" if difference <= 0 else "{} short of ".format(difference)
)
return "Your latest score was {}. That's {}your personal best!".format(
self.latest(), result_qualifier
)
50 changes: 13 additions & 37 deletions exercises/high-scores/high_scores_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from high_scores import HighScores


# Tests adapted from `problem-specifications//canonical-data.json` @ v2.0.0
# Tests adapted from `problem-specifications//canonical-data.json` @ v4.0.0


class HighScoreTest(unittest.TestCase):
Expand All @@ -22,54 +22,30 @@ def test_personal_best(self):
expected = 100
self.assertEqual(HighScores(scores).personal_best(), expected)

def test_personal_top(self):
scores = [50, 30, 10]
expected = [50, 30, 10]
self.assertEqual(HighScores(scores).personal_top(), expected)
def test_personal_top_three_from_a_long_list(self):
scores = [10, 30, 90, 30, 100, 20, 10, 0, 30, 40, 40, 70, 70]
expected = [100, 90, 70]
self.assertEqual(HighScores(scores).personal_top_three(), expected)

def test_personal_top_highest_to_lowest(self):
def test_personal_top_three_highest_to_lowest(self):
scores = [20, 10, 30]
expected = [30, 20, 10]
self.assertEqual(HighScores(scores).personal_top(), expected)
self.assertEqual(HighScores(scores).personal_top_three(), expected)

def test_personal_top_when_there_is_a_tie(self):
def test_personal_top_three_when_there_is_a_tie(self):
scores = [40, 20, 40, 30]
expected = [40, 40, 30]
self.assertEqual(HighScores(scores).personal_top(), expected)
self.assertEqual(HighScores(scores).personal_top_three(), expected)

def test_personal_top_when_there_are_less_than_3(self):
def test_personal_top_three_when_there_are_less_than_3(self):
scores = [30, 70]
expected = [70, 30]
self.assertEqual(HighScores(scores).personal_top(), expected)
self.assertEqual(HighScores(scores).personal_top_three(), expected)

def test_personal_top_when_there_is_only_one(self):
def test_personal_top_three_when_there_is_only_one(self):
scores = [40]
expected = [40]
self.assertEqual(HighScores(scores).personal_top(), expected)

def test_personal_top_from_a_long_list(self):
scores = [10, 30, 90, 30, 100, 20, 10, 0, 30, 40, 40, 70, 70]
expected = [100, 90, 70]
self.assertEqual(HighScores(scores).personal_top(), expected)

def test_message_for_new_personal_best(self):
scores = [20, 40, 0, 30, 70]
expected = "Your latest score was 70. That's your personal best!"
self.assertEqual(HighScores(scores).report(), expected)

def test_message_when_latest_score_is_not_the_highest_score(self):
scores = [20, 100, 0, 30, 70]
expected = (
"Your latest score was 70. That's 30 short of your personal best!"
)
self.assertEqual(HighScores(scores).report(), expected)

def test_message_for_repeated_personal_best(self):
scores = [20, 70, 50, 70, 30]
expected = (
"Your latest score was 30. That's 40 short of your personal best!"
)
self.assertEqual(HighScores(scores).report(), expected)
self.assertEqual(HighScores(scores).personal_top_three(), expected)


if __name__ == "__main__":
Expand Down