import pytest
from hypothesis import given, strategies as st
from robobench.core.resources import ResourceBenchmark, ResourceMetrics
from unittest.mock import patch

@pytest.fixture
def resource_benchmark(mock_model_name):
    return ResourceBenchmark(mock_model_name)

def test_resource_benchmark_initialization(resource_benchmark):
    assert resource_benchmark.duration > 0
    assert resource_benchmark.sampling_interval > 0

@given(st.lists(st.floats(min_value=100.0, max_value=1000.0), min_size=2))
def test_memory_growth_calculation(resource_benchmark, memory_values):
    snapshots = [
        MemorySnapshot(ram_used=value)
        for value in memory_values
    ]
    growth_rate = resource_benchmark._calculate_memory_growth(snapshots)
    assert isinstance(growth_rate, float)

@patch('psutil.cpu_percent')
@patch('psutil.virtual_memory')
def test_system_metrics_collection(mock_vmem, mock_cpu, resource_benchmark):
    mock_cpu.return_value = 50.0
    mock_vmem.return_value = MagicMock(percent=60.0)

    metrics = resource_benchmark._get_system_metrics()
    assert len(metrics) == 3  # load_avg, io_ops, net_usage
