Test a Square Function
Write and test a function square(n) that returns n ** 2, checking both a positive and a negative input — following pytest's plain-assert style.
Why not run real pytest? an automated judge grades exact program output, and pytest's own test-runner output includes non-deterministic timing (e.g. "3 passed in 0.02s") — so instead, write the assertions directly in the script and print a fixed summary once they all hold, which is exactly what a passing pytest run means in spirit.
Approach: define square(n), then use plain assert statements (pytest style) to check it against both given inputs, printing a summary once both checks pass.
Input: Two lines: a positive test input a, and a negative test input b.
Output: One line: 2/2 tests passed.
5 -3
2/2 tests passed
- -1000 <= a, b <= 1000
Hint 1
square(n) just needs to return n ** 2.
Hint 2
assert expression raises an AssertionError if the expression is False — exactly pytest's own checking mechanism, just without the framework.
Hint 3
If both assert lines don't raise, execution reaches the print() line, meaning both tests passed.
square(n) returns n 2. The two assert statements are pytest-style checks — assert square(a) == a 2 — that silently do nothing if true and raise AssertionError if false. Reaching the final print() line is proof both checks passed, mirroring what a green pytest run means.