added tests
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
"""Tests for the calculator module."""
|
||||
|
||||
import pytest
|
||||
from test_package.calculator import Calculator
|
||||
|
||||
|
||||
class TestCalculator:
|
||||
"""Test cases for Calculator class."""
|
||||
|
||||
def setup_method(self):
|
||||
"""Set up test fixtures."""
|
||||
self.calc = Calculator()
|
||||
|
||||
def test_add(self):
|
||||
"""Test addition operation."""
|
||||
assert self.calc.add(2, 3) == 5
|
||||
assert self.calc.add(-1, 1) == 0
|
||||
assert self.calc.add(0.1, 0.2) == pytest.approx(0.3)
|
||||
|
||||
def test_subtract(self):
|
||||
"""Test subtraction operation."""
|
||||
assert self.calc.subtract(5, 3) == 2
|
||||
assert self.calc.subtract(1, 1) == 0
|
||||
assert self.calc.subtract(-1, -2) == 1
|
||||
|
||||
def test_multiply(self):
|
||||
"""Test multiplication operation."""
|
||||
assert self.calc.multiply(3, 4) == 12
|
||||
assert self.calc.multiply(-2, 3) == -6
|
||||
assert self.calc.multiply(0, 100) == 0
|
||||
|
||||
def test_divide(self):
|
||||
"""Test division operation."""
|
||||
assert self.calc.divide(10, 2) == 5.0
|
||||
assert self.calc.divide(7, 2) == 3.5
|
||||
assert self.calc.divide(-6, 3) == -2.0
|
||||
|
||||
def test_divide_by_zero(self):
|
||||
"""Test division by zero raises error."""
|
||||
with pytest.raises(ValueError, match="Cannot divide by zero"):
|
||||
self.calc.divide(5, 0)
|
||||
|
||||
def test_power(self):
|
||||
"""Test power operation."""
|
||||
assert self.calc.power(2, 3) == 8
|
||||
assert self.calc.power(5, 0) == 1
|
||||
assert self.calc.power(2, -1) == 0.5
|
||||
Reference in New Issue
Block a user