"""Tests para geometric_mean."""

import math
import sys
import os

sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
from geometric_mean import geometric_mean


def test_geometric_mean_powers_of_two():
    result = geometric_mean([1, 2, 4, 8])
    expected = 2 ** 1.5  # ~2.828
    assert abs(result - expected) < 1e-6, f"Expected ~{expected}, got {result}"


def test_geometric_mean_filters_non_positive():
    result = geometric_mean([1, -2, 3])
    expected = math.exp((math.log(1) + math.log(3)) / 2)
    assert abs(result - expected) < 1e-6


def test_geometric_mean_empty_returns_nan():
    result = geometric_mean([])
    assert math.isnan(result)


def test_geometric_mean_all_negative_returns_nan():
    result = geometric_mean([-1, -2, -3])
    assert math.isnan(result)


def test_geometric_mean_single_positive():
    result = geometric_mean([9.0])
    assert abs(result - 9.0) < 1e-9
