Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# TODO: make all functions work with strings as well
# TODO: add a new cool calculator function


def sum(a: int, b: int) -> int:
'''
This function returns the sum of two numbers
Expand All @@ -17,6 +18,7 @@ def sum(a: int, b: int) -> int:
'''
return a + b


def multiply(a, b) -> float:
'''
This function returns the product of two numbers
Expand All @@ -30,6 +32,7 @@ def multiply(a, b) -> float:
'''
return a * b


def divide(a: float, b: float) -> float:
'''
...
Expand All @@ -43,6 +46,7 @@ def divide(a: float, b: float) -> float:
'''
return a / b


def modulo(a: int, b: int):
'''
...
Expand All @@ -60,6 +64,7 @@ def modulo(a: int, b: int):

return result


def element_wise_multiply(a: np.array, b: np.array) -> np.array:
'''
...
Expand All @@ -76,6 +81,7 @@ def element_wise_multiply(a: np.array, b: np.array) -> np.array:

return np.multiply(a, b)


def return_hexadecimal(a: int) -> float:
'''
...
Expand All @@ -91,16 +97,16 @@ def return_hexadecimal(a: int) -> float:
return hex(a)


def return_random_number() -> int:
def return_random_number(seed: Optional[int] = None) -> int:
'''
...
This function returns a random number between 0 and 100

Args:
a: float
b: float
seed: int the seed for the random number generator

Returns:
float
int a random number between 0 and 100
'''
np.random.seed(seed)

return np.random.randint(0, 100)
return np.random.randint(0, 200)
46 changes: 45 additions & 1 deletion tests/test_multiply.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,50 @@
from src.utils import multiply
from utils import multiply, divide
import pytest


def test_multiply():
a = 2
b = 3

assert multiply(a, b) == 6


def test_divide_positive_numbers():
assert divide(10.0, 2.0) == 5.0


def test_divide_negative_numbers():
assert divide(-10.0, -2.0) == 5.0


def test_divide_positive_and_negative():
assert divide(10.0, -2.0) == -5.0


def test_divide_by_one():
assert divide(10.0, 1.0) == 10.0


def test_divide_by_fraction():
assert divide(10.0, 0.5) == 20.0


def test_divide_zero():
assert divide(0.0, 10.0) == 0.0
print("Test passed")


def test_divide_by_zero():
with pytest.raises(ZeroDivisionError):
divide(10.0, 0.0)


if __name__ == '__main__':
test_multiply()
test_divide_positive_numbers()
test_divide_negative_numbers()
test_divide_positive_and_negative()
test_divide_by_one()
test_divide_by_fraction()
test_divide_zero()
test_divide_by_zero()