-
-
Save mrbus/d00aa10eee95dd0583364dd5d35461d5 to your computer and use it in GitHub Desktop.
Rust Developer Intern - Task 2
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}}, | |
Stamp {offset: 5, score: Score {home: 1, away: 0}}, | |
Stamp {offset: 6, score: Score {home: 1, away: 0}}, | |
Stamp {offset: 9, score: Score {home: 2, away: 0}}, | |
Stamp {offset: 10, score: Score {home: 2, away: 1}}, | |
Stamp {offset: 12, score: Score {home: 2, away: 1}}, | |
Stamp {offset: 15, score: Score {home: 3, away: 1}}, | |
Stamp {offset: 16, score: Score {home: 3, away: 2}}, | |
Stamp {offset: 19, score: Score {home: 3, away: 2}}, | |
Stamp {offset: 21, score: Score {home: 3, away: 3}}, | |
Stamp {offset: 22, score: Score {home: 3, away: 4}}, | |
Stamp {offset: 23, score: Score {home: 3, away: 4}}, | |
Stamp {offset: 26, score: Score {home: 3, away: 4}}, | |
Stamp {offset: 27, score: Score {home: 3, away: 5}}, | |
Stamp {offset: 29, score: Score {home: 4, away: 5}}, | |
Stamp {offset: 31, score: Score {home: 4, away: 5}}, | |
Stamp {offset: 32, score: Score {home: 4, away: 6}}, | |
Stamp {offset: 33, score: Score {home: 4, away: 6}}, | |
Stamp {offset: 36, score: Score {home: 4, away: 6}}, | |
Stamp {offset: 38, score: Score {home: 4, away: 7}}, | |
Stamp {offset: 39, score: Score {home: 5, away: 7}}, | |
Stamp {offset: 40, score: Score {home: 5, away: 7}}, | |
Stamp {offset: 43, score: Score {home: 5, away: 7}}, | |
Stamp {offset: 45, score: Score {home: 5, away: 8}}] | |
} | |
#[test] | |
fn test_no_panic() { | |
let stamps = make_stamps(); | |
assert_eq!(get_score(&stamps, 0), (0, 0)); | |
assert_eq!(get_score(&stamps, 1), (0, 0)); | |
assert_eq!(get_score(&stamps, 6), (1, 0)); | |
assert_eq!(get_score(&stamps, 16), (3, 2)); | |
assert_eq!(get_score(&stamps, 29), (4, 5)); | |
assert_eq!(get_score(&stamps, 45), (5, 8)); | |
} | |
#[test] | |
#[should_panic] | |
fn test_panic1() { | |
let stamps = make_stamps(); | |
get_score(&stamps, 3); | |
} | |
#[test] | |
#[should_panic] | |
fn test_panic2() { | |
let stamps = make_stamps(); | |
get_score(&stamps, 7); | |
} | |
#[test] | |
#[should_panic] | |
fn test_panic3() { | |
let stamps = make_stamps(); | |
get_score(&stamps, 11); | |
} | |
#[test] | |
#[should_panic] | |
fn test_panic4() { | |
let stamps = make_stamps(); | |
get_score(&stamps, 24); | |
} | |
#[test] | |
#[should_panic] | |
fn test_panic5() { | |
let stamps = make_stamps(); | |
get_score(&stamps, 37); | |
} | |
#[test] | |
#[should_panic] | |
fn test_panic6() { | |
let stamps = make_stamps(); | |
get_score(&stamps, 46); | |
} | |
#[test] | |
#[should_panic] | |
fn test_panic7() { | |
let stamps = make_stamps(); | |
get_score(&stamps, 47); | |
} | |
#[test] | |
#[should_panic] | |
fn test_panic8() { | |
let stamps = make_stamps(); | |
get_score(&stamps, 100); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment