#!/usr/bin/env python3
"""
Unit tests for Python pi calculation using pytest
"""

import subprocess
import pytest

SCRIPT_PATH = "/Users/einand/Code/test/python/print_hej.py"

def run_script(decimals=None):
    """Run the Python script with optional decimals argument"""
    cmd = ["python3", SCRIPT_PATH]
    if decimals is not None:
        cmd.append(str(decimals))
    result = subprocess.run(cmd, capture_output=True, text=True)
    return result.stdout.strip()

class TestPiCalculation:
    """Test cases for pi calculation"""
    
    def test_10_decimals(self):
        """Test with 10 decimal places"""
        result = run_script(10)
        expected = "3.1415926535"
        assert result == expected, f"Expected {expected}, got {result}"
    
    def test_5_decimals(self):
        """Test with 5 decimal places"""
        result = run_script(5)
        expected = "3.14159"
        assert result == expected, f"Expected {expected}, got {result}"
    
    def test_1_decimal(self):
        """Test with 1 decimal place"""
        result = run_script(1)
        expected = "3.1"
        assert result == expected, f"Expected {expected}, got {result}"
    
    def test_100_decimals(self):
        """Test with 100 decimal places"""
        result = run_script(100)
        expected = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679"
        assert result == expected, f"Expected {expected}, got {result}"
    
    def test_default_100_decimals(self):
        """Test default (100 decimal places)"""
        result = run_script()
        expected = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679"
        assert result == expected, f"Expected {expected}, got {result}"
    
    def test_invalid_input(self):
        """Test with invalid input (should use default 100)"""
        result = run_script("invalid")
        expected = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679"
        assert result == expected, f"Expected {expected}, got {result}"
    
    def test_10000_decimals(self):
        """Test with 10000 decimal places"""
        result = run_script(10000)
        # Check length: "3." + 10000 digits = 10002 characters
        assert len(result) == 10002, f"Expected 10002 characters, got {len(result)}"
        assert result.startswith("3.14159"), f"Result should start with 3.14159, got {result[:10]}"

if __name__ == "__main__":
    pytest.main([__file__, "-v"])