#Hashmap rustlings help
20 messages · Page 1 of 1 (latest)
the whole question
i don't know what to write
is it safe to use an LLM or better to ask here?
i mean if i wanted to learn i wouldnt use LLMs
well thing is though, am not sure if the question makes sense or i do not know how to implement it at this point tbh
i mean, not sure what's confusing about the question to me
there is nothing wrong with the question. the problem is how can i write the code that this problem requires me to
more like i have no idea what to write
am thinking to make a for loop but nothing comes up after that
isn't it just summing how many times a team goaled and didnt goal
yeah, but like i got no idea how to write the code required
have you at least read the docs for HashMap
i did, but if i had to be specific, the one part am puzzled with is that am trying to make a for i in v loop to loop thru hashmap, then read scored goals and goals conceded then save both numbers in the team then return that
am i thinking straight??
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)
#[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);
}
}
mb forgot to send the test function, this is the test function
yea i'm reading it from the repo