aboutsummaryrefslogtreecommitdiff
path: root/high-scores/tests/high-scores.rs
diff options
context:
space:
mode:
authorFederico Igne <git@federicoigne.com>2020-07-09 17:51:00 +0200
committerFederico Igne <git@federicoigne.com>2021-11-03 18:55:08 +0000
commitb6a96e1bfe1a2e411a14fff13948236054a8cca5 (patch)
tree38079dbf70091a049b586b504c572bed43d78c33 /high-scores/tests/high-scores.rs
parent1bbdf8a1d5490737388d435831639938cec439e0 (diff)
downloadexercism-b6a96e1bfe1a2e411a14fff13948236054a8cca5.tar.gz
exercism-b6a96e1bfe1a2e411a14fff13948236054a8cca5.zip
[rust] High Score
Diffstat (limited to 'high-scores/tests/high-scores.rs')
-rw-r--r--high-scores/tests/high-scores.rs68
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 @@
1use high_scores::HighScores;
2
3#[test]
4fn 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]
11fn 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]
17fn test_latest_score_empty() {
18 let high_scores = HighScores::new(&[]);
19 assert_eq!(high_scores.latest(), None);
20}
21
22#[test]
23fn 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]
29fn test_personal_best_empty() {
30 let high_scores = HighScores::new(&[]);
31 assert_eq!(high_scores.personal_best(), None);
32}
33
34#[test]
35fn 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]
41fn 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]
47fn 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]
53fn 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]
59fn 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]
65fn test_personal_top_three_empty() {
66 let high_scores = HighScores::new(&[]);
67 assert!(high_scores.personal_top_three().is_empty());
68}