Task: Implement a Python module with a factorial function that satisfies the provided tests
Location:
Implement the module at /app/factorial_example.py (or as a package /app/factorial_example/ with an init.py). The tests use: from factorial_example import factorial_function.
Required functionality and behavior:
Expose a function with the signature:
def factorial_function(n: int) -> int
Input validation and error handling:
If n is not an integer, raise an AssertionError (e.g., use asserts to enforce type).
If n < 0, raise an AssertionError (the tests expect this for negative input).
Computation:
For non-negative integers, compute the factorial iteratively (do not rely on math.factorial for negative inputs to ensure the AssertionError behavior).
Return 1 when n == 0.
Return the product 1 * 2 * ... * n for n > 0.
Correctness guarantees:
factorial_function(0) must be 1.
factorial_function(4) must be 24.
For i in range(5) (i.e., 0 through 4), factorial_function(i) must equal math.factorial(i).
Implementation notes:
The function should be self-contained, no external dependencies beyond the Python standard library, and use clear type hints.
Include a brief module/docstring describing the behavior.
Result:
The implemented /app/factorial_example.py (or /app/factorial_example/init.py) should be importable as factorial_example and provide factorial_function that passes all the provided tests: