use crate::data;

/// Iterates embedded dictionary names grouped by length from `min_len` to `max_len`.
pub fn iter_names(min_len: usize, max_len: usize) -> impl Iterator<Item = &'static str> {
    data::only_names(min_len, max_len)
}

/// Iterates embedded dictionary words grouped by length from `min_len` to `max_len`.
pub fn iter_words(min_len: usize, max_len: usize) -> impl Iterator<Item = &'static str> {
    data::only_words(min_len, max_len)
}

#[cfg(test)]
mod tests {
    use super::{iter_names, iter_words};

    #[test]
    fn iter_words_filters_and_orders() {
        let collected: Vec<&'static str> = iter_words(3, 5).collect();
        assert!(!collected.is_empty());
        assert!(collected.len() > 1500, "expected a larger dictionary slice");
        assert!(collected.iter().all(|word| (3..=5).contains(&word.len())));
        assert!(collected.windows(2).all(|pair| pair[0].len() <= pair[1].len()));
        for len in 3..=5 {
            let bucket: Vec<&'static str> =
                collected.iter().copied().filter(|word| word.len() == len).collect();
            assert!(bucket.windows(2).all(|pair| pair[0] <= pair[1]));
        }
    }

    #[test]
    fn iter_names_filters_and_orders() {
        let collected: Vec<&'static str> = iter_names(4, 5).collect();
        assert_eq!(collected, vec!["juno", "elara", "fiona", "greta"]);
    }
}
