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

'Testing Assertions' exercise solution is incorrect #1040

Open
tobyhodges opened this issue May 31, 2023 · 1 comment
Open

'Testing Assertions' exercise solution is incorrect #1040

tobyhodges opened this issue May 31, 2023 · 1 comment

Comments

@tobyhodges
Copy link
Member

(Reported by a community member over email.)

The Testing Assertions exercise in the Defentsive Programming episode includes one assert statement that does not work as described:

assert int(value) will not raise an AssertionError but instead a ValueError when value cannot be converted to an integer.

The exercise should be updated to account for this. I suggest two possible approaches:

  1. update the solution to mention that a ValueError will be raised, and ideally explaining why the assert statement is never evaluated.
  2. update the exercise example to remove that line.

I know that the idea of replacing assertions with try...except has been the topic of multiple discussions, and @DamienIrving was working on a PR to switch the approach taken in the episode (unfortunately disrupted by the lesson infrastructure transition). I mention this because the appearance of a ValueError rather than an AssertionError from the code in this exercise seems to be a case where try...except could be less confusing for the Learner.

@edbennett
Copy link
Contributor

Worth noting that this also asserts that if the element is numeric, that it is not in the range $(-1.0, 1.0)$. This is also not currently documented, and it's not clear why such a constraint would be being imposed.

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

2 participants