From ade5ec9a712a9fb5b9c934bc4c4b3c9f75e30e21 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 4 Jul 2024 23:12:03 +0200 Subject: [PATCH] Refactor code for speed and clarity --- template/module1.py | 17 +++++++++++++++-- tests/test_module1.py | 15 ++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/template/module1.py b/template/module1.py index 2114ded..fc3c13f 100644 --- a/template/module1.py +++ b/template/module1.py @@ -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 diff --git a/tests/test_module1.py b/tests/test_module1.py index 9e66641..14aa825 100644 --- a/tests/test_module1.py +++ b/tests/test_module1.py @@ -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