"""Tests for the Calculator class"""

import pytest
from zsz_package.calculator import Calculator


class TestCalculator:
    """Test suite for Calculator class."""

    def test_add(self):
        """Test addition."""
        calc = Calculator()
        assert calc.add(2, 3) == 5
        assert calc.add(-1, 1) == 0
        assert calc.add(0.1, 0.2) == pytest.approx(0.3)

    def test_subtract(self):
        """Test subtraction."""
        calc = Calculator()
        assert calc.subtract(5, 3) == 2
        assert calc.subtract(0, 5) == -5
        assert calc.subtract(10.5, 0.5) == 10.0

    def test_multiply(self):
        """Test multiplication."""
        calc = Calculator()
        assert calc.multiply(3, 4) == 12
        assert calc.multiply(-2, 3) == -6
        assert calc.multiply(0, 100) == 0
        assert calc.multiply(2.5, 4) == 10.0

    def test_divide(self):
        """Test division."""
        calc = Calculator()
        assert calc.divide(10, 2) == 5.0
        assert calc.divide(7, 2) == 3.5
        assert calc.divide(-10, 2) == -5.0

    def test_divide_by_zero(self):
        """Test division by zero raises ValueError."""
        calc = Calculator()
        with pytest.raises(ValueError, match="Cannot divide by zero"):
            calc.divide(10, 0)

    def test_power(self):
        """Test exponentiation."""
        calc = Calculator()
        assert calc.power(2, 3) == 8
        assert calc.power(5, 0) == 1
        assert calc.power(4, 0.5) == 2.0
        assert calc.power(10, -1) == 0.1

    def test_history(self):
        """Test calculation history."""
        calc = Calculator()
        calc.add(1, 2)
        calc.multiply(3, 4)
        
        history = calc.get_history()
        assert len(history) == 2
        assert "1 + 2 = 3" in history
        assert "3 * 4 = 12" in history

    def test_clear_history(self):
        """Test clearing history."""
        calc = Calculator()
        calc.add(1, 2)
        calc.subtract(5, 3)
        calc.clear_history()
        
        assert len(calc.get_history()) == 0

    def test_multiple_operations(self, sample_numbers):
        """Test multiple operations in sequence."""
        calc = Calculator()
        a, b = sample_numbers["a"], sample_numbers["b"]
        
        result1 = calc.add(a, b)  # 15
        result2 = calc.multiply(result1, 2)  # 30
        result3 = calc.divide(result2, 3)  # 10.0
        
        assert result3 == 10.0
        assert len(calc.get_history()) == 3
