"""
Tests for Equation of State module
"""

import pytest
import numpy as np
from src.core.equation_of_state import EquationOfState


class TestEquationOfState:
    """Test suite for EquationOfState"""
    
    def test_initialization(self):
        """Test initialization"""
        eos = EquationOfState(temperature=2.0, salinity=34.7, depth=10911)
        assert eos.temperature == 2.0
        assert eos.salinity == 34.7
        assert eos.depth == 10911
    
    def test_surface_density(self):
        """Test surface density calculation"""
        eos = EquationOfState(temperature=2.0, salinity=34.7)
        rho0 = eos.surface_density()
        # Surface density should be around 1025 kg/m³ with some tolerance
        assert 1020 <= rho0 <= 1030
    
    def test_density_calculation(self):
        """Test density calculation at depth"""
        # Challenger Deep conditions
        eos = EquationOfState(temperature=1.9, salinity=34.68, depth=10911)
        rho = eos.compute_density()
        
        # Density should be physically reasonable
        assert 1000 < rho < 1200
    
    def test_compression_ratio(self):
        """Test compression ratio calculation"""
        eos = EquationOfState(temperature=1.9, salinity=34.68, depth=10911)
        ratio = eos.compression_ratio()
        
        # Compression ratio should be positive and reasonable
        assert 0 < ratio < 0.2
    
    def test_bulk_modulus(self):
        """Test bulk modulus calculation"""
        eos = EquationOfState(pressure=110.0)
        B = eos.bulk_modulus()
        assert B > 0
    
    def test_pressure_depth_conversion(self):
        """Test pressure-depth conversion"""
        eos = EquationOfState()
        
        # 10,000m should be about 100 MPa
        P = eos._depth_to_pressure(10000)
        assert 90 < P < 110
        
        D = eos._pressure_to_depth(100)
        assert 9000 < D < 11000
    
    def test_temperature_salinity_effects(self):
        """Test effects of temperature and salinity"""
        eos1 = EquationOfState(temperature=2.0, salinity=34.7, depth=1000)
        eos2 = EquationOfState(temperature=10.0, salinity=35.0, depth=1000)
        
        rho1 = eos1.compute_density()
        rho2 = eos2.compute_density()
        
        # Higher temperature = lower density
        assert rho2 < rho1
