-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
multiply function + pytest coverage + enrich readme (#4)
<img width="763" alt="image" src="https://github.com/MridulaMaddukuri/boilerplate-poetry-project/assets/18033881/252da371-0837-4f9a-8a52-80d103b78be8">
- Loading branch information
Showing
5 changed files
with
104 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
def multiply_int(x: int, y: int) -> int: | ||
"""Multiply two integers. | ||
Parameters: | ||
- x (int): The first integer to multiply. | ||
- y (int): The second integer to multiply. | ||
Returns: | ||
- int: The product of x and y. | ||
Raises: | ||
- TypeError: If either x or y is not an integer. | ||
Example: | ||
>>> multiply_int(2, 3) | ||
6 | ||
""" | ||
if not isinstance(x, int) or not isinstance(y, int): | ||
raise TypeError("Both x and y must be integers.") | ||
return x * y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import hypothesis.strategies as st | ||
import pytest | ||
from hypothesis import given | ||
|
||
from boilerplate_poetry_project.multiply import multiply_int | ||
|
||
|
||
def test_multiply_int_success(): | ||
"""Test that multiplying two integers returns the correct product. | ||
# basic functionality""" | ||
assert multiply_int(2, 3) == 6 | ||
assert multiply_int(-1, -1) == 1 | ||
assert multiply_int(0, 0) == 0 | ||
|
||
|
||
@pytest.mark.parametrize("x, y", [("a", 2), (2, "b"), ("a", "b"), (1.5, 2), (2, 1.5)]) | ||
def test_multiply_int_raises_type_error_on_invalid_input(x, y): | ||
"""Test that a TypeError is raised when non-integers are provided.""" | ||
with pytest.raises(TypeError): | ||
multiply_int(x, y) | ||
|
||
|
||
@given(x=st.integers(), y=st.integers()) | ||
def test_multiply_int_with_hypothesis(x, y): | ||
"""Test that multiplying two integers returns the correct product using Hypothesis.""" | ||
assert multiply_int(x, y) == x * y |