diff options
Diffstat (limited to 'high-scores/tests/high-scores.rs')
| -rw-r--r-- | high-scores/tests/high-scores.rs | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/high-scores/tests/high-scores.rs b/high-scores/tests/high-scores.rs new file mode 100644 index 0000000..4d2feb7 --- /dev/null +++ b/high-scores/tests/high-scores.rs | |||
| @@ -0,0 +1,68 @@ | |||
| 1 | use high_scores::HighScores; | ||
| 2 | |||
| 3 | #[test] | ||
| 4 | fn test_list_of_scores() { | ||
| 5 | let expected = [30, 50, 20, 70]; | ||
| 6 | let high_scores = HighScores::new(&expected); | ||
| 7 | assert_eq!(high_scores.scores(), &expected); | ||
| 8 | } | ||
| 9 | |||
| 10 | #[test] | ||
| 11 | fn test_latest_score() { | ||
| 12 | let high_scores = HighScores::new(&[100, 0, 90, 30]); | ||
| 13 | assert_eq!(high_scores.latest(), Some(30)); | ||
| 14 | } | ||
| 15 | |||
| 16 | #[test] | ||
| 17 | fn test_latest_score_empty() { | ||
| 18 | let high_scores = HighScores::new(&[]); | ||
| 19 | assert_eq!(high_scores.latest(), None); | ||
| 20 | } | ||
| 21 | |||
| 22 | #[test] | ||
| 23 | fn test_personal_best() { | ||
| 24 | let high_scores = HighScores::new(&[40, 100, 70]); | ||
| 25 | assert_eq!(high_scores.personal_best(), Some(100)); | ||
| 26 | } | ||
| 27 | |||
| 28 | #[test] | ||
| 29 | fn test_personal_best_empty() { | ||
| 30 | let high_scores = HighScores::new(&[]); | ||
| 31 | assert_eq!(high_scores.personal_best(), None); | ||
| 32 | } | ||
| 33 | |||
| 34 | #[test] | ||
| 35 | fn test_personal_top_three() { | ||
| 36 | let high_scores = HighScores::new(&[10, 30, 90, 30, 100, 20, 10, 0, 30, 40, 40, 70, 70]); | ||
| 37 | assert_eq!(high_scores.personal_top_three(), vec![100, 90, 70]); | ||
| 38 | } | ||
| 39 | |||
| 40 | #[test] | ||
| 41 | fn test_personal_top_three_highest_to_lowest() { | ||
| 42 | let high_scores = HighScores::new(&[20, 10, 30]); | ||
| 43 | assert_eq!(high_scores.personal_top_three(), vec![30, 20, 10]); | ||
| 44 | } | ||
| 45 | |||
| 46 | #[test] | ||
| 47 | fn test_personal_top_three_with_tie() { | ||
| 48 | let high_scores = HighScores::new(&[40, 20, 40, 30]); | ||
| 49 | assert_eq!(high_scores.personal_top_three(), vec![40, 40, 30]); | ||
| 50 | } | ||
| 51 | |||
| 52 | #[test] | ||
| 53 | fn test_personal_top_three_with_less_than_three_scores() { | ||
| 54 | let high_scores = HighScores::new(&[30, 70]); | ||
| 55 | assert_eq!(high_scores.personal_top_three(), vec![70, 30]); | ||
| 56 | } | ||
| 57 | |||
| 58 | #[test] | ||
| 59 | fn test_personal_top_three_only_one_score() { | ||
| 60 | let high_scores = HighScores::new(&[40]); | ||
| 61 | assert_eq!(high_scores.personal_top_three(), vec![40]); | ||
| 62 | } | ||
| 63 | |||
| 64 | #[test] | ||
| 65 | fn test_personal_top_three_empty() { | ||
| 66 | let high_scores = HighScores::new(&[]); | ||
| 67 | assert!(high_scores.personal_top_three().is_empty()); | ||
| 68 | } | ||
