Struct scoreboard::ScoreBoard
source · pub struct ScoreBoard { /* private fields */ }
Expand description
Score board representation
Implementations§
source§impl ScoreBoard
impl ScoreBoard
sourcepub fn new() -> ScoreBoard
pub fn new() -> ScoreBoard
Returns a newly created, empty score board
sourcepub fn start_game<T: ToString, U: ToString>(
&mut self,
home: T,
away: U
) -> Result<(), String>
pub fn start_game<T: ToString, U: ToString>( &mut self, home: T, away: U ) -> Result<(), String>
Starts a game between two teams, with initial score 0 - 0
Arguments
home
- Name of the home team. Must be either aString
or a type that is convertable toString
away
- Name of the away team. Must be either aString
or a type that is convertable toString
Errors
- When the two provided names are the same
- When any of the provided team is currently playing a match
Examples
let mut expected_result: Vec<String> = Vec::new();
expected_result.push(String::from("Japan 0 - Indonesia 0"));
let mut sb = scoreboard::ScoreBoard::new();
sb.start_game("Japan", "Indonesia");
let summary = sb.get_summary();
assert_eq!(summary, expected_result);
sourcepub fn update_score<T: ToString, U: ToString>(
&mut self,
home: T,
new_home_score: u8,
away: U,
new_away_score: u8
) -> Result<(), String>
pub fn update_score<T: ToString, U: ToString>( &mut self, home: T, new_home_score: u8, away: U, new_away_score: u8 ) -> Result<(), String>
Updates a score of a running match with absolute values
Arguments
home
- Name of the home team. Must be either aString
or a type that is convertable toString
new_home_score
- A new score to be set for the home teamaway
- Name of the away team. Must be either aString
or a type that is convertable toString
new_away_score
- A new score to be set for the away team
Errors
- When there is no active match between the given teams
Examples
let mut expected_result: Vec<String> = Vec::new();
expected_result.push(String::from("Japan 2 - Indonesia 0"));
let mut sb = scoreboard::ScoreBoard::new();
sb.start_game("Japan", "Indonesia");
sb.update_score("Japan", 2, "Indonesia", 0);
let summary = sb.get_summary();
assert_eq!(summary, expected_result);
sourcepub fn finish_game<T: ToString, U: ToString>(
&mut self,
home: T,
away: U
) -> Result<(), String>
pub fn finish_game<T: ToString, U: ToString>( &mut self, home: T, away: U ) -> Result<(), String>
Finishes a match and removes it from the score board
Arguments
home
- Name of the home team. Must be either aString
or a type that is convertable toString
away
- Name of the away team. Must be either aString
or a type that is convertable toString
Errors
- When there is no active match between the given teams
Examples
let mut expected_result: Vec<String> = Vec::new();
let mut sb = scoreboard::ScoreBoard::new();
sb.start_game("Japan", "Indonesia");
sb.update_score("Japan", 2, "Indonesia", 0);
sb.finish_game("Japan", "Indonesia");
let summary = sb.get_summary();
assert_eq!(summary, expected_result);
sourcepub fn get_summary(&self) -> Vec<String>
pub fn get_summary(&self) -> Vec<String>
Provides the current status of the scoreboard, with all current matches listed. The matches are ordered by total score (the highest coming first) and, in the case of the same score, by start time (the earliest match coming first)
Returns
- A vector of strings, each string containing the home team, its score, the away team and its score
Examples
let mut expected_result: Vec<String> = Vec::new();
expected_result.push(String::from("Japan 0 - Indonesia 0"));
let mut sb = scoreboard::ScoreBoard::new();
sb.start_game("Japan", "Indonesia");
let summary = sb.get_summary();
assert_eq!(summary, expected_result);