volli-core 0.1.11

Shared types for volli
Documentation
use eyre::{Report, eyre};
use rand::prelude::IndexedRandom;
use rand::rng;

const ADJECTIVES: &[&str] = &[
    "brave",
    "calm",
    "eager",
    "swift",
    "bold",
    "bright",
    "clever",
    "curious",
    "daring",
    "gentle",
    "happy",
    "jolly",
    "kind",
    "lively",
    "mighty",
    "noble",
    "proud",
    "quick",
    "rapid",
    "silent",
    "shy",
    "smart",
    "strong",
    "tiny",
    "vast",
    "young",
    "zany",
    "wild",
    "keen",
    "fierce",
    "loyal",
    "wise",
    "steady",
    "witty",
    "fuzzy",
    "graceful",
    "harmonious",
    "radiant",
    "vivid",
    "serene",
    "mellow",
    "sturdy",
    "playful",
    "cheerful",
    "crafty",
    "glad",
    "jovial",
    "spry",
    "charming",
    "breezy",
    "dapper",
    "earthy",
    "fiery",
    "gleaming",
    "humble",
    "mystic",
    "nimble",
    "polite",
    "quirky",
    "rustic",
    "savvy",
    "tender",
    "upbeat",
    "zesty",
];
const NOUNS: &[&str] = &[
    "sun", "moon", "star", "cloud", "river", "mountain", "forest", "stone", "lake", "ocean",
    "field", "meadow", "plain", "hill", "valley", "cliff", "desert", "canyon", "storm", "rain",
    "wind", "breeze", "leaf", "flower", "tree", "bush", "seed", "root", "branch", "wave", "fire",
    "ember", "glow", "light", "shadow", "echo", "frost", "snow", "ice", "mist", "spark", "thunder",
    "rainbow", "comet", "meteor", "galaxy", "orbit", "planet", "dust", "dawn", "dusk", "reef",
    "island", "shore", "beach", "peak", "trail", "marsh", "swamp", "brook", "delta", "glen",
    "grove", "cave",
];

const ANIMALS: &[&str] = &[
    "panda",
    "lion",
    "otter",
    "eagle",
    "falcon",
    "tiger",
    "koala",
    "yak",
    "wolf",
    "bear",
    "fox",
    "hare",
    "deer",
    "badger",
    "weasel",
    "owl",
    "hawk",
    "crow",
    "raven",
    "sparrow",
    "serpent",
    "lizard",
    "gecko",
    "python",
    "viper",
    "shark",
    "whale",
    "dolphin",
    "seal",
    "penguin",
    "walrus",
    "gorilla",
    "lemur",
    "monkey",
    "baboon",
    "rhino",
    "hippo",
    "buffalo",
    "camel",
    "donkey",
    "horse",
    "zebra",
    "antelope",
    "cheetah",
    "leopard",
    "jaguar",
    "cougar",
    "lynx",
    "ferret",
    "mink",
    "mouse",
    "rat",
    "squirrel",
    "chipmunk",
    "giraffe",
    "elephant",
    "moose",
    "turkey",
    "chicken",
    "rooster",
    "parrot",
    "iguana",
    "alligator",
    "crocodile",
];

pub fn random_profile() -> Result<String, Report> {
    let mut rng = rng();
    let adjective = ADJECTIVES
        .choose(&mut rng)
        .ok_or_else(|| eyre!("no adjectives"))?;
    let noun = NOUNS.choose(&mut rng).ok_or_else(|| eyre!("no nouns"))?;
    let animal = ANIMALS
        .choose(&mut rng)
        .ok_or_else(|| eyre!("no animals"))?;
    Ok(format!("{adjective}-{noun}-{animal}"))
}

#[cfg(test)]
mod tests {
    use super::random_profile;
    use std::collections::HashSet;

    #[test]
    fn random_profile_unique() {
        let mut set = HashSet::new();
        for _ in 0..100 {
            let name = random_profile().unwrap();
            set.insert(name);
        }
        assert!(set.len() > 90);
    }

    #[test]
    fn random_profile_format() {
        let name = random_profile().unwrap();
        let parts: Vec<&str> = name.split('-').collect();
        assert_eq!(parts.len(), 3);
    }
}