"""Tests para words_to_dataset."""

import sys
import os

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

from words_to_dataset import words_to_dataset


def test_cuenta_palabras_repetidas():
    texts = ["calle mayor", "calle del sol", "avenida principal"]
    result = words_to_dataset(texts)
    palabras = {r["palabra"]: r["ocurrencias"] for r in result}
    assert palabras["CALLE"] == 2


def test_eliminar_stopwords_filtra_del():
    texts = ["calle mayor", "calle del sol", "avenida principal"]
    result = words_to_dataset(texts, eliminar_stopwords=True)
    palabras = {r["palabra"] for r in result}
    assert "DEL" not in palabras


def test_min_ocurrencias_filtra():
    texts = ["calle mayor", "calle del sol", "avenida principal"]
    result = words_to_dataset(texts, min_ocurrencias=2)
    palabras = {r["palabra"]: r["ocurrencias"] for r in result}
    assert "CALLE" in palabras
    assert "MAYOR" not in palabras


def test_none_ignorados():
    texts = ["hola mundo", None, "hola"]
    result = words_to_dataset(texts)
    palabras = {r["palabra"]: r["ocurrencias"] for r in result}
    assert palabras["HOLA"] == 2


def test_lista_vacia():
    result = words_to_dataset([])
    assert result == []


def test_orden_descendente():
    texts = ["a a a", "b b", "c"]
    result = words_to_dataset(texts)
    counts = [r["ocurrencias"] for r in result]
    assert counts == sorted(counts, reverse=True)
