Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust high scores #259

Merged
merged 2 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ members = [
"./grains",
"./health-statistics",
"./hello-world",
"./high-scores",
"./isogram",
"./leap",
"./lucians-luscious-lasagna",
Expand Down
1 change: 1 addition & 0 deletions rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@
- [series](./series/README.md)
- [bob](./bob/README.md)
- [all-your-base](./all-your-base/README.md)
- [high-scores](./high-scores/README.md)
25 changes: 25 additions & 0 deletions rust/high-scores/.exercism/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"authors": [
"Br1ght0ne"
],
"contributors": [
"coriolinus",
"cwhakes",
"efx",
"ErikSchierboom"
],
"files": {
"solution": [
"src/lib.rs",
"Cargo.toml"
],
"test": [
"tests/high-scores.rs"
],
"example": [
".meta/example.rs"
]
},
"blurb": "Manage a player's High Score list.",
"source": "Tribute to the eighties' arcade game Frogger"
}
1 change: 1 addition & 0 deletions rust/high-scores/.exercism/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"track":"rust","exercise":"high-scores","id":"31bde3893b1248e9abe1f08193de2103","url":"https://exercism.org/tracks/rust/exercises/high-scores","handle":"vpayno","is_requester":true,"auto_approve":false}
8 changes: 8 additions & 0 deletions rust/high-scores/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Generated by exercism rust track exercise tool
# will have compiled files and executables
/target/
**/*.rs.bk

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
Cargo.lock
4 changes: 4 additions & 0 deletions rust/high-scores/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[package]
edition = "2021"
name = "high-scores"
version = "1.0.0"
86 changes: 86 additions & 0 deletions rust/high-scores/HELP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Help

## Running the tests

Execute the tests with:

```bash
$ cargo test
```

All but the first test have been ignored. After you get the first test to
pass, open the tests source file which is located in the `tests` directory
and remove the `#[ignore]` flag from the next test and get the tests to pass
again. Each separate test is a function with `#[test]` flag above it.
Continue, until you pass every test.

If you wish to run _only ignored_ tests without editing the tests source file, use:

```bash
$ cargo test -- --ignored
```

If you are using Rust 1.51 or later, you can run _all_ tests with

```bash
$ cargo test -- --include-ignored
```

To run a specific test, for example `some_test`, you can use:

```bash
$ cargo test some_test
```

If the specific test is ignored, use:

```bash
$ cargo test some_test -- --ignored
```

To learn more about Rust tests refer to the online [test documentation][rust-tests].

[rust-tests]: https://doc.rust-lang.org/book/ch11-02-running-tests.html

## Submitting your solution

You can submit your solution using the `exercism submit src/lib.rs Cargo.toml` command.
This command will upload your solution to the Exercism website and print the solution page's URL.

It's possible to submit an incomplete solution which allows you to:

- See how others have completed the exercise
- Request help from a mentor

## Need to get help?

If you'd like help solving the exercise, check the following pages:

- The [Rust track's documentation](https://exercism.org/docs/tracks/rust)
- The [Rust track's programming category on the forum](https://forum.exercism.org/c/programming/rust)
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)

Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.

## Rust Installation

Refer to the [exercism help page][help-page] for Rust installation and learning
resources.

## Submitting the solution

Generally you should submit all files in which you implemented your solution (`src/lib.rs` in most cases). If you are using any external crates, please consider submitting the `Cargo.toml` file. This will make the review process faster and clearer.

## Feedback, Issues, Pull Requests

The GitHub [track repository][github] is the home for all of the Rust exercises. If you have feedback about an exercise, or want to help implement new exercises, head over there and create an issue. Members of the rust track team are happy to help!

If you want to know more about Exercism, take a look at the [contribution guide].

## Submitting Incomplete Solutions
It's possible to submit an incomplete solution so you can see how others have completed the exercise.

[help-page]: https://exercism.org/tracks/rust/learning
[github]: https://github.com/exercism/rust
[contribution guide]: https://exercism.org/docs/community/contributors
35 changes: 35 additions & 0 deletions rust/high-scores/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# High Scores

Welcome to High Scores on Exercism's Rust Track.
If you need help running the tests or submitting your code, check out `HELP.md`.

## Instructions

Manage a game player's High Score list.

Your task is to build a high-score component of the classic Frogger game, one of the highest selling and addictive games of all time, and a classic of the arcade era. Your task is to write methods that return the highest score from the list, the last added score and the three highest scores.

Consider retaining a reference to `scores` in the struct - copying is not
necessary. You will require some lifetime annotations, though.

## Source

### Created by

- @Br1ght0ne

### Contributed to by

- @coriolinus
- @cwhakes
- @efx
- @ErikSchierboom

### Based on

Tribute to the eighties' arcade game Frogger

### My Solution

- [my solution](./src/lib.rs)
- [run-tests](./run-tests-rust.txt)
89 changes: 89 additions & 0 deletions rust/high-scores/coverage-annotations.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
1| |use std::fmt::Debug;
2| |
3| 0|#[derive(Debug)]
------------------
| Unexecuted instantiation: <high_scores::HighScores as core::fmt::Debug>::fmt
------------------
| Unexecuted instantiation: <high_scores::HighScores as core::fmt::Debug>::fmt
------------------
4| |pub struct HighScores {
5| | scores: Vec<u32>,
6| |}
7| |
8| |impl HighScores {
9| 33| pub fn new(scores: &[u32]) -> Self {
10| 33| HighScores {
11| 33| scores: scores.to_vec(),
12| 33| }
13| 33| }
------------------
| Unexecuted instantiation: <high_scores::HighScores>::new
------------------
| <high_scores::HighScores>::new:
| 9| 33| pub fn new(scores: &[u32]) -> Self {
| 10| 33| HighScores {
| 11| 33| scores: scores.to_vec(),
| 12| 33| }
| 13| 33| }
------------------
14| |
15| 3| pub fn scores(&self) -> &[u32] {
16| 3| &self.scores
17| 3| }
------------------
| Unexecuted instantiation: <high_scores::HighScores>::scores
------------------
| <high_scores::HighScores>::scores:
| 15| 3| pub fn scores(&self) -> &[u32] {
| 16| 3| &self.scores
| 17| 3| }
------------------
18| |
19| 6| pub fn latest(&self) -> Option<u32> {
20| 6| self.scores.last().copied()
21| 6| }
------------------
| Unexecuted instantiation: <high_scores::HighScores>::latest
------------------
| <high_scores::HighScores>::latest:
| 19| 6| pub fn latest(&self) -> Option<u32> {
| 20| 6| self.scores.last().copied()
| 21| 6| }
------------------
22| |
23| 6| pub fn personal_best(&self) -> Option<u32> {
24| 6| self.scores.iter().max().copied()
25| 6| }
------------------
| Unexecuted instantiation: <high_scores::HighScores>::personal_best
------------------
| <high_scores::HighScores>::personal_best:
| 23| 6| pub fn personal_best(&self) -> Option<u32> {
| 24| 6| self.scores.iter().max().copied()
| 25| 6| }
------------------
26| |
27| 18| pub fn personal_top_three(&self) -> Vec<u32> {
28| 18| let mut top = self.scores.clone();
29| 18|
30| 189| top.sort_by(|a, b| b.cmp(a));
------------------
| Unexecuted instantiation: <high_scores::HighScores>::personal_top_three::{closure#0}
------------------
| <high_scores::HighScores>::personal_top_three::{closure#0}:
| 30| 189| top.sort_by(|a, b| b.cmp(a));
------------------
31| 18| top[0..top.len().min(3)].to_vec()
32| 18| }
------------------
| Unexecuted instantiation: <high_scores::HighScores>::personal_top_three
------------------
| <high_scores::HighScores>::personal_top_three:
| 27| 18| pub fn personal_top_three(&self) -> Vec<u32> {
| 28| 18| let mut top = self.scores.clone();
| 29| 18|
| 30| 18| top.sort_by(|a, b| b.cmp(a));
| 31| 18| top[0..top.len().min(3)].to_vec()
| 32| 18| }
------------------
33| |}
10 changes: 10 additions & 0 deletions rust/high-scores/coverage-missing-lines.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Running: cargo llvm-cov --no-clean --all-features --show-missing-lines

Filename Regions Missed Regions Cover Functions Missed Functions Executed Lines Missed Lines Cover Branches Missed Branches Cover
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/home/vpayno/git_vpayno/exercism-workspace/rust/high-scores/src/lib.rs 8 1 87.50% 7 1 85.71% 22 1 95.45% 0 0 -
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL 8 1 87.50% 7 1 85.71% 22 1 95.45% 0 0 -
Uncovered Lines:
/home/vpayno/git_vpayno/exercism-workspace/rust/high-scores/src/lib.rs: 3

57 changes: 57 additions & 0 deletions rust/high-scores/report.lcov
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
SF:/home/vpayno/git_vpayno/exercism-workspace/rust/high-scores/src/lib.rs
FN:15,_RNvMCscorwc19CMRv_11high_scoresNtB2_10HighScores6scores
FN:9,_RNvMCscorwc19CMRv_11high_scoresNtB2_10HighScores3new
FN:19,_RNvMCscorwc19CMRv_11high_scoresNtB2_10HighScores6latest
FN:30,_RNCNvMCscorwc19CMRv_11high_scoresNtB4_10HighScores18personal_top_three0B4_
FN:23,_RNvMCscorwc19CMRv_11high_scoresNtB2_10HighScores13personal_best
FN:3,_RNvXs_Cscorwc19CMRv_11high_scoresNtB4_10HighScoresNtNtCs8zepCCxJ8Q4_4core3fmt5Debug3fmt
FN:27,_RNvMCscorwc19CMRv_11high_scoresNtB2_10HighScores18personal_top_three
FN:15,_RNvMCsjNZkcr9m2Qz_11high_scoresNtB2_10HighScores6scores
FN:9,_RNvMCsjNZkcr9m2Qz_11high_scoresNtB2_10HighScores3new
FN:19,_RNvMCsjNZkcr9m2Qz_11high_scoresNtB2_10HighScores6latest
FN:30,_RNCNvMCsjNZkcr9m2Qz_11high_scoresNtB4_10HighScores18personal_top_three0B4_
FN:23,_RNvMCsjNZkcr9m2Qz_11high_scoresNtB2_10HighScores13personal_best
FN:3,_RNvXs_CsjNZkcr9m2Qz_11high_scoresNtB4_10HighScoresNtNtCs8zepCCxJ8Q4_4core3fmt5Debug3fmt
FN:27,_RNvMCsjNZkcr9m2Qz_11high_scoresNtB2_10HighScores18personal_top_three
FNDA:0,_RNvMCscorwc19CMRv_11high_scoresNtB2_10HighScores6scores
FNDA:0,_RNvMCscorwc19CMRv_11high_scoresNtB2_10HighScores3new
FNDA:0,_RNvMCscorwc19CMRv_11high_scoresNtB2_10HighScores6latest
FNDA:0,_RNCNvMCscorwc19CMRv_11high_scoresNtB4_10HighScores18personal_top_three0B4_
FNDA:0,_RNvMCscorwc19CMRv_11high_scoresNtB2_10HighScores13personal_best
FNDA:0,_RNvXs_Cscorwc19CMRv_11high_scoresNtB4_10HighScoresNtNtCs8zepCCxJ8Q4_4core3fmt5Debug3fmt
FNDA:0,_RNvMCscorwc19CMRv_11high_scoresNtB2_10HighScores18personal_top_three
FNDA:1,_RNvMCsjNZkcr9m2Qz_11high_scoresNtB2_10HighScores6scores
FNDA:11,_RNvMCsjNZkcr9m2Qz_11high_scoresNtB2_10HighScores3new
FNDA:2,_RNvMCsjNZkcr9m2Qz_11high_scoresNtB2_10HighScores6latest
FNDA:63,_RNCNvMCsjNZkcr9m2Qz_11high_scoresNtB4_10HighScores18personal_top_three0B4_
FNDA:2,_RNvMCsjNZkcr9m2Qz_11high_scoresNtB2_10HighScores13personal_best
FNDA:0,_RNvXs_CsjNZkcr9m2Qz_11high_scoresNtB4_10HighScoresNtNtCs8zepCCxJ8Q4_4core3fmt5Debug3fmt
FNDA:6,_RNvMCsjNZkcr9m2Qz_11high_scoresNtB2_10HighScores18personal_top_three
FNF:7
FNH:6
DA:3,0
DA:9,11
DA:10,11
DA:11,11
DA:12,11
DA:13,11
DA:15,1
DA:16,1
DA:17,1
DA:19,2
DA:20,2
DA:21,2
DA:23,2
DA:24,2
DA:25,2
DA:27,6
DA:28,6
DA:29,6
DA:30,63
DA:31,6
DA:32,6
BRF:0
BRH:0
LF:22
LH:21
end_of_record
Loading