# SPDX-License-Identifier: Apache-2.0
# Copyright 2025 Python Calculator Project

"""Simple demonstration of the calculator functionality."""

from calculator import Calculator, CalculatorError

def main():
    """Demonstrate calculator functionality."""
    print("Python Calculator Demo")
    print("=====================")
    
    calc = Calculator()
    
    # Test basic operations
    print("\n1. Basic Operations:")
    print(f"   2 + 3 = {calc.add(2, 3)}")
    print(f"   10 - 4 = {calc.subtract(10, 4)}")
    print(f"   5 * 6 = {calc.multiply(5, 6)}")
    print(f"   15 / 3 = {calc.divide(15, 3)}")
    print(f"   2^8 = {calc.power(2, 8)}")
    print(f"   17 % 5 = {calc.modulo(17, 5)}")
    
    # Test mathematical functions
    print("\n2. Mathematical Functions:")
    print(f"   sqrt(64) = {calc.apply_function('sqrt', 64)}")
    print(f"   abs(-10) = {calc.apply_function('abs', -10)}")
    print(f"   factorial(5) = {calc.apply_function('factorial', 5)}")
    
    # Test expression evaluation
    print("\n3. Expression Evaluation:")
    expressions = [
        '2 + 3 * 4',
        '(2 + 3) * 4', 
        'sqrt(16) + 2^3',
        'abs(-5) + ceil(4.3)'
    ]
    
    for expr in expressions:
        try:
            result = calc.evaluate_expression(expr)
            print(f"   {expr} = {result}")
        except CalculatorError as e:
            print(f"   {expr} -> Error: {e}")
    
    # Test memory operations
    print("\n4. Memory Operations:")
    calc.memory_store(100)
    print(f"   Stored 100 in memory")
    print(f"   Memory recall: {calc.memory_recall()}")
    
    calc.memory_add(25)
    print(f"   Added 25 to memory: {calc.memory_recall()}")
    
    # Test error handling
    print("\n5. Error Handling:")
    try:
        calc.divide(5, 0)
    except CalculatorError as e:
        print(f"   Division by zero: {e}")
    
    try:
        calc.square_root(-1)
    except CalculatorError as e:
        print(f"   Square root of negative: {e}")
    
    print("\nDemo completed successfully!")

if __name__ == "__main__":
    main()