The Python track ellens-alien-game tests incorrectly pass when we return an empty array from the factory

Hey folks! It looks to me like we’re missing an assertion for the test on the ellens-alien-game exercise in the Python track.

The test checks that the factory method returns an Alien object for each item in the input. However, you can pass the test by returning an empty list.

If we add a length assertion then the empty list will be rejected.

Hi @alexanderbird :wave:

Welcome to the Exercism forums! Thanks for posting this.

I’ll take a look in the next day or two, and see what fix (if any) we’d like to implement.

Meanwhile, could you provide the code that (incorrectly) passes the tests? Many thanks!

1 Like

Awesome!

I put the code in the description of the linked (closed) PR, and I’ll paste it again here. (I prepared a PR before reading the docs indicating they would be auto-closed, so I published it anyway, since I already had it ready to go.)

"""Solution to Ellen's Alien Game exercise."""


class Alien:
    """Create an Alien object with location x_coordinate and y_coordinate.

    Attributes
    ----------
    (class)total_aliens_created: int
    x_coordinate: int - Position on the x-axis.
    y_coordinate: int - Position on the y-axis.
    health: int - Number of health points.

    Methods
    -------
    hit(): Decrement Alien health by one point.
    is_alive(): Return a boolean for if Alien is alive (if health is > 0).
    teleport(new_x_coordinate, new_y_coordinate): Move Alien object to new coordinates.
    collision_detection(other): Implementation TBD.
    """

    total_aliens_created = 0

    def __init__(self, x_coordinate, y_coordinate):
        Alien.total_aliens_created += 1
        self.x_coordinate = x_coordinate
        self.y_coordinate = y_coordinate
        self.health = 3

    def collision_detection(self, x):
        pass

    def hit(self):
        self.health -= 1

    def teleport(self, x, y):
        self.x_coordinate = x
        self.y_coordinate = y

    def is_alive(self):
        return self.health > 0

#TODO:  create the new_aliens_collection() function below to call your Alien class with a list of coordinates.

def new_aliens_collection(x):
    return []

Also, I got the tests to pass without implementing collision_detection – maybe there is another missing test for that one also?

(edit: never mind about the collision detection :sweat_smile:)

Thanks for taking a look! :pray:t2:

You might want to re-read the instructions for that one ;)

Aha, thanks @IsaacG!