This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add this module to your main code | |
#[cfg(test)] | |
mod tests { | |
use super::*; | |
fn make_stamps() -> Vec<Stamp> { | |
vec![INITIAL_STAMP, | |
Stamp {offset: 1, score: Score {home: 0, away: 0}}, | |
Stamp {offset: 2, score: Score {home: 1, away: 0}}, | |
Stamp {offset: 4, score: Score {home: 1, away: 0}}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn get_score(game_stamps: &[Stamp], offset: i32) -> (i32, i32) { | |
// Using binary search because the vector is sorted by offset | |
let found_index = game_stamps.binary_search_by_key(&offset, |s| s.offset).unwrap(); | |
(game_stamps[found_index].score.home, game_stamps[found_index].score.away) | |
} |