Skip to content

high-scores: add tests to prevent solutions that mutate 'scores' #1874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
21 changes: 21 additions & 0 deletions exercises/high-scores/high_scores_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,27 @@ def test_personal_top_when_there_is_only_one(self):
expected = [40]
self.assertEqual(personal_top_three(scores), expected)

def test_latest_doesnt_mutate_scores(self):
# make sure latest doesn't affect/damage our original object
scores = [20, 10, 30]
scores_backup = list(scores)
_unused = latest(scores)
self.assertEqual(scores, scores_backup)

def test_personal_best_doesnt_mutate_scores(self):
# make sure personal_best doesn't affect/damage our original object
scores = [20, 10, 30, 50, 40, 10]
scores_backup = list(scores)
_unused = personal_best(scores)
self.assertEqual(scores, scores_backup)

def test_personal_top_three_doesnt_mutate_scores(self):
# make sure personal_top_three doesn't affect/damage our original object
scores = [10, 30, 90, 30, 100, 20, 10, 0, 30, 40, 40, 70, 70]
scores_backup = list(scores)
_unused = personal_top_three(scores)
self.assertEqual(scores, scores_backup)


if __name__ == "__main__":
unittest.main()