"""
tests/test_environment.py

Tests for Module 1: Environment & Channel Simulator
"""

import pytest
import numpy as np
from src.models.environment import EnvironmentConfig, ChannelSimulator


def test_environment_initialization():
    config = EnvironmentConfig(num_users=10, num_channels=10, bandwidth=1e6)
    env = ChannelSimulator(config)
    assert env.config.num_users == 10
    assert env.config.num_channels == 10
    assert env.config.bandwidth == 1e6


def test_path_loss_calculation():
    config = EnvironmentConfig(num_users=1, num_channels=1)
    env = ChannelSimulator(config)

    # 1 km distance
    distances = np.array([1.0])
    path_loss = env._calculate_pathloss(distances)
    # PL = 128.1 + 37.6 * log10(d)
    expected_pl = 128.1
    np.testing.assert_allclose(path_loss, expected_pl, atol=1e-5)


def test_snr_generation():
    config = EnvironmentConfig(num_users=5, num_channels=3)
    env = ChannelSimulator(config)

    transmit_power_dbm = 10.0
    snr_db, snr_linear = env.generate_channels(transmit_power_dbm)

    assert snr_db.shape == (5, 3)
    assert snr_linear.shape == (5, 3)
    assert np.all(snr_linear > 0)
