Skip to content
Open
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
4 changes: 3 additions & 1 deletion src/arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
Python 3.6+ is required to run this module, since it uses type hints.
"""

from math import pow


def add(a: int | float, b: int | float) -> int | float:
"""Add two numbers."""
Expand All @@ -27,7 +29,7 @@ def divide(a: int | float, b: int | float) -> float:

def power(a: int | float, b: int | float) -> int | float:
"""Raise a to the power of b."""
raise NotImplementedError("power is not implemented yet")
return pow(a, b)


def factorial(n: int) -> int:
Expand Down
8 changes: 4 additions & 4 deletions src/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from math import pi

from .arithmetic import multiply
from .arithmetic import multiply, power


def rectangle_area(width: int | float, height: int | float) -> float:
Expand All @@ -30,6 +30,6 @@ def circle_circumference(radius: int | float) -> float:

def circle_area(radius: int | float) -> float:
"""Calculate the area of a circle."""
raise NotImplementedError(
"circle_area is not implemented yet. Should be implmented only after src.arithmetic.power is implemented."
)
if radius < 0:
raise ValueError("Radius must be non-negative.")
return multiply(pi, power(radius, 2))
9 changes: 8 additions & 1 deletion tests/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pytest

from src.arithmetic import add, divide, multiply, subtract
from src.arithmetic import add, divide, multiply, power, subtract


def test_add():
Expand Down Expand Up @@ -41,5 +41,12 @@ def test_divide_by_zero():
divide(1, 0)


def test_power():
"""Test the power function."""
assert power(2, 3) == 8
assert power(0, 0) == 1
assert power(-1, 1) == -1


if __name__ == "__main__":
pytest.main()
15 changes: 14 additions & 1 deletion tests/test_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
import numpy as np
import pytest

from src.geometry import circle_circumference, rectangle_area, triangle_area
from src.geometry import (
circle_area,
circle_circumference,
rectangle_area,
triangle_area,
)


def test_rectangle_area():
Expand All @@ -34,5 +39,13 @@ def test_circle_circumference():
circle_circumference(-1)


def test_circle_area():
"""Test the circle_area function."""
assert np.isclose(circle_area(1), pi)
assert np.isclose(circle_area(0), 0)
with pytest.raises(ValueError):
circle_area(-1)


if __name__ == "__main__":
pytest.main()