import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.List;
import java.util.Map;
import java.util.Set;

import org.junit.jupiter.api.Test;

class WordCountTest {

    @Test
    void countsIgnoringCaseAndPunctuation() {
        Map<String, Integer> counts = WordCount.count("Lima, lima. LIMA y Cusco");
        assertEquals(3, counts.get("lima"));
        assertEquals(1, counts.get("cusco"));
        assertNull(counts.get("Lima"));             // las claves quedan en minúsculas
    }

    @Test
    void emptyTextGivesEmptyMap() {
        assertTrue(WordCount.count("").isEmpty());
        assertTrue(WordCount.count(" ... ").isEmpty());
    }

    @Test
    void keysComeOutInAlphabeticalOrder() {
        Map<String, Integer> counts = WordCount.count("río mar arena mar");
        assertEquals(List.of("arena", "mar", "río"), List.copyOf(counts.keySet()));
    }

    @Test
    void indexKeepsEachLineOnceAndSorted() {
        Map<String, Set<Integer>> index = WordIndex.index(List.of("el río", "el mar, el río", "mar"));
        assertEquals(Set.of(1, 2), index.get("el"));
        assertEquals(List.of(2, 3), List.copyOf(index.get("mar")));
        assertNull(index.get("sol"));
    }
}
