added tests
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
"""Utility functions for the test package."""
|
||||
|
||||
from typing import Union
|
||||
|
||||
|
||||
def format_number(number: Union[int, float], precision: int = 2) -> str:
|
||||
"""Format a number with specified precision."""
|
||||
if isinstance(number, int):
|
||||
return str(number)
|
||||
return f"{number:.{precision}f}"
|
||||
|
||||
|
||||
def is_even(number: int) -> bool:
|
||||
"""Check if a number is even."""
|
||||
return number % 2 == 0
|
||||
|
||||
|
||||
def factorial(n: int) -> int:
|
||||
"""Calculate factorial of a number."""
|
||||
if n < 0:
|
||||
raise ValueError("Factorial is not defined for negative numbers")
|
||||
if n == 0 or n == 1:
|
||||
return 1
|
||||
return n * factorial(n - 1)
|
||||
Reference in New Issue
Block a user