Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion checks/functional/functional1.py
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)}"

Copy link
Copy Markdown
Owner

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 evaluates square(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) and absolute(-100) messages in functional2 have the same problem. Add a focused regression using a side-effecting failing function.

print("functional1 ✓")
4 changes: 2 additions & 2 deletions checks/functional/functional2.py
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 ✓")
2 changes: 1 addition & 1 deletion checks/functional/functional3.py
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 ✓")
6 changes: 3 additions & 3 deletions checks/functional/functional4.py
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 ✓")
6 changes: 3 additions & 3 deletions checks/functional/functional5.py
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 ✓")
7 changes: 5 additions & 2 deletions checks/functional/functional6.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}"

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The 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 apply_twice(...) again, including executing the learner's callback again. The same probe reproduces a RuntimeError masking the original assertion failure. Keep the original predicate and use an expected-value message that does not execute learner code.

)
print("functional6 ✓")