#Hashmap rustlings help

20 messages · Page 1 of 1 (latest)

slim mango
#

what are you specifically struggling with

tender creek
#

i don't know what to write

#

is it safe to use an LLM or better to ask here?

slim mango
#

i mean if i wanted to learn i wouldnt use LLMs

tender creek
slim mango
tender creek
#

more like i have no idea what to write

#

am thinking to make a for loop but nothing comes up after that

slim mango
#

isn't it just summing how many times a team goaled and didnt goal

tender creek
#

yeah, but like i got no idea how to write the code required

slim mango
#

have you at least read the docs for HashMap

tender creek
#

am i thinking straight??

slim mango
#

how would you loop the thru the hashmap that doesnt have any elements yet

#

i'd imagine that by "populate" the exercise is asking you to HashMap::insert to the map (or some other variation)

tender creek
#
#[cfg(test)]
mod tests {
    use super::*;

    const RESULTS: &str = "England,France,4,2
France,Italy,3,1
Poland,Spain,2,0
Germany,England,2,1
England,Spain,1,0";

    #[test]
    fn build_scores() {
        let scores = build_scores_table(RESULTS);

        assert!(["England", "France", "Germany", "Italy", "Poland", "Spain"]
            .into_iter()
            .all(|team_name| scores.contains_key(team_name)));
    }

    #[test]
    fn validate_team_score_1() {
        let scores = build_scores_table(RESULTS);
        let team = scores.get("England").unwrap();
        assert_eq!(team.goals_scored, 6);
        assert_eq!(team.goals_conceded, 4);
    }

    #[test]
    fn validate_team_score_2() {
        let scores = build_scores_table(RESULTS);
        let team = scores.get("Spain").unwrap();
        assert_eq!(team.goals_scored, 0);
        assert_eq!(team.goals_conceded, 3);
    }
}
tender creek
slim mango
#

yea i'm reading it from the repo