From f3fd126ba378b83d669d5707c3beecee506b8a65 Mon Sep 17 00:00:00 2001 From: Pavlin Angelov Date: Mon, 22 Apr 2019 08:58:17 +0300 Subject: [PATCH 1/8] 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 --- .gitignore | 1 + exercises/high-scores/README.md | 10 +--------- exercises/high-scores/__init__.py | 0 exercises/high-scores/example.py | 16 ++++++---------- exercises/high-scores/high_scores.py | 11 ++++++++--- exercises/high-scores/high_scores_test.py | 22 +++++++++------------- 6 files changed, 25 insertions(+), 35 deletions(-) create mode 100644 exercises/high-scores/__init__.py diff --git a/.gitignore b/.gitignore index edce8452bf..6f97f3570a 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ bin/configlet bin/configlet.exe .idea/ .cache +.pytest_cache __pycache__ diff --git a/exercises/high-scores/README.md b/exercises/high-scores/README.md index 6b08db6eb9..bdfc8d28fc 100644 --- a/exercises/high-scores/README.md +++ b/exercises/high-scores/README.md @@ -2,15 +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 and the three highest scores. - -In this exercise you're going to create a **class** and use lists to organize scores. _Don't worry, it's not as complicated as you think!_ - -- [**A First Look at Classes**](https://docs.python.org/3/tutorial/classes.html#a-first-look-at-classes) from the Python 3 documentation. -- [**How to Define a Class in Python**](https://realpython.com/python3-object-oriented-programming/#how-to-define-a-class-in-python) from the Real Python website. -- [**Data Structures in Python**](https://docs.python.org/3/tutorial/datastructures.html) from the Python 3 documentation. - - +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 three functions that from the original score list will return the highest score, the last added score and the three highest scores respectivly. ## Exception messages diff --git a/exercises/high-scores/__init__.py b/exercises/high-scores/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/exercises/high-scores/example.py b/exercises/high-scores/example.py index 0c77d73af8..6caece7bdd 100644 --- a/exercises/high-scores/example.py +++ b/exercises/high-scores/example.py @@ -1,12 +1,8 @@ -class HighScores(object): - def __init__(self, scores): - self.scores = scores +def latest(scores): + return scores[-1] - def latest(self): - return self.scores[-1] +def personal_best(scores): + return max(scores) - def personal_best(self): - return max(self.scores) - - def personal_top_three(self): - return sorted(self.scores, reverse=True)[:3] +def personal_top_three(scores): + return sorted(scores, reverse=True)[:3] diff --git a/exercises/high-scores/high_scores.py b/exercises/high-scores/high_scores.py index 3bfba4d0b5..84f5172b77 100644 --- a/exercises/high-scores/high_scores.py +++ b/exercises/high-scores/high_scores.py @@ -1,3 +1,8 @@ -class HighScores(object): - def __init__(self, scores): - pass +def latest(scores): + pass # Put your code here + +def personal_best(scores): + pass # Put your code here + +def personal_top_three(scores): + pass # Put your code here diff --git a/exercises/high-scores/high_scores_test.py b/exercises/high-scores/high_scores_test.py index 17d69c0e15..b0e7c57850 100644 --- a/exercises/high-scores/high_scores_test.py +++ b/exercises/high-scores/high_scores_test.py @@ -1,51 +1,47 @@ import unittest -from high_scores import HighScores +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_list_of_scores(self): - scores = [30, 50, 20, 70] - expected = [30, 50, 20, 70] - self.assertEqual(HighScores(scores).scores, expected) - + def test_latest_score(self): scores = [100, 0, 90, 30] expected = 30 - self.assertEqual(HighScores(scores).latest(), expected) + self.assertEqual(latest(scores), expected) def test_personal_best(self): scores = [40, 100, 70] expected = 100 - self.assertEqual(HighScores(scores).personal_best(), expected) + 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(HighScores(scores).personal_top_three(), expected) + 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(HighScores(scores).personal_top_three(), expected) + 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(HighScores(scores).personal_top_three(), expected) + 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(HighScores(scores).personal_top_three(), expected) + self.assertEqual(personal_top_three(scores), expected) def test_personal_top_three_when_there_is_only_one(self): scores = [40] expected = [40] - self.assertEqual(HighScores(scores).personal_top_three(), expected) + self.assertEqual(personal_top_three(scores), expected) if __name__ == "__main__": From e35893792683770019e77450ccc0a6c4179de008 Mon Sep 17 00:00:00 2001 From: Pavlin Angelov Date: Mon, 22 Apr 2019 09:11:21 +0300 Subject: [PATCH 2/8] Fix style problems --- exercises/high-scores/example.py | 2 ++ exercises/high-scores/high_scores.py | 8 +++++--- exercises/high-scores/high_scores_test.py | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/exercises/high-scores/example.py b/exercises/high-scores/example.py index 6caece7bdd..fd168ffc52 100644 --- a/exercises/high-scores/example.py +++ b/exercises/high-scores/example.py @@ -1,8 +1,10 @@ def latest(scores): return scores[-1] + def personal_best(scores): return max(scores) + def personal_top_three(scores): return sorted(scores, reverse=True)[:3] diff --git a/exercises/high-scores/high_scores.py b/exercises/high-scores/high_scores.py index 84f5172b77..b5869b9c30 100644 --- a/exercises/high-scores/high_scores.py +++ b/exercises/high-scores/high_scores.py @@ -1,8 +1,10 @@ def latest(scores): - pass # Put your code here + pass # Put your code here + def personal_best(scores): - pass # Put your code here + pass # Put your code here + def personal_top_three(scores): - pass # Put your code here + pass # Put your code here diff --git a/exercises/high-scores/high_scores_test.py b/exercises/high-scores/high_scores_test.py index b0e7c57850..40bd76c5ed 100644 --- a/exercises/high-scores/high_scores_test.py +++ b/exercises/high-scores/high_scores_test.py @@ -7,7 +7,7 @@ class HighScoreTest(unittest.TestCase): - + def test_latest_score(self): scores = [100, 0, 90, 30] expected = 30 From 47d3eafa77226ea82ba307e7f9be83e00b96372e Mon Sep 17 00:00:00 2001 From: Pavlin Angelov Date: Tue, 23 Apr 2019 09:16:27 +0300 Subject: [PATCH 3/8] Made requested changes in PR Remove __init__.py Remove content of HINTS.md Generate the README.md Remove the comments in stub file --- exercises/high-scores/.meta/HINTS.md | 5 ----- exercises/high-scores/README.md | 3 ++- exercises/high-scores/__init__.py | 0 exercises/high-scores/high_scores.py | 6 +++--- 4 files changed, 5 insertions(+), 9 deletions(-) delete mode 100644 exercises/high-scores/__init__.py diff --git a/exercises/high-scores/.meta/HINTS.md b/exercises/high-scores/.meta/HINTS.md index d1d5af1196..e69de29bb2 100644 --- a/exercises/high-scores/.meta/HINTS.md +++ b/exercises/high-scores/.meta/HINTS.md @@ -1,5 +0,0 @@ -In this exercise you're going to create a **class** and use lists to organize scores. _Don't worry, it's not as complicated as you think!_ - -- [**A First Look at Classes**](https://docs.python.org/3/tutorial/classes.html#a-first-look-at-classes) from the Python 3 documentation. -- [**How to Define a Class in Python**](https://realpython.com/python3-object-oriented-programming/#how-to-define-a-class-in-python) from the Real Python website. -- [**Data Structures in Python**](https://docs.python.org/3/tutorial/datastructures.html) from the Python 3 documentation. diff --git a/exercises/high-scores/README.md b/exercises/high-scores/README.md index bdfc8d28fc..6e1e57cff7 100644 --- a/exercises/high-scores/README.md +++ b/exercises/high-scores/README.md @@ -2,7 +2,8 @@ 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 three functions that from the original score list will return the highest score, the last added score and the three highest scores respectivly. +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. + ## Exception messages diff --git a/exercises/high-scores/__init__.py b/exercises/high-scores/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/exercises/high-scores/high_scores.py b/exercises/high-scores/high_scores.py index b5869b9c30..0d24cdb1c1 100644 --- a/exercises/high-scores/high_scores.py +++ b/exercises/high-scores/high_scores.py @@ -1,10 +1,10 @@ def latest(scores): - pass # Put your code here + pass def personal_best(scores): - pass # Put your code here + pass def personal_top_three(scores): - pass # Put your code here + pass From 7f9b8c6e163706222e49078d8f21f3edb2e24486 Mon Sep 17 00:00:00 2001 From: Pavlin Angelov Date: Wed, 24 Apr 2019 09:18:07 +0300 Subject: [PATCH 4/8] 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 --- exercises/high-scores/.meta/HINTS.md | 5 +++++ exercises/high-scores/README.md | 6 ++++++ exercises/matrix/.meta/HINTS.md | 5 +++++ exercises/matrix/README.md | 7 +++++++ 4 files changed, 23 insertions(+) create mode 100644 exercises/matrix/.meta/HINTS.md diff --git a/exercises/high-scores/.meta/HINTS.md b/exercises/high-scores/.meta/HINTS.md index e69de29bb2..cdc643fcb5 100644 --- a/exercises/high-scores/.meta/HINTS.md +++ b/exercises/high-scores/.meta/HINTS.md @@ -0,0 +1,5 @@ +In this exercise, you're going to use and manipulate lists. Python lists are very versatile, and you'll find yourself using them again and agin in problems both simple and complex. + +- [**Data Structures (Python 3 Documentation Tutorial)**](https://docs.python.org/3/tutorial/datastructures.html) +- [**Lists and Tuples in Python (Real Python)**](https://realpython.com/python-lists-tuples/) +- [**Python Lists (Google for Education)**](https://developers.google.com/edu/python/lists) \ No newline at end of file diff --git a/exercises/high-scores/README.md b/exercises/high-scores/README.md index 6e1e57cff7..14a5c78250 100644 --- a/exercises/high-scores/README.md +++ b/exercises/high-scores/README.md @@ -4,6 +4,12 @@ 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 and the three highest scores. +In this exercise, you're going to use and manipulate lists. Python lists are very versatile, and you'll find yourself using them again and agin in problems both simple and complex. + +- [**Data Structures (Python 3 Documentation Tutorial)**](https://docs.python.org/3/tutorial/datastructures.html) +- [**Lists and Tuples in Python (Real Python)**](https://realpython.com/python-lists-tuples/) +- [**Python Lists (Google for Education)**](https://developers.google.com/edu/python/lists) + ## Exception messages diff --git a/exercises/matrix/.meta/HINTS.md b/exercises/matrix/.meta/HINTS.md new file mode 100644 index 0000000000..50ceeae164 --- /dev/null +++ b/exercises/matrix/.meta/HINTS.md @@ -0,0 +1,5 @@ +In this exercise you're going to create a **class**. _Don't worry, it's not as complicated as you think!_ + +- [**A First Look at Classes**](https://docs.python.org/3/tutorial/classes.html#a-first-look-at-classes) from the Python 3 documentation. +- [**How to Define a Class in Python**](https://realpython.com/python3-object-oriented-programming/#how-to-define-a-class-in-python) from the Real Python website. +- [**Data Structures in Python**](https://docs.python.org/3/tutorial/datastructures.html) from the Python 3 documentation. \ No newline at end of file diff --git a/exercises/matrix/README.md b/exercises/matrix/README.md index 2165e6fe80..1564c11bf6 100644 --- a/exercises/matrix/README.md +++ b/exercises/matrix/README.md @@ -40,6 +40,13 @@ And its columns: - 8, 3, 6 - 7, 2, 7 +In this exercise you're going to create a **class**. _Don't worry, it's not as complicated as you think!_ + +- [**A First Look at Classes**](https://docs.python.org/3/tutorial/classes.html#a-first-look-at-classes) from the Python 3 documentation. +- [**How to Define a Class in Python**](https://realpython.com/python3-object-oriented-programming/#how-to-define-a-class-in-python) from the Real Python website. +- [**Data Structures in Python**](https://docs.python.org/3/tutorial/datastructures.html) from the Python 3 documentation. + + ## Exception messages Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to From c2bc97dc71dae96f1feadbce8436d977f28b4cbf Mon Sep 17 00:00:00 2001 From: Pavlin Angelov Date: Thu, 25 Apr 2019 08:44:42 +0300 Subject: [PATCH 5/8] Remove changes to matrix from this PR --- exercises/matrix/.meta/HINTS.md | 5 ----- exercises/matrix/README.md | 6 ------ 2 files changed, 11 deletions(-) delete mode 100644 exercises/matrix/.meta/HINTS.md diff --git a/exercises/matrix/.meta/HINTS.md b/exercises/matrix/.meta/HINTS.md deleted file mode 100644 index 50ceeae164..0000000000 --- a/exercises/matrix/.meta/HINTS.md +++ /dev/null @@ -1,5 +0,0 @@ -In this exercise you're going to create a **class**. _Don't worry, it's not as complicated as you think!_ - -- [**A First Look at Classes**](https://docs.python.org/3/tutorial/classes.html#a-first-look-at-classes) from the Python 3 documentation. -- [**How to Define a Class in Python**](https://realpython.com/python3-object-oriented-programming/#how-to-define-a-class-in-python) from the Real Python website. -- [**Data Structures in Python**](https://docs.python.org/3/tutorial/datastructures.html) from the Python 3 documentation. \ No newline at end of file diff --git a/exercises/matrix/README.md b/exercises/matrix/README.md index 1564c11bf6..9721ad6c79 100644 --- a/exercises/matrix/README.md +++ b/exercises/matrix/README.md @@ -40,12 +40,6 @@ And its columns: - 8, 3, 6 - 7, 2, 7 -In this exercise you're going to create a **class**. _Don't worry, it's not as complicated as you think!_ - -- [**A First Look at Classes**](https://docs.python.org/3/tutorial/classes.html#a-first-look-at-classes) from the Python 3 documentation. -- [**How to Define a Class in Python**](https://realpython.com/python3-object-oriented-programming/#how-to-define-a-class-in-python) from the Real Python website. -- [**Data Structures in Python**](https://docs.python.org/3/tutorial/datastructures.html) from the Python 3 documentation. - ## Exception messages From 4317e1c3e77c15ff47c321db39a3a53f6bf9b759 Mon Sep 17 00:00:00 2001 From: Corey McCandless Date: Thu, 2 May 2019 12:22:15 +0300 Subject: [PATCH 6/8] Update exercises/high-scores/.meta/HINTS.md Co-Authored-By: simmol --- exercises/high-scores/.meta/HINTS.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exercises/high-scores/.meta/HINTS.md b/exercises/high-scores/.meta/HINTS.md index cdc643fcb5..b1de85b183 100644 --- a/exercises/high-scores/.meta/HINTS.md +++ b/exercises/high-scores/.meta/HINTS.md @@ -1,5 +1,5 @@ -In this exercise, you're going to use and manipulate lists. Python lists are very versatile, and you'll find yourself using them again and agin in problems both simple and complex. +In this exercise, you're going to use and manipulate lists. Python lists are very versatile, and you'll find yourself using them again and again in problems both simple and complex. - [**Data Structures (Python 3 Documentation Tutorial)**](https://docs.python.org/3/tutorial/datastructures.html) - [**Lists and Tuples in Python (Real Python)**](https://realpython.com/python-lists-tuples/) -- [**Python Lists (Google for Education)**](https://developers.google.com/edu/python/lists) \ No newline at end of file +- [**Python Lists (Google for Education)**](https://developers.google.com/edu/python/lists) From 4d41a8e360f3e8931b5c0bac6d6090dc8586ab2c Mon Sep 17 00:00:00 2001 From: Corey McCandless Date: Thu, 2 May 2019 12:23:26 +0300 Subject: [PATCH 7/8] Update exercises/matrix/README.md Co-Authored-By: simmol --- exercises/matrix/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/exercises/matrix/README.md b/exercises/matrix/README.md index 9721ad6c79..2165e6fe80 100644 --- a/exercises/matrix/README.md +++ b/exercises/matrix/README.md @@ -40,7 +40,6 @@ And its columns: - 8, 3, 6 - 7, 2, 7 - ## Exception messages Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to From 91dabe3fd1e60ad6784945fd980a83f12a5939a7 Mon Sep 17 00:00:00 2001 From: Pavlin Angelov Date: Fri, 3 May 2019 10:06:48 +0300 Subject: [PATCH 8/8] Regenerate README --- exercises/high-scores/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/exercises/high-scores/README.md b/exercises/high-scores/README.md index 14a5c78250..fa7934d4d3 100644 --- a/exercises/high-scores/README.md +++ b/exercises/high-scores/README.md @@ -4,13 +4,14 @@ 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 and the three highest scores. -In this exercise, you're going to use and manipulate lists. Python lists are very versatile, and you'll find yourself using them again and agin in problems both simple and complex. +In this exercise, you're going to use and manipulate lists. Python lists are very versatile, and you'll find yourself using them again and again in problems both simple and complex. - [**Data Structures (Python 3 Documentation Tutorial)**](https://docs.python.org/3/tutorial/datastructures.html) - [**Lists and Tuples in Python (Real Python)**](https://realpython.com/python-lists-tuples/) - [**Python Lists (Google for Education)**](https://developers.google.com/edu/python/lists) + ## Exception messages Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to