Repository navigation
fix: add messages to functional assertions #151
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| assert square(3) == 9, f"square(3) should be 9, got {square(3)}" | ||
| assert square(5) == 25, f"square(5) should be 25, got {square(5)}" | ||
| assert square(0) == 0 | ||
| assert square(0) == 0, f"square(0) should be 0, got {square(0)}" | ||
| print("functional1 ✓") | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| assert absolute(5) == 5, f"absolute(5) should be 5, got {absolute(5)}" | ||
| assert absolute(-3) == 3, f"absolute(-3) should be 3, got {absolute(-3)}" | ||
| assert absolute(0) == 0 | ||
| assert absolute(-100) == 100 | ||
| assert absolute(0) == 0, f"Expected absolute(0) to be 0, got {absolute(0)}" | ||
| assert absolute(-100) == 100, f"Expected absolute(-100) to be 100, got {absolute(-100)}" | ||
| print("functional2 ✓") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| assert doubled == [2, 4, 6, 8, 10], f"doubled should be [2, 4, 6, 8, 10], got {doubled}" | ||
| assert isinstance(doubled, list) | ||
| assert isinstance(doubled, list), f"Expected doubled to be a list, got {type(doubled).__name__}" | ||
| print("functional3 ✓") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| assert evens == [2, 4, 6, 8, 10], f"evens should be [2, 4, 6, 8, 10], got {evens}" | ||
| assert isinstance(evens, list) | ||
| assert all(x % 2 == 0 for x in evens) | ||
| print("functional4 ✓") | ||
| assert isinstance(evens, list), f"evens should be a list, got {type(evens).__name__}" | ||
| assert all(x % 2 == 0 for x in evens), f"evens should contain only even numbers, got {evens}" | ||
| print("functional4 ✓") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| assert by_length == ["fig", "kiwi", "date", "apple", "banana"], ( | ||
| f"by_length should be ['fig', 'kiwi', 'date', 'apple', 'banana'], got {by_length}" | ||
| ) | ||
| assert by_length[0] == "fig" | ||
| assert by_length[-1] == "banana" | ||
| print("functional5 ✓") | ||
| assert by_length[0] == "fig", f"by_length[0] should be 'fig', got {by_length[0]}" | ||
| assert by_length[-1] == "banana", f"by_length[-1] should be 'banana', got {by_length[-1]}" | ||
| print("functional5 ✓") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,5 +4,8 @@ | |
| assert apply_twice(add_ten, 5) == 25, ( | ||
| f"apply_twice(add_ten, 5) should be 25, got {apply_twice(add_ten, 5)}" | ||
| ) | ||
| assert apply_twice(lambda x: x + 1, 0) == 2 | ||
| print("functional6 ✓") | ||
| assert apply_twice(lambda x: x + 1, 0) == 2, ( | ||
| f"apply_twice(lambda x: x + 1, 0) should be 2, " | ||
| f"got {apply_twice(lambda x: x + 1, 0)}" | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P2] Preserve the single evaluation of apply_twice. This new failure message also calls |
||
| ) | ||
| print("functional6 ✓") | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P2] Do not call the learner's function again in the failure message.
The new
square(0)message evaluatessquare(0)a second time. I reproduced this with a learner function that returns an incorrect result on the first zero call and raises on the second: the check reports the second call's RuntimeError instead of the expected assertion failure. This violates CONTRIBUTING.md's rule against re-calling learner functions to format messages.Use a constant expected-value message here. The new
absolute(0)andabsolute(-100)messages in functional2 have the same problem. Add a focused regression using a side-effecting failing function.