From ce14543bc4ab1de29383496b5d71a6b3f50e4519 Mon Sep 17 00:00:00 2001 From: Isaac Good Date: Tue, 28 Jul 2026 09:51:46 -0700 Subject: [PATCH 1/4] [Ellen's Alien Game] Test that an instance variable is used for the health, not a class variable. --- .../concept/ellens-alien-game/classes_test.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/exercises/concept/ellens-alien-game/classes_test.py b/exercises/concept/ellens-alien-game/classes_test.py index 3d2b986be4d..1c5ea27cc9f 100644 --- a/exercises/concept/ellens-alien-game/classes_test.py +++ b/exercises/concept/ellens-alien-game/classes_test.py @@ -7,7 +7,7 @@ except ImportError as import_fail: # pylint: disable=raise-missing-from raise ImportError("\n\nMISSING CLASS --> We tried to import the 'Alien' class from " - "your classes.py file, but could not find it." + "your classes.py file, but could not find it." "Did you misname or forget to create it?") from None try: @@ -144,7 +144,6 @@ def test_alien_class_variable(self): """Test class attribute/variables are identical across instances.""" alien_one, alien_two = Alien(0, 2), Alien(-6, -1) - Alien.health = 6 created_error_message = ('Created two new Aliens and requested the ' 'total_aliens_created attribute for each one. ' @@ -165,6 +164,22 @@ def test_alien_class_variable(self): alien_one.health, msg=health_error_message) + @pytest.mark.task(taskno=6) + def test_alien_health_is_instance_variable(self): + """Test the health is an instance variable and not a class variable.""" + + alien_one, alien_two = Alien(0, 2), Alien(-6, -1) + alien_one.hit() + + error_message = ('Created two new Aliens and called hit() on one of them. ' + f'Received {alien_one.health, alien_two.health} for health, ' + 'but the tests expect them to have different health as ' + 'only one was hit. Are you using a class variable for the health?') + + self.assertNotEqual(alien_two.health, + alien_one.health, + msg=error_message) + @pytest.mark.task(taskno=6) def test_alien_total_aliens_created(self): """Test total_aliens_created class variable increments upon object instantiation.""" From b7f8513e07dff9dfc8c9b3d98ae707bc844a8890 Mon Sep 17 00:00:00 2001 From: Isaac Good Date: Sun, 9 Aug 2026 20:56:18 -0700 Subject: [PATCH 2/4] Update docstrings and strings (quotes, trailing spaces) --- .../concept/ellens-alien-game/classes_test.py | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/exercises/concept/ellens-alien-game/classes_test.py b/exercises/concept/ellens-alien-game/classes_test.py index 1c5ea27cc9f..05500c22dd5 100644 --- a/exercises/concept/ellens-alien-game/classes_test.py +++ b/exercises/concept/ellens-alien-game/classes_test.py @@ -7,16 +7,16 @@ except ImportError as import_fail: # pylint: disable=raise-missing-from raise ImportError("\n\nMISSING CLASS --> We tried to import the 'Alien' class from " - "your classes.py file, but could not find it." - "Did you misname or forget to create it?") from None + 'your classes.py file, but could not find it. ' + 'Did you misname or forget to create it?') from None try: from classes import new_aliens_collection except ImportError as err: - raise ImportError("\n\nMISSING FUNCTION --> We tried to import the " - "new_aliens_collection() function " - "from your classes.py file, but could not find it. " - "Did you misname or forget to create it?") from None + raise ImportError('\n\nMISSING FUNCTION --> We tried to import the ' + 'new_aliens_collection() function ' + 'from your classes.py file, but could not find it. ' + 'Did you misname or forget to create it?') from None class ClassesTest(unittest.TestCase): @@ -38,7 +38,7 @@ def test_alien_has_health(self): alien = Alien(0, 0) error_message = (f'Created a new Alien by calling Alien(0, 0). ' f'The new Alien has a health of {alien.health}, ' - f'but the tests expect health = 3') + f'but the tests expect health = 3.') self.assertEqual(3, alien.health, msg=error_message) @@ -72,7 +72,6 @@ def test_alien_hit_method(self): There are two valid interpretations for this method/task. `self.health -= 1` and `self.health = max(0, self.health - 1)` The tests for this task reflect this ambiguity. - """ test_data = [1, 2, 3, 4, 5, 6] @@ -99,6 +98,7 @@ def test_alien_hit_method(self): @pytest.mark.task(taskno=3) def test_alien_is_alive_method(self): + """Test the is_alive() method returns the expected values after a number of hits.""" alien = Alien(0, 1) alive_error = ('Created a new Alien and called hit(). ' @@ -106,8 +106,8 @@ def test_alien_is_alive_method(self): 'while alien.health is greater than 0.') dead_error = ('Created a new Alien and called hit(). ' - 'The function is_alive() is returning True (alive) ' - 'while alien.health is less than or equal to 0.') + 'The function is_alive() is returning True (alive) ' + 'while alien.health is less than or equal to 0.') for _ in range(5): alien.hit() @@ -118,6 +118,7 @@ def test_alien_is_alive_method(self): @pytest.mark.task(taskno=4) def test_alien_teleport_method(self): + """Test the teleport method updates the alien's coordinates.""" alien = Alien(0, 0) alien.teleport(-1, -4) @@ -130,11 +131,12 @@ def test_alien_teleport_method(self): @pytest.mark.task(taskno=5) def test_alien_collision_detection_method(self): + """Test the collision_detection() method can be called and returns None.""" alien = Alien(7, 3) error_message = ('Created a new Alien at (7,3) and called ' 'alien.collision_detection(Alien(7, 2)). ' f'The method returned {alien.collision_detection(Alien(7, 2))}, ' - 'but the tests expected None. ') + 'but the tests expected None.') self.assertIsNone(alien.collision_detection(Alien(7, 2)), msg=error_message) @@ -149,12 +151,12 @@ def test_alien_class_variable(self): 'total_aliens_created attribute for each one. ' f'Received {alien_one.total_aliens_created, alien_two.total_aliens_created} ' f'for total_aliens_created, but the tests expect ' - f'the class attributes for each newly created Alien to be identical. ') + f'the class attributes for each newly created Alien to be identical.') health_error_message = ('Created two new Aliens and requested the ' f'health attribute for each one. Received {alien_one.health, alien_two.health} ' 'for health, but the tests expect the class ' - 'attributes for each newly created Alien to be identical. ') + 'attributes for each newly created Alien to be identical.') self.assertEqual(alien_two.total_aliens_created, alien_one.total_aliens_created, @@ -176,9 +178,12 @@ def test_alien_health_is_instance_variable(self): 'but the tests expect them to have different health as ' 'only one was hit. Are you using a class variable for the health?') + # This checks that a class attribute, Alien.health, is not being used. + # If a class attribute is being used, hit() would update the health across + # all instances of the class. self.assertNotEqual(alien_two.health, - alien_one.health, - msg=error_message) + alien_one.health, + msg=error_message) @pytest.mark.task(taskno=6) def test_alien_total_aliens_created(self): @@ -197,9 +202,9 @@ def test_alien_total_aliens_created(self): aliens.append(Alien(-5, -5)) def error_text(alien, variable): - return ('Created two additional Aliens for the session.' + return ('Created two additional Aliens for the session. ' f"Alien number {alien}'s total_aliens_created variable " - f"is equal to {variable}, but the tests expected all " + f'is equal to {variable}, but the tests expected all ' 'total_aliens_created variables for all instances to be ' 'equal to number of alien instances created (i.e. 3).') @@ -214,7 +219,7 @@ def test_new_aliens_collection(self): test_data = [(-2, 6), (1, 5), (-4, -3)] actual_result = new_aliens_collection(test_data) - error_message = "new_aliens_collection() must return a list of Alien objects." + error_message = 'new_aliens_collection() must return a list of Alien objects.' for obj in actual_result: self.assertIsInstance(obj, Alien, msg=error_message) From 7f9c76de9691b0917ca1c12b8f2593b9b28e4d89 Mon Sep 17 00:00:00 2001 From: Isaac Good Date: Sun, 9 Aug 2026 21:00:14 -0700 Subject: [PATCH 3/4] Drop unneeded test --- exercises/concept/ellens-alien-game/classes_test.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/exercises/concept/ellens-alien-game/classes_test.py b/exercises/concept/ellens-alien-game/classes_test.py index 05500c22dd5..eac33fdf277 100644 --- a/exercises/concept/ellens-alien-game/classes_test.py +++ b/exercises/concept/ellens-alien-game/classes_test.py @@ -153,19 +153,10 @@ def test_alien_class_variable(self): f'for total_aliens_created, but the tests expect ' f'the class attributes for each newly created Alien to be identical.') - health_error_message = ('Created two new Aliens and requested the ' - f'health attribute for each one. Received {alien_one.health, alien_two.health} ' - 'for health, but the tests expect the class ' - 'attributes for each newly created Alien to be identical.') - self.assertEqual(alien_two.total_aliens_created, alien_one.total_aliens_created, msg=created_error_message) - self.assertEqual(alien_two.health, - alien_one.health, - msg=health_error_message) - @pytest.mark.task(taskno=6) def test_alien_health_is_instance_variable(self): """Test the health is an instance variable and not a class variable.""" From 9cb5873dfb6959df40c90cc7e9aef3e6f5dc278c Mon Sep 17 00:00:00 2001 From: Isaac Good Date: Sun, 9 Aug 2026 21:10:27 -0700 Subject: [PATCH 4/4] Replace tab with spaces --- exercises/concept/ellens-alien-game/classes_test.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/exercises/concept/ellens-alien-game/classes_test.py b/exercises/concept/ellens-alien-game/classes_test.py index 63effcd851b..b7afb7cc3e2 100644 --- a/exercises/concept/ellens-alien-game/classes_test.py +++ b/exercises/concept/ellens-alien-game/classes_test.py @@ -98,7 +98,7 @@ def test_alien_hit_method(self): @pytest.mark.task(taskno=3) def test_alien_is_alive_method(self): - """Test the is_alive() method returns the expected values after a number of hits.""" + """Test the is_alive() method returns the expected values after a number of hits.""" alien = Alien(0, 1) alive_error = ('Created a new Alien and called hit(). ' @@ -118,7 +118,7 @@ def test_alien_is_alive_method(self): @pytest.mark.task(taskno=4) def test_alien_teleport_method(self): - """Test the teleport method updates the alien's coordinates.""" + """Test the teleport method updates the alien's coordinates.""" alien = Alien(0, 0) alien.teleport(-1, -4) @@ -131,7 +131,7 @@ def test_alien_teleport_method(self): @pytest.mark.task(taskno=5) def test_alien_collision_detection_method(self): - """Test the collision_detection() method can be called and returns None.""" + """Test the collision_detection() method can be called and returns None.""" alien = Alien(7, 3) error_message = ('Created a new Alien at (7,3) and called ' 'alien.collision_detection(Alien(7, 2)). '