import pytest
from hypothesis import given, strategies as st
from robobench.core.runtime import RuntimeBenchmark, RuntimeMetrics
from unittest.mock import patch, MagicMock

@pytest.fixture
def runtime_benchmark(mock_model_name):
    return RuntimeBenchmark(mock_model_name)

def test_runtime_benchmark_initialization(runtime_benchmark):
    assert runtime_benchmark.model_name.count(":") == 1
    assert len(runtime_benchmark.batch_prompts) > 0

@given(st.lists(st.floats(min_value=0.1, max_value=10.0), min_size=1))
def test_token_variance_calculation(runtime_benchmark, latencies):
    variance = runtime_benchmark._calculate_variance([f"token_{i}" for i in range(len(latencies))])
    assert variance >= 0

@patch('subprocess.run')
def test_measure_first_token_latency(mock_run, runtime_benchmark, mock_cortex_response):
    mock_run.return_value = MagicMock(
        stdout=mock_cortex_response,
        returncode=0
    )

    latency = runtime_benchmark._measure_first_token_latency()
    assert latency > 0
