From 02481656966b0a8dfc95cf3c22bcc049660ff7d4 Mon Sep 17 00:00:00 2001 From: Federico Igne Date: Sat, 26 Dec 2020 17:48:38 +0000 Subject: Move Rust exercises in a subdirectory --- rust/high-scores/tests/high-scores.rs | 68 +++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 rust/high-scores/tests/high-scores.rs (limited to 'rust/high-scores/tests/high-scores.rs') diff --git a/rust/high-scores/tests/high-scores.rs b/rust/high-scores/tests/high-scores.rs new file mode 100644 index 0000000..4d2feb7 --- /dev/null +++ b/rust/high-scores/tests/high-scores.rs @@ -0,0 +1,68 @@ +use high_scores::HighScores; + +#[test] +fn test_list_of_scores() { + let expected = [30, 50, 20, 70]; + let high_scores = HighScores::new(&expected); + assert_eq!(high_scores.scores(), &expected); +} + +#[test] +fn test_latest_score() { + let high_scores = HighScores::new(&[100, 0, 90, 30]); + assert_eq!(high_scores.latest(), Some(30)); +} + +#[test] +fn test_latest_score_empty() { + let high_scores = HighScores::new(&[]); + assert_eq!(high_scores.latest(), None); +} + +#[test] +fn test_personal_best() { + let high_scores = HighScores::new(&[40, 100, 70]); + assert_eq!(high_scores.personal_best(), Some(100)); +} + +#[test] +fn test_personal_best_empty() { + let high_scores = HighScores::new(&[]); + assert_eq!(high_scores.personal_best(), None); +} + +#[test] +fn test_personal_top_three() { + let high_scores = HighScores::new(&[10, 30, 90, 30, 100, 20, 10, 0, 30, 40, 40, 70, 70]); + assert_eq!(high_scores.personal_top_three(), vec![100, 90, 70]); +} + +#[test] +fn test_personal_top_three_highest_to_lowest() { + let high_scores = HighScores::new(&[20, 10, 30]); + assert_eq!(high_scores.personal_top_three(), vec![30, 20, 10]); +} + +#[test] +fn test_personal_top_three_with_tie() { + let high_scores = HighScores::new(&[40, 20, 40, 30]); + assert_eq!(high_scores.personal_top_three(), vec![40, 40, 30]); +} + +#[test] +fn test_personal_top_three_with_less_than_three_scores() { + let high_scores = HighScores::new(&[30, 70]); + assert_eq!(high_scores.personal_top_three(), vec![70, 30]); +} + +#[test] +fn test_personal_top_three_only_one_score() { + let high_scores = HighScores::new(&[40]); + assert_eq!(high_scores.personal_top_three(), vec![40]); +} + +#[test] +fn test_personal_top_three_empty() { + let high_scores = HighScores::new(&[]); + assert!(high_scores.personal_top_three().is_empty()); +} -- cgit v1.2.3