Skip to content
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

high-scores: incorrect solution can pass the tests #1745

Closed
ali1234 opened this issue Apr 13, 2019 · 3 comments
Closed

high-scores: incorrect solution can pass the tests #1745

ali1234 opened this issue Apr 13, 2019 · 3 comments

Comments

@ali1234
Copy link

ali1234 commented Apr 13, 2019

Consider the following partial solution to this problem:

class HighScores(object):
    def __init__(self, scores):
        self.scores = scores

    def latest(self):
        return self.scores[-1]

    def personal_best(self):
        self.scores.sort()
        return self.scores[-1]

This will pass the tests for the functions it implements. However, if latest is called after calling personal_best, it can give the wrong answer. The current tests do not check for this situation.

@cmccandless
Copy link
Contributor

This issue has come up before in #1735.

Currently, side effect testing is outside the scope of this exercise. There is a discussion here to include such tests, but I would like to wait and see the consensus there before adding these tests here.

Another solution discussed in #1744 would be to convert this track's implementation to use stand-alone functions rather than a class instance, which might make things more clear to students anyway.

@simmol
Copy link
Contributor

simmol commented May 2, 2019

PR #1764 will be merged soon that will make the exercise simpler (using separate functions).

@stale
Copy link

stale bot commented May 23, 2019

This issue has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants