* Simplify High-scores exercise. Replace Class with functions Exercise text edited. Tests made to expect functions. One test removed, cause was no longer valid. Make new example.py using functions. Add the functions as starting point in the exercise file. (This also make the tests not complain of missing imports and such.) Added __init__.py to the package for the people that still run 2.7+ Added pytest cache to gitignore file * Fix style problems * Made requested changes in PR Remove __init__.py Remove content of HINTS.md Generate the README.md Remove the comments in stub file * Add new hints to high-score Added hints for some docs around list and tuples - thanks @BethanyG for that Moved original hints for classes in matrix ( cause is the next exercise for now which use class) slightly edited to not refer to high-score Regenerate both README.md * Remove changes to matrix from this PR * Update exercises/high-scores/.meta/HINTS.md Co-Authored-By: simmol <simmol@users.noreply.github.com> * Update exercises/matrix/README.md Co-Authored-By: simmol <simmol@users.noreply.github.com> * Regenerate README
49 lines
1.5 KiB
Python
49 lines
1.5 KiB
Python
import unittest
|
|
|
|
from high_scores import latest, personal_best, personal_top_three
|
|
|
|
|
|
# Tests adapted from `problem-specifications//canonical-data.json` @ v4.0.0
|
|
|
|
|
|
class HighScoreTest(unittest.TestCase):
|
|
|
|
def test_latest_score(self):
|
|
scores = [100, 0, 90, 30]
|
|
expected = 30
|
|
self.assertEqual(latest(scores), expected)
|
|
|
|
def test_personal_best(self):
|
|
scores = [40, 100, 70]
|
|
expected = 100
|
|
self.assertEqual(personal_best(scores), 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(personal_top_three(scores), expected)
|
|
|
|
def test_personal_top_three_highest_to_lowest(self):
|
|
scores = [20, 10, 30]
|
|
expected = [30, 20, 10]
|
|
self.assertEqual(personal_top_three(scores), expected)
|
|
|
|
def test_personal_top_three_when_there_is_a_tie(self):
|
|
scores = [40, 20, 40, 30]
|
|
expected = [40, 40, 30]
|
|
self.assertEqual(personal_top_three(scores), expected)
|
|
|
|
def test_personal_top_three_when_there_are_less_than_3(self):
|
|
scores = [30, 70]
|
|
expected = [70, 30]
|
|
self.assertEqual(personal_top_three(scores), expected)
|
|
|
|
def test_personal_top_three_when_there_is_only_one(self):
|
|
scores = [40]
|
|
expected = [40]
|
|
self.assertEqual(personal_top_three(scores), expected)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|