Skip to content

Commit

Permalink
Refactor code for speed and clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
glenn-jocher committed Jul 4, 2024
1 parent ced9fe7 commit ade5ec9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
17 changes: 15 additions & 2 deletions template/module1.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,23 @@ def add_numbers(a, b):
Adds two numbers and returns the sum.
Args:
a (float | int): The first number to add.
b (float | int): The second number to add.
a (float | int): The first number in the addition.
b (float | int): The second number in the addition.
Returns:
(float | int): The sum of `a` and `b`.
Notes:
This function supports both integer and floating-point numbers. The returned value will match the type of the input
values unless they're mixed, in which case a float is returned.
Examples:
```python
result = add_numbers(3, 5)
assert result == 8
result = add_numbers(3.5, 2)
assert result == 5.5
```
"""
return a + b
15 changes: 14 additions & 1 deletion tests/test_module1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,20 @@


def test_add_numbers():
"""Test the add_numbers function from module1."""
"""
Test the add_numbers function from module1 by verifying the correctness of summation operation between pairs of
integers.
Tests:
- Ensures that the sum of 2 and 3 equals 5.
- Validates that the sum of -1 and 1 equals 0.
Returns:
None: This function performs assertions to validate the behavior of add_numbers. It does not return a value.
Raises:
AssertionError: If any of the assertions fail, this error is raised indicating a test case failure.
"""
assert add_numbers(2, 3) == 5
assert add_numbers(-1, 1) == 0
assert add_numbers(-1, -1) == -2

0 comments on commit ade5ec9

Please sign in to comment.