From 35f7225f85817212e419dff364023c824562628d Mon Sep 17 00:00:00 2001 From: Victor Payno Date: Mon, 18 Sep 2023 09:33:45 -0700 Subject: [PATCH 1/3] rust/scrabble-score: download exercise --- rust/scrabble-score/.exercism/config.json | 40 ++++++++++ rust/scrabble-score/.exercism/metadata.json | 1 + rust/scrabble-score/.gitignore | 8 ++ rust/scrabble-score/Cargo.toml | 4 + rust/scrabble-score/HELP.md | 86 +++++++++++++++++++++ rust/scrabble-score/README.md | 76 ++++++++++++++++++ rust/scrabble-score/src/lib.rs | 4 + rust/scrabble-score/tests/scrabble-score.rs | 74 ++++++++++++++++++ 8 files changed, 293 insertions(+) create mode 100644 rust/scrabble-score/.exercism/config.json create mode 100644 rust/scrabble-score/.exercism/metadata.json create mode 100644 rust/scrabble-score/.gitignore create mode 100644 rust/scrabble-score/Cargo.toml create mode 100644 rust/scrabble-score/HELP.md create mode 100644 rust/scrabble-score/README.md create mode 100644 rust/scrabble-score/src/lib.rs create mode 100644 rust/scrabble-score/tests/scrabble-score.rs diff --git a/rust/scrabble-score/.exercism/config.json b/rust/scrabble-score/.exercism/config.json new file mode 100644 index 00000000..4050334a --- /dev/null +++ b/rust/scrabble-score/.exercism/config.json @@ -0,0 +1,40 @@ +{ + "authors": [ + "IanWhitney" + ], + "contributors": [ + "ashleygwilliams", + "AvasDream", + "coriolinus", + "cwhakes", + "efx", + "ErikSchierboom", + "IanWhitney", + "juleskers", + "kotp", + "lutostag", + "mkantor", + "navossoc", + "nfiles", + "petertseng", + "rofrol", + "stringparser", + "xakon", + "ZapAnton" + ], + "files": { + "solution": [ + "src/lib.rs", + "Cargo.toml" + ], + "test": [ + "tests/scrabble-score.rs" + ], + "example": [ + ".meta/example.rs" + ] + }, + "blurb": "Given a word, compute the Scrabble score for that word.", + "source": "Inspired by the Extreme Startup game", + "source_url": "https://github.com/rchatley/extreme_startup" +} diff --git a/rust/scrabble-score/.exercism/metadata.json b/rust/scrabble-score/.exercism/metadata.json new file mode 100644 index 00000000..632c635d --- /dev/null +++ b/rust/scrabble-score/.exercism/metadata.json @@ -0,0 +1 @@ +{"track":"rust","exercise":"scrabble-score","id":"4cf847a06ce14af8a0e1f6061e332429","url":"https://exercism.org/tracks/rust/exercises/scrabble-score","handle":"vpayno","is_requester":true,"auto_approve":false} \ No newline at end of file diff --git a/rust/scrabble-score/.gitignore b/rust/scrabble-score/.gitignore new file mode 100644 index 00000000..db7f315c --- /dev/null +++ b/rust/scrabble-score/.gitignore @@ -0,0 +1,8 @@ +# Generated by Cargo +# 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 diff --git a/rust/scrabble-score/Cargo.toml b/rust/scrabble-score/Cargo.toml new file mode 100644 index 00000000..7de526ac --- /dev/null +++ b/rust/scrabble-score/Cargo.toml @@ -0,0 +1,4 @@ +[package] +edition = "2021" +name = "scrabble-score" +version = "1.1.0" diff --git a/rust/scrabble-score/HELP.md b/rust/scrabble-score/HELP.md new file mode 100644 index 00000000..67add768 --- /dev/null +++ b/rust/scrabble-score/HELP.md @@ -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 \ No newline at end of file diff --git a/rust/scrabble-score/README.md b/rust/scrabble-score/README.md new file mode 100644 index 00000000..943624f5 --- /dev/null +++ b/rust/scrabble-score/README.md @@ -0,0 +1,76 @@ +# Scrabble Score + +Welcome to Scrabble Score on Exercism's Rust Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## Instructions + +Given a word, compute the Scrabble score for that word. + +## Letter Values + +You'll need these: + +```text +Letter Value +A, E, I, O, U, L, N, R, S, T 1 +D, G 2 +B, C, M, P 3 +F, H, V, W, Y 4 +K 5 +J, X 8 +Q, Z 10 +``` + +## Examples + +"cabbage" should be scored as worth 14 points: + +- 3 points for C +- 1 point for A, twice +- 3 points for B, twice +- 2 points for G +- 1 point for E + +And to total: + +- `3 + 2*1 + 2*3 + 2 + 1` +- = `3 + 2 + 6 + 3` +- = `5 + 9` +- = 14 + +## Extensions + +- You can play a double or a triple letter. +- You can play a double or a triple word. + +## Source + +### Created by + +- @IanWhitney + +### Contributed to by + +- @ashleygwilliams +- @AvasDream +- @coriolinus +- @cwhakes +- @efx +- @ErikSchierboom +- @IanWhitney +- @juleskers +- @kotp +- @lutostag +- @mkantor +- @navossoc +- @nfiles +- @petertseng +- @rofrol +- @stringparser +- @xakon +- @ZapAnton + +### Based on + +Inspired by the Extreme Startup game - https://github.com/rchatley/extreme_startup \ No newline at end of file diff --git a/rust/scrabble-score/src/lib.rs b/rust/scrabble-score/src/lib.rs new file mode 100644 index 00000000..d875e197 --- /dev/null +++ b/rust/scrabble-score/src/lib.rs @@ -0,0 +1,4 @@ +/// Compute the Scrabble score for a word. +pub fn score(word: &str) -> u64 { + todo!("Score {word} in Scrabble."); +} diff --git a/rust/scrabble-score/tests/scrabble-score.rs b/rust/scrabble-score/tests/scrabble-score.rs new file mode 100644 index 00000000..ab7439a9 --- /dev/null +++ b/rust/scrabble-score/tests/scrabble-score.rs @@ -0,0 +1,74 @@ +use scrabble_score::*; + +#[test] +fn a_is_worth_one_point() { + assert_eq!(score("a"), 1); +} + +#[test] +#[ignore] +fn scoring_is_case_insensitive() { + assert_eq!(score("A"), 1); +} + +#[test] +#[ignore] +fn f_is_worth_four() { + assert_eq!(score("f"), 4); +} + +#[test] +#[ignore] +fn two_one_point_letters_make_a_two_point_word() { + assert_eq!(score("at"), 2); +} + +#[test] +#[ignore] +fn three_letter_word() { + assert_eq!(score("zoo"), 12); +} + +#[test] +#[ignore] +fn medium_word() { + assert_eq!(score("street"), 6); +} + +#[test] +#[ignore] +fn longer_words_with_valuable_letters() { + assert_eq!(score("quirky"), 22); +} + +#[test] +#[ignore] +fn long_mixed_case_word() { + assert_eq!(score("OxyphenButazone"), 41); +} + +#[test] +#[ignore] +fn non_english_scrabble_letters_do_not_score() { + assert_eq!(score("pinata"), 8, "'n' should score 1"); + assert_eq!(score("piñata"), 7, "'ñ' should score 0"); +} + +#[test] +#[ignore] +fn empty_words_are_worth_zero() { + assert_eq!(score(""), 0); +} + +#[test] +#[ignore] +fn all_letters_work() { + assert_eq!(score("abcdefghijklmnopqrstuvwxyz"), 87); +} + +#[test] +#[ignore] +fn german_letters_do_not_score() { + assert_eq!(score("STRASSE"), 7, "\"SS\" should score 2"); + assert_eq!(score("STRAßE"), 5, "'ß' should score 0"); +} From 56fb50bf40b08e713eafdb639b45981e1a1912e5 Mon Sep 17 00:00:00 2001 From: Victor Payno Date: Mon, 18 Sep 2023 09:54:41 -0700 Subject: [PATCH 2/3] rust/scrabble-score: 1st iteration --- rust/README.md | 1 + rust/scrabble-score/README.md | 7 +- rust/scrabble-score/coverage-annotations.txt | 61 +++ .../scrabble-score/coverage-missing-lines.txt | 8 + rust/scrabble-score/report.lcov | 29 ++ rust/scrabble-score/run-tests-rust.txt | 485 ++++++++++++++++++ rust/scrabble-score/src/lib.rs | 31 +- rust/scrabble-score/tests/scrabble-score.rs | 11 - 8 files changed, 620 insertions(+), 13 deletions(-) create mode 100644 rust/scrabble-score/coverage-annotations.txt create mode 100644 rust/scrabble-score/coverage-missing-lines.txt create mode 100644 rust/scrabble-score/report.lcov create mode 100644 rust/scrabble-score/run-tests-rust.txt diff --git a/rust/README.md b/rust/README.md index e42fba91..ed1f24cc 100644 --- a/rust/README.md +++ b/rust/README.md @@ -38,3 +38,4 @@ - [allergies](./allergies/README.md) - [difference-of-squares](./difference-of-squares/README.md) - [anagram](./anagram/README.md) +- [scrabble-score](./scrabble-score/README.md) diff --git a/rust/scrabble-score/README.md b/rust/scrabble-score/README.md index 943624f5..5a3072c3 100644 --- a/rust/scrabble-score/README.md +++ b/rust/scrabble-score/README.md @@ -73,4 +73,9 @@ And to total: ### Based on -Inspired by the Extreme Startup game - https://github.com/rchatley/extreme_startup \ No newline at end of file +Inspired by the Extreme Startup game - https://github.com/rchatley/extreme_startup + +### My Solution + +- [my solution](./src/lib.rs) +- [run-tests](./run-tests-rust.txt) diff --git a/rust/scrabble-score/coverage-annotations.txt b/rust/scrabble-score/coverage-annotations.txt new file mode 100644 index 00000000..f0e65b37 --- /dev/null +++ b/rust/scrabble-score/coverage-annotations.txt @@ -0,0 +1,61 @@ + 1| |/// Compute the Scrabble score for a word. + 2| | + 3| |/// Scores a scrabble word. + 4| |/// + 5| |/// ```rust + 6| |/// use scrabble_score::*; + 7| |/// + 8| |/// let want: u64 = 87; + 9| |/// let got: u64 = score("abcdefghijklmnopqrstuvwxyz"); + 10| |/// + 11| |/// assert_eq!(got, want); + 12| |/// ``` + 13| 42|pub fn score(word: &str) -> u64 { + 14| 42| let mut result: u64 = 0; + 15| 42| + 16| 42| let binding = word.to_lowercase(); + 17| 42| let letters: &str = binding.trim(); + 18| | + 19| 258| for letter in letters.chars() { + ^42 + 20| 258| result += match letter { + 21| 165| 'a' | 'e' | 'i' | 'o' | 'u' | 'l' | 'n' | 'r' | 's' | 't' => 1, + 22| 6| 'd' | 'g' => 2, + 23| 24| 'b' | 'c' | 'm' | 'p' => 3, + 24| 27| 'f' | 'h' | 'v' | 'w' | 'y' => 4, + 25| 6| 'k' => 5, + 26| 9| 'j' | 'x' => 8, + 27| 15| 'q' | 'z' => 10, + 28| 6| _ => 0, + 29| | }; + 30| | } + 31| | + 32| 42| result + 33| 42|} + ------------------ + | scrabble_score::score: + | 13| 42|pub fn score(word: &str) -> u64 { + | 14| 42| let mut result: u64 = 0; + | 15| 42| + | 16| 42| let binding = word.to_lowercase(); + | 17| 42| let letters: &str = binding.trim(); + | 18| | + | 19| 258| for letter in letters.chars() { + | ^42 + | 20| 258| result += match letter { + | 21| 165| 'a' | 'e' | 'i' | 'o' | 'u' | 'l' | 'n' | 'r' | 's' | 't' => 1, + | 22| 6| 'd' | 'g' => 2, + | 23| 24| 'b' | 'c' | 'm' | 'p' => 3, + | 24| 27| 'f' | 'h' | 'v' | 'w' | 'y' => 4, + | 25| 6| 'k' => 5, + | 26| 9| 'j' | 'x' => 8, + | 27| 15| 'q' | 'z' => 10, + | 28| 6| _ => 0, + | 29| | }; + | 30| | } + | 31| | + | 32| 42| result + | 33| 42|} + ------------------ + | Unexecuted instantiation: scrabble_score::score + ------------------ \ No newline at end of file diff --git a/rust/scrabble-score/coverage-missing-lines.txt b/rust/scrabble-score/coverage-missing-lines.txt new file mode 100644 index 00000000..d56b0276 --- /dev/null +++ b/rust/scrabble-score/coverage-missing-lines.txt @@ -0,0 +1,8 @@ +Running: cargo llvm-cov --no-clean --all-features --workspace --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/scrabble-score/src/lib.rs 13 0 100.00% 1 0 100.00% 17 0 100.00% 0 0 - +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +TOTAL 13 0 100.00% 1 0 100.00% 17 0 100.00% 0 0 - + diff --git a/rust/scrabble-score/report.lcov b/rust/scrabble-score/report.lcov new file mode 100644 index 00000000..5c3f1a58 --- /dev/null +++ b/rust/scrabble-score/report.lcov @@ -0,0 +1,29 @@ +SF:/home/vpayno/git_vpayno/exercism-workspace/rust/scrabble-score/src/lib.rs +FN:13,_RNvCsbE52QhvtJFr_14scrabble_score5score +FN:13,_RNvCsfA8C7faOhHu_14scrabble_score5score +FNDA:14,_RNvCsbE52QhvtJFr_14scrabble_score5score +FNDA:0,_RNvCsfA8C7faOhHu_14scrabble_score5score +FNF:1 +FNH:1 +DA:13,14 +DA:14,14 +DA:15,14 +DA:16,14 +DA:17,14 +DA:19,86 +DA:20,86 +DA:21,55 +DA:22,2 +DA:23,8 +DA:24,9 +DA:25,2 +DA:26,3 +DA:27,5 +DA:28,2 +DA:32,14 +DA:33,14 +BRF:0 +BRH:0 +LF:17 +LH:17 +end_of_record \ No newline at end of file diff --git a/rust/scrabble-score/run-tests-rust.txt b/rust/scrabble-score/run-tests-rust.txt new file mode 100644 index 00000000..19bb4c51 --- /dev/null +++ b/rust/scrabble-score/run-tests-rust.txt @@ -0,0 +1,485 @@ +Running automated test file(s): + + +=============================================================================== + +Running: ../../.github/citools/rust/rust-lint-check --release + +Running Rust Cargo Check + +Rust version: + + rustc 1.72.0 (5680fa18f 2023-08-23) + + + ============================================================================== + +Running: cargo clean + + +real 0m0.013s +user 0m0.007s +sys 0m0.006s + + + ============================================================================== + +Running: cargo check --future-incompat-report --release + + Checking scrabble-score v1.1.0 (/home/vpayno/git_vpayno/exercism-workspace/rust/scrabble-score) + Finished release [optimized] target(s) in 0.13s +note: 0 dependencies had future-incompatible warnings + +real 0m0.138s +user 0m0.025s +sys 0m0.028s + + + ============================================================================== + +Exit code: 0 + +real 0m0.168s +user 0m0.041s +sys 0m0.044s + +real 0m0.172s +user 0m0.044s +sys 0m0.046s + +=============================================================================== + +Running: ../../.github/citools/rust/rust-lint-clippy --release + +Running Rust Cargo Clippy + +Rust version: + + rustc 1.72.0 (5680fa18f 2023-08-23) + + + ============================================================================== + +Running: cargo clean + + +real 0m0.009s +user 0m0.005s +sys 0m0.003s + + + ============================================================================== + +Running: cargo clippy --release + + Checking scrabble-score v1.1.0 (/home/vpayno/git_vpayno/exercism-workspace/rust/scrabble-score) + Finished release [optimized] target(s) in 0.07s + +real 0m0.098s +user 0m0.045s +sys 0m0.053s + + + ============================================================================== + +Exit code: 0 + +real 0m0.118s +user 0m0.056s +sys 0m0.063s + +real 0m0.121s +user 0m0.056s +sys 0m0.065s + +=============================================================================== + +Running: ../../.github/citools/rust/rust-lint-audit +No deps found, skipping cargo audit. + +real 0m0.057s +user 0m0.026s +sys 0m0.032s + +real 0m0.059s +user 0m0.026s +sys 0m0.034s + +=============================================================================== + +rm -fv ./*.profraw ./*.profdata + +=============================================================================== + +Running: ../../.github/citools/rust/rust-test-with-tarpaulin + +Running Rust Tests With Tarpaulin + +Rust version: + + rustc 1.72.0 (5680fa18f 2023-08-23) + + + ============================================================================== + +Running: cargo clean + + +real 0m0.008s +user 0m0.006s +sys 0m0.002s + + + ============================================================================== + +Running: cargo test --all-features + + Compiling scrabble-score v1.1.0 (/home/vpayno/git_vpayno/exercism-workspace/rust/scrabble-score) + Finished test [unoptimized + debuginfo] target(s) in 0.30s + Running unittests src/lib.rs (target/debug/deps/scrabble_score-17e4a989f76efe6c) + +running 0 tests + +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + + Running tests/scrabble-score.rs (target/debug/deps/scrabble_score-a35cf42499fcd551) + +running 12 tests +test a_is_worth_one_point ... ok +test empty_words_are_worth_zero ... ok +test german_letters_do_not_score ... ok +test long_mixed_case_word ... ok +test longer_words_with_valuable_letters ... ok +test f_is_worth_four ... ok +test non_english_scrabble_letters_do_not_score ... ok +test medium_word ... ok +test three_letter_word ... ok +test scoring_is_case_insensitive ... ok +test two_one_point_letters_make_a_two_point_word ... ok +test all_letters_work ... ok + +test result: ok. 12 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + + Doc-tests scrabble-score + +running 1 test +test src/lib.rs - score (line 4) ... ok + +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.13s + + +real 0m0.466s +user 0m0.494s +sys 0m0.238s + + + ============================================================================== + +Running: cargo tarpaulin --release --timeout=300 + +Sep 18 09:54:18.484  INFO cargo_tarpaulin::config: Creating config +Sep 18 09:54:18.495  INFO cargo_tarpaulin: Running Tarpaulin +Sep 18 09:54:18.495  INFO cargo_tarpaulin: Building project +Sep 18 09:54:18.495  INFO cargo_tarpaulin::cargo: Cleaning project + Compiling scrabble-score v1.1.0 (/home/vpayno/git_vpayno/exercism-workspace/rust/scrabble-score) + Finished release [optimized] target(s) in 0.37s +Sep 18 09:54:18.905  INFO cargo_tarpaulin::process_handling::linux: Launching test +Sep 18 09:54:18.905  INFO cargo_tarpaulin::process_handling: running /home/vpayno/git_vpayno/exercism-workspace/rust/scrabble-score/target/release/deps/scrabble_score-3309945b89de8b75 + +running 0 tests + +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + +Sep 18 09:54:19.396  INFO cargo_tarpaulin::process_handling::linux: Launching test +Sep 18 09:54:19.396  INFO cargo_tarpaulin::process_handling: running /home/vpayno/git_vpayno/exercism-workspace/rust/scrabble-score/target/release/deps/scrabble_score-99f310b7d2d90a3d + +running 12 tests +test empty_words_are_worth_zero ... ok +test medium_word ... ok +test longer_words_with_valuable_letters ... ok +test long_mixed_case_word ... ok +test german_letters_do_not_score ... ok +test f_is_worth_four ... ok +test all_letters_work ... ok +test a_is_worth_one_point ... ok +test two_one_point_letters_make_a_two_point_word ... ok +test three_letter_word ... ok +test scoring_is_case_insensitive ... ok +test non_english_scrabble_letters_do_not_score ... ok + +test result: ok. 12 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.03s + +Sep 18 09:54:19.889  INFO cargo_tarpaulin::report: Coverage Results: +|| Uncovered Lines: +|| Tested/Total Lines: +|| src/lib.rs: 4/4 +|| +100.00% coverage, 4/4 lines covered + +real 0m1.419s +user 0m0.516s +sys 0m1.022s + + + ============================================================================== + +Exit code: 0 + +real 0m1.914s +user 0m1.022s +sys 0m1.278s + +real 0m1.918s +user 0m1.025s +sys 0m1.278s + +=============================================================================== + +Running: ../../.github/citools/rust/rust-test-with-llvm-coverage + +Running Rust Tests With LLVM Coverage + +Rust version: + + rustc 1.72.0 (5680fa18f 2023-08-23) + + + ============================================================================== + +Running: cargo clean + + +real 0m0.015s +user 0m0.005s +sys 0m0.009s + + + ============================================================================== + +Running: cargo llvm-cov clean --workspace + + +real 0m0.193s +user 0m0.104s +sys 0m0.091s + + + ============================================================================== + +Running: cargo test --all-features --doc + + Compiling scrabble-score v1.1.0 (/home/vpayno/git_vpayno/exercism-workspace/rust/scrabble-score) + Finished test [unoptimized + debuginfo] target(s) in 0.09s + Doc-tests scrabble-score + +running 1 test +test src/lib.rs - score (line 4) ... ok + +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.11s + + +real 0m0.227s +user 0m0.162s +sys 0m0.093s + + + ============================================================================== + +Running: cargo llvm-cov --no-clean --all-features --workspace + + Compiling scrabble-score v1.1.0 (/home/vpayno/git_vpayno/exercism-workspace/rust/scrabble-score) + Finished test [unoptimized + debuginfo] target(s) in 0.30s + Running unittests src/lib.rs (target/llvm-cov-target/debug/deps/scrabble_score-e79c80208243ac63) + +running 0 tests + +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + + Running tests/scrabble-score.rs (target/llvm-cov-target/debug/deps/scrabble_score-ab55caec03cf22f9) + +running 12 tests +test a_is_worth_one_point ... ok +test all_letters_work ... ok +test empty_words_are_worth_zero ... ok +test f_is_worth_four ... ok +test german_letters_do_not_score ... ok +test long_mixed_case_word ... ok +test longer_words_with_valuable_letters ... ok +test medium_word ... ok +test non_english_scrabble_letters_do_not_score ... ok +test scoring_is_case_insensitive ... ok +test three_letter_word ... ok +test two_one_point_letters_make_a_two_point_word ... ok + +test result: ok. 12 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + +Filename Regions Missed Regions Cover Functions Missed Functions Executed Lines Missed Lines Cover Branches Missed Branches Cover +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +/home/vpayno/git_vpayno/exercism-workspace/rust/scrabble-score/src/lib.rs 13 0 100.00% 1 0 100.00% 17 0 100.00% 0 0 - +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +TOTAL 13 0 100.00% 1 0 100.00% 17 0 100.00% 0 0 - + +real 0m0.455s +user 0m0.358s +sys 0m0.189s + + + ============================================================================== + +Running: cargo llvm-cov report --lcov --output-path report.lcov + + + Finished report saved to report.lcov + +real 0m0.130s +user 0m0.064s +sys 0m0.066s + + Finished test [unoptimized + debuginfo] target(s) in 0.00s + Running unittests src/lib.rs (target/llvm-cov-target/debug/deps/scrabble_score-e79c80208243ac63) + +running 0 tests + +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + + Running tests/scrabble-score.rs (target/llvm-cov-target/debug/deps/scrabble_score-ab55caec03cf22f9) + +running 12 tests +test a_is_worth_one_point ... ok +test all_letters_work ... ok +test empty_words_are_worth_zero ... ok +test f_is_worth_four ... ok +test german_letters_do_not_score ... ok +test long_mixed_case_word ... ok +test longer_words_with_valuable_letters ... ok +test medium_word ... ok +test non_english_scrabble_letters_do_not_score ... ok +test scoring_is_case_insensitive ... ok +test three_letter_word ... ok +test two_one_point_letters_make_a_two_point_word ... ok + +test result: ok. 12 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + + +real 0m0.157s +user 0m0.076s +sys 0m0.081s + + ============================================================================== + +Running: cargo llvm-cov --no-clean --all-features --workspace --text --output-path=coverage-annotations.txt + + Finished test [unoptimized + debuginfo] target(s) in 0.00s + Running unittests src/lib.rs (target/llvm-cov-target/debug/deps/scrabble_score-e79c80208243ac63) + +running 0 tests + +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + + Running tests/scrabble-score.rs (target/llvm-cov-target/debug/deps/scrabble_score-ab55caec03cf22f9) + +running 12 tests +test a_is_worth_one_point ... ok +test all_letters_work ... ok +test empty_words_are_worth_zero ... ok +test f_is_worth_four ... ok +test german_letters_do_not_score ... ok +test long_mixed_case_word ... ok +test longer_words_with_valuable_letters ... ok +test medium_word ... ok +test non_english_scrabble_letters_do_not_score ... ok +test scoring_is_case_insensitive ... ok +test three_letter_word ... ok +test two_one_point_letters_make_a_two_point_word ... ok + +test result: ok. 12 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + + + Finished report saved to coverage-annotations.txt + +real 0m0.165s +user 0m0.075s +sys 0m0.094s + + + ============================================================================== + +Running: cargo llvm-cov clean --workspace + + +real 0m0.127s +user 0m0.063s +sys 0m0.067s + + + ============================================================================== + +Running: lcov --list report.lcov + +Reading tracefile report.lcov + |Lines |Functions |Branches +Filename |Rate Num|Rate Num|Rate Num +================================================== +[/home/vpayno/git_vpayno/exercism-workspace/rust/scrabble-score/src/] +lib.rs | 100% 17|50.0% 2| - 0 +================================================== + Total:| 100% 17|50.0% 2| - 0 + +real 0m0.037s +user 0m0.033s +sys 0m0.004s + + +Running: lcov --summary report.lcov + +Reading tracefile report.lcov +Summary coverage rate: + lines......: 100.0% (17 of 17 lines) + functions..: 50.0% (1 of 2 functions) + branches...: no data found + +real 0m0.035s +user 0m0.032s +sys 0m0.003s + + + ============================================================================== + +Exit code: 0 + +real 0m1.555s +user 0m0.981s +sys 0m0.703s + +real 0m1.556s +user 0m0.981s +sys 0m0.704s + +=============================================================================== + +Running: misspell . + +real 0m0.024s +user 0m0.028s +sys 0m0.012s + +=============================================================================== + +Running: cargo doc + Documenting scrabble-score v1.1.0 (/home/vpayno/git_vpayno/exercism-workspace/rust/scrabble-score) + Finished dev [unoptimized + debuginfo] target(s) in 0.19s + +real 0m0.203s +user 0m0.167s +sys 0m0.037s + +=============================================================================== + +Running: cargo clean + +real 0m0.010s +user 0m0.007s +sys 0m0.004s + +=============================================================================== + diff --git a/rust/scrabble-score/src/lib.rs b/rust/scrabble-score/src/lib.rs index d875e197..414041d1 100644 --- a/rust/scrabble-score/src/lib.rs +++ b/rust/scrabble-score/src/lib.rs @@ -1,4 +1,33 @@ /// Compute the Scrabble score for a word. + +/// Scores a scrabble word. +/// +/// ```rust +/// use scrabble_score::*; +/// +/// let want: u64 = 87; +/// let got: u64 = score("abcdefghijklmnopqrstuvwxyz"); +/// +/// assert_eq!(got, want); +/// ``` pub fn score(word: &str) -> u64 { - todo!("Score {word} in Scrabble."); + let mut result: u64 = 0; + + let binding = word.to_lowercase(); + let letters: &str = binding.trim(); + + for letter in letters.chars() { + result += match letter { + 'a' | 'e' | 'i' | 'o' | 'u' | 'l' | 'n' | 'r' | 's' | 't' => 1, + 'd' | 'g' => 2, + 'b' | 'c' | 'm' | 'p' => 3, + 'f' | 'h' | 'v' | 'w' | 'y' => 4, + 'k' => 5, + 'j' | 'x' => 8, + 'q' | 'z' => 10, + _ => 0, + }; + } + + result } diff --git a/rust/scrabble-score/tests/scrabble-score.rs b/rust/scrabble-score/tests/scrabble-score.rs index ab7439a9..8d6348a0 100644 --- a/rust/scrabble-score/tests/scrabble-score.rs +++ b/rust/scrabble-score/tests/scrabble-score.rs @@ -6,68 +6,57 @@ fn a_is_worth_one_point() { } #[test] -#[ignore] fn scoring_is_case_insensitive() { assert_eq!(score("A"), 1); } #[test] -#[ignore] fn f_is_worth_four() { assert_eq!(score("f"), 4); } #[test] -#[ignore] fn two_one_point_letters_make_a_two_point_word() { assert_eq!(score("at"), 2); } #[test] -#[ignore] fn three_letter_word() { assert_eq!(score("zoo"), 12); } #[test] -#[ignore] fn medium_word() { assert_eq!(score("street"), 6); } #[test] -#[ignore] fn longer_words_with_valuable_letters() { assert_eq!(score("quirky"), 22); } #[test] -#[ignore] fn long_mixed_case_word() { assert_eq!(score("OxyphenButazone"), 41); } #[test] -#[ignore] fn non_english_scrabble_letters_do_not_score() { assert_eq!(score("pinata"), 8, "'n' should score 1"); assert_eq!(score("piñata"), 7, "'ñ' should score 0"); } #[test] -#[ignore] fn empty_words_are_worth_zero() { assert_eq!(score(""), 0); } #[test] -#[ignore] fn all_letters_work() { assert_eq!(score("abcdefghijklmnopqrstuvwxyz"), 87); } #[test] -#[ignore] fn german_letters_do_not_score() { assert_eq!(score("STRASSE"), 7, "\"SS\" should score 2"); assert_eq!(score("STRAßE"), 5, "'ß' should score 0"); From 03a3fc4de3532777e30406fdf2f5c4152792bb1a Mon Sep 17 00:00:00 2001 From: Victor Payno Date: Mon, 18 Sep 2023 09:58:58 -0700 Subject: [PATCH 3/3] rust/scrabble-score: 2nd iteration --- rust/scrabble-score/coverage-annotations.txt | 87 +++---- .../scrabble-score/coverage-missing-lines.txt | 4 +- rust/scrabble-score/report.lcov | 33 +-- rust/scrabble-score/run-tests-rust.txt | 220 +++++++++--------- rust/scrabble-score/src/lib.rs | 17 +- 5 files changed, 181 insertions(+), 180 deletions(-) diff --git a/rust/scrabble-score/coverage-annotations.txt b/rust/scrabble-score/coverage-annotations.txt index f0e65b37..ccb21edb 100644 --- a/rust/scrabble-score/coverage-annotations.txt +++ b/rust/scrabble-score/coverage-annotations.txt @@ -11,51 +11,54 @@ 11| |/// assert_eq!(got, want); 12| |/// ``` 13| 42|pub fn score(word: &str) -> u64 { - 14| 42| let mut result: u64 = 0; - 15| 42| - 16| 42| let binding = word.to_lowercase(); - 17| 42| let letters: &str = binding.trim(); - 18| | - 19| 258| for letter in letters.chars() { - ^42 - 20| 258| result += match letter { - 21| 165| 'a' | 'e' | 'i' | 'o' | 'u' | 'l' | 'n' | 'r' | 's' | 't' => 1, - 22| 6| 'd' | 'g' => 2, - 23| 24| 'b' | 'c' | 'm' | 'p' => 3, - 24| 27| 'f' | 'h' | 'v' | 'w' | 'y' => 4, - 25| 6| 'k' => 5, - 26| 9| 'j' | 'x' => 8, - 27| 15| 'q' | 'z' => 10, - 28| 6| _ => 0, - 29| | }; - 30| | } - 31| | - 32| 42| result - 33| 42|} + 14| 42| word.to_lowercase() + 15| 42| .trim() + 16| 42| .chars() + 17| 258| .map(|c| match c { + 18| 165| 'a' | 'e' | 'i' | 'o' | 'u' | 'l' | 'n' | 'r' | 's' | 't' => 1, + 19| 6| 'd' | 'g' => 2, + 20| 24| 'b' | 'c' | 'm' | 'p' => 3, + 21| 27| 'f' | 'h' | 'v' | 'w' | 'y' => 4, + 22| 6| 'k' => 5, + 23| 9| 'j' | 'x' => 8, + 24| 15| 'q' | 'z' => 10, + 25| 6| _ => 0, + 26| 258| }) + ------------------ + | scrabble_score::score::{closure#0}: + | 17| 258| .map(|c| match c { + | 18| 165| 'a' | 'e' | 'i' | 'o' | 'u' | 'l' | 'n' | 'r' | 's' | 't' => 1, + | 19| 6| 'd' | 'g' => 2, + | 20| 24| 'b' | 'c' | 'm' | 'p' => 3, + | 21| 27| 'f' | 'h' | 'v' | 'w' | 'y' => 4, + | 22| 6| 'k' => 5, + | 23| 9| 'j' | 'x' => 8, + | 24| 15| 'q' | 'z' => 10, + | 25| 6| _ => 0, + | 26| 258| }) + ------------------ + | Unexecuted instantiation: scrabble_score::score::{closure#0} + ------------------ + 27| 42| .sum() + 28| 42|} ------------------ | scrabble_score::score: | 13| 42|pub fn score(word: &str) -> u64 { - | 14| 42| let mut result: u64 = 0; - | 15| 42| - | 16| 42| let binding = word.to_lowercase(); - | 17| 42| let letters: &str = binding.trim(); - | 18| | - | 19| 258| for letter in letters.chars() { - | ^42 - | 20| 258| result += match letter { - | 21| 165| 'a' | 'e' | 'i' | 'o' | 'u' | 'l' | 'n' | 'r' | 's' | 't' => 1, - | 22| 6| 'd' | 'g' => 2, - | 23| 24| 'b' | 'c' | 'm' | 'p' => 3, - | 24| 27| 'f' | 'h' | 'v' | 'w' | 'y' => 4, - | 25| 6| 'k' => 5, - | 26| 9| 'j' | 'x' => 8, - | 27| 15| 'q' | 'z' => 10, - | 28| 6| _ => 0, - | 29| | }; - | 30| | } - | 31| | - | 32| 42| result - | 33| 42|} + | 14| 42| word.to_lowercase() + | 15| 42| .trim() + | 16| 42| .chars() + | 17| 42| .map(|c| match c { + | 18| | 'a' | 'e' | 'i' | 'o' | 'u' | 'l' | 'n' | 'r' | 's' | 't' => 1, + | 19| | 'd' | 'g' => 2, + | 20| | 'b' | 'c' | 'm' | 'p' => 3, + | 21| | 'f' | 'h' | 'v' | 'w' | 'y' => 4, + | 22| | 'k' => 5, + | 23| | 'j' | 'x' => 8, + | 24| | 'q' | 'z' => 10, + | 25| | _ => 0, + | 26| 42| }) + | 27| 42| .sum() + | 28| 42|} ------------------ | Unexecuted instantiation: scrabble_score::score ------------------ \ No newline at end of file diff --git a/rust/scrabble-score/coverage-missing-lines.txt b/rust/scrabble-score/coverage-missing-lines.txt index d56b0276..46d54138 100644 --- a/rust/scrabble-score/coverage-missing-lines.txt +++ b/rust/scrabble-score/coverage-missing-lines.txt @@ -2,7 +2,7 @@ Running: cargo llvm-cov --no-clean --all-features --workspace --show-missing-lin Filename Regions Missed Regions Cover Functions Missed Functions Executed Lines Missed Lines Cover Branches Missed Branches Cover ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -/home/vpayno/git_vpayno/exercism-workspace/rust/scrabble-score/src/lib.rs 13 0 100.00% 1 0 100.00% 17 0 100.00% 0 0 - +/home/vpayno/git_vpayno/exercism-workspace/rust/scrabble-score/src/lib.rs 12 0 100.00% 2 0 100.00% 18 0 100.00% 0 0 - ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -TOTAL 13 0 100.00% 1 0 100.00% 17 0 100.00% 0 0 - +TOTAL 12 0 100.00% 2 0 100.00% 18 0 100.00% 0 0 - diff --git a/rust/scrabble-score/report.lcov b/rust/scrabble-score/report.lcov index 5c3f1a58..873e7e05 100644 --- a/rust/scrabble-score/report.lcov +++ b/rust/scrabble-score/report.lcov @@ -1,29 +1,32 @@ SF:/home/vpayno/git_vpayno/exercism-workspace/rust/scrabble-score/src/lib.rs +FN:17,_RNCNvCsbE52QhvtJFr_14scrabble_score5score0B3_ FN:13,_RNvCsbE52QhvtJFr_14scrabble_score5score +FN:17,_RNCNvCsfA8C7faOhHu_14scrabble_score5score0B3_ FN:13,_RNvCsfA8C7faOhHu_14scrabble_score5score +FNDA:86,_RNCNvCsbE52QhvtJFr_14scrabble_score5score0B3_ FNDA:14,_RNvCsbE52QhvtJFr_14scrabble_score5score +FNDA:0,_RNCNvCsfA8C7faOhHu_14scrabble_score5score0B3_ FNDA:0,_RNvCsfA8C7faOhHu_14scrabble_score5score -FNF:1 -FNH:1 +FNF:2 +FNH:2 DA:13,14 DA:14,14 DA:15,14 DA:16,14 -DA:17,14 -DA:19,86 -DA:20,86 -DA:21,55 +DA:17,86 +DA:18,55 +DA:19,2 +DA:20,8 +DA:21,9 DA:22,2 -DA:23,8 -DA:24,9 +DA:23,3 +DA:24,5 DA:25,2 -DA:26,3 -DA:27,5 -DA:28,2 -DA:32,14 -DA:33,14 +DA:26,86 +DA:27,14 +DA:28,14 BRF:0 BRH:0 -LF:17 -LH:17 +LF:18 +LH:18 end_of_record \ No newline at end of file diff --git a/rust/scrabble-score/run-tests-rust.txt b/rust/scrabble-score/run-tests-rust.txt index 19bb4c51..8e51c7a4 100644 --- a/rust/scrabble-score/run-tests-rust.txt +++ b/rust/scrabble-score/run-tests-rust.txt @@ -17,9 +17,9 @@ Rust version: Running: cargo clean -real 0m0.013s +real 0m0.015s user 0m0.007s -sys 0m0.006s +sys 0m0.008s ============================================================================== @@ -27,26 +27,26 @@ sys 0m0.006s Running: cargo check --future-incompat-report --release Checking scrabble-score v1.1.0 (/home/vpayno/git_vpayno/exercism-workspace/rust/scrabble-score) - Finished release [optimized] target(s) in 0.13s + Finished release [optimized] target(s) in 0.10s note: 0 dependencies had future-incompatible warnings -real 0m0.138s -user 0m0.025s -sys 0m0.028s +real 0m0.113s +user 0m0.028s +sys 0m0.026s ============================================================================== Exit code: 0 -real 0m0.168s +real 0m0.146s user 0m0.041s -sys 0m0.044s - -real 0m0.172s -user 0m0.044s sys 0m0.046s +real 0m0.149s +user 0m0.043s +sys 0m0.047s + =============================================================================== Running: ../../.github/citools/rust/rust-lint-clippy --release @@ -65,7 +65,7 @@ Running: cargo clean real 0m0.009s user 0m0.005s -sys 0m0.003s +sys 0m0.004s ============================================================================== @@ -73,37 +73,37 @@ sys 0m0.003s Running: cargo clippy --release Checking scrabble-score v1.1.0 (/home/vpayno/git_vpayno/exercism-workspace/rust/scrabble-score) - Finished release [optimized] target(s) in 0.07s + Finished release [optimized] target(s) in 0.06s -real 0m0.098s +real 0m0.093s user 0m0.045s -sys 0m0.053s +sys 0m0.047s ============================================================================== Exit code: 0 -real 0m0.118s -user 0m0.056s -sys 0m0.063s +real 0m0.119s +user 0m0.055s +sys 0m0.064s -real 0m0.121s +real 0m0.120s user 0m0.056s -sys 0m0.065s +sys 0m0.064s =============================================================================== Running: ../../.github/citools/rust/rust-lint-audit No deps found, skipping cargo audit. -real 0m0.057s -user 0m0.026s -sys 0m0.032s +real 0m0.044s +user 0m0.020s +sys 0m0.025s -real 0m0.059s -user 0m0.026s -sys 0m0.034s +real 0m0.045s +user 0m0.021s +sys 0m0.025s =============================================================================== @@ -125,9 +125,9 @@ Rust version: Running: cargo clean -real 0m0.008s -user 0m0.006s -sys 0m0.002s +real 0m0.010s +user 0m0.007s +sys 0m0.003s ============================================================================== @@ -135,7 +135,7 @@ sys 0m0.002s Running: cargo test --all-features Compiling scrabble-score v1.1.0 (/home/vpayno/git_vpayno/exercism-workspace/rust/scrabble-score) - Finished test [unoptimized + debuginfo] target(s) in 0.30s + Finished test [unoptimized + debuginfo] target(s) in 0.31s Running unittests src/lib.rs (target/debug/deps/scrabble_score-17e4a989f76efe6c) running 0 tests @@ -146,17 +146,17 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; fini running 12 tests test a_is_worth_one_point ... ok +test all_letters_work ... ok test empty_words_are_worth_zero ... ok +test f_is_worth_four ... ok test german_letters_do_not_score ... ok test long_mixed_case_word ... ok +test medium_word ... ok test longer_words_with_valuable_letters ... ok -test f_is_worth_four ... ok test non_english_scrabble_letters_do_not_score ... ok -test medium_word ... ok test three_letter_word ... ok -test scoring_is_case_insensitive ... ok test two_one_point_letters_make_a_two_point_word ... ok -test all_letters_work ... ok +test scoring_is_case_insensitive ... ok test result: ok. 12 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s @@ -168,30 +168,30 @@ test src/lib.rs - score (line 4) ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.13s -real 0m0.466s -user 0m0.494s -sys 0m0.238s +real 0m0.473s +user 0m0.473s +sys 0m0.253s ============================================================================== Running: cargo tarpaulin --release --timeout=300 -Sep 18 09:54:18.484  INFO cargo_tarpaulin::config: Creating config -Sep 18 09:54:18.495  INFO cargo_tarpaulin: Running Tarpaulin -Sep 18 09:54:18.495  INFO cargo_tarpaulin: Building project -Sep 18 09:54:18.495  INFO cargo_tarpaulin::cargo: Cleaning project +Sep 18 09:58:39.686  INFO cargo_tarpaulin::config: Creating config +Sep 18 09:58:39.697  INFO cargo_tarpaulin: Running Tarpaulin +Sep 18 09:58:39.697  INFO cargo_tarpaulin: Building project +Sep 18 09:58:39.697  INFO cargo_tarpaulin::cargo: Cleaning project Compiling scrabble-score v1.1.0 (/home/vpayno/git_vpayno/exercism-workspace/rust/scrabble-score) - Finished release [optimized] target(s) in 0.37s -Sep 18 09:54:18.905  INFO cargo_tarpaulin::process_handling::linux: Launching test -Sep 18 09:54:18.905  INFO cargo_tarpaulin::process_handling: running /home/vpayno/git_vpayno/exercism-workspace/rust/scrabble-score/target/release/deps/scrabble_score-3309945b89de8b75 + Finished release [optimized] target(s) in 0.38s +Sep 18 09:58:40.124  INFO cargo_tarpaulin::process_handling::linux: Launching test +Sep 18 09:58:40.124  INFO cargo_tarpaulin::process_handling: running /home/vpayno/git_vpayno/exercism-workspace/rust/scrabble-score/target/release/deps/scrabble_score-3309945b89de8b75 running 0 tests test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s -Sep 18 09:54:19.396  INFO cargo_tarpaulin::process_handling::linux: Launching test -Sep 18 09:54:19.396  INFO cargo_tarpaulin::process_handling: running /home/vpayno/git_vpayno/exercism-workspace/rust/scrabble-score/target/release/deps/scrabble_score-99f310b7d2d90a3d +Sep 18 09:58:40.569  INFO cargo_tarpaulin::process_handling::linux: Launching test +Sep 18 09:58:40.569  INFO cargo_tarpaulin::process_handling: running /home/vpayno/git_vpayno/exercism-workspace/rust/scrabble-score/target/release/deps/scrabble_score-99f310b7d2d90a3d running 12 tests test empty_words_are_worth_zero ... ok @@ -201,37 +201,37 @@ test long_mixed_case_word ... ok test german_letters_do_not_score ... ok test f_is_worth_four ... ok test all_letters_work ... ok -test a_is_worth_one_point ... ok test two_one_point_letters_make_a_two_point_word ... ok test three_letter_word ... ok +test a_is_worth_one_point ... ok test scoring_is_case_insensitive ... ok test non_english_scrabble_letters_do_not_score ... ok -test result: ok. 12 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.03s +test result: ok. 12 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.02s -Sep 18 09:54:19.889  INFO cargo_tarpaulin::report: Coverage Results: +Sep 18 09:58:41.041  INFO cargo_tarpaulin::report: Coverage Results: || Uncovered Lines: || Tested/Total Lines: -|| src/lib.rs: 4/4 +|| src/lib.rs: 3/3 || -100.00% coverage, 4/4 lines covered +100.00% coverage, 3/3 lines covered -real 0m1.419s -user 0m0.516s -sys 0m1.022s +real 0m1.372s +user 0m0.506s +sys 0m0.969s ============================================================================== Exit code: 0 -real 0m1.914s -user 0m1.022s -sys 0m1.278s +real 0m1.868s +user 0m0.993s +sys 0m1.233s -real 0m1.918s -user 0m1.025s -sys 0m1.278s +real 0m1.870s +user 0m0.994s +sys 0m1.234s =============================================================================== @@ -249,8 +249,8 @@ Rust version: Running: cargo clean -real 0m0.015s -user 0m0.005s +real 0m0.013s +user 0m0.004s sys 0m0.009s @@ -259,9 +259,9 @@ sys 0m0.009s Running: cargo llvm-cov clean --workspace -real 0m0.193s -user 0m0.104s -sys 0m0.091s +real 0m0.189s +user 0m0.098s +sys 0m0.094s ============================================================================== @@ -269,7 +269,7 @@ sys 0m0.091s Running: cargo test --all-features --doc Compiling scrabble-score v1.1.0 (/home/vpayno/git_vpayno/exercism-workspace/rust/scrabble-score) - Finished test [unoptimized + debuginfo] target(s) in 0.09s + Finished test [unoptimized + debuginfo] target(s) in 0.12s Doc-tests scrabble-score running 1 test @@ -278,9 +278,9 @@ test src/lib.rs - score (line 4) ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.11s -real 0m0.227s -user 0m0.162s -sys 0m0.093s +real 0m0.259s +user 0m0.172s +sys 0m0.125s ============================================================================== @@ -288,7 +288,7 @@ sys 0m0.093s Running: cargo llvm-cov --no-clean --all-features --workspace Compiling scrabble-score v1.1.0 (/home/vpayno/git_vpayno/exercism-workspace/rust/scrabble-score) - Finished test [unoptimized + debuginfo] target(s) in 0.30s + Finished test [unoptimized + debuginfo] target(s) in 0.31s Running unittests src/lib.rs (target/llvm-cov-target/debug/deps/scrabble_score-e79c80208243ac63) running 0 tests @@ -315,13 +315,13 @@ test result: ok. 12 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; fin Filename Regions Missed Regions Cover Functions Missed Functions Executed Lines Missed Lines Cover Branches Missed Branches Cover ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -/home/vpayno/git_vpayno/exercism-workspace/rust/scrabble-score/src/lib.rs 13 0 100.00% 1 0 100.00% 17 0 100.00% 0 0 - +/home/vpayno/git_vpayno/exercism-workspace/rust/scrabble-score/src/lib.rs 12 0 100.00% 2 0 100.00% 18 0 100.00% 0 0 - ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -TOTAL 13 0 100.00% 1 0 100.00% 17 0 100.00% 0 0 - +TOTAL 12 0 100.00% 2 0 100.00% 18 0 100.00% 0 0 - -real 0m0.455s -user 0m0.358s -sys 0m0.189s +real 0m0.447s +user 0m0.349s +sys 0m0.187s ============================================================================== @@ -331,9 +331,9 @@ Running: cargo llvm-cov report --lcov --output-path report.lcov Finished report saved to report.lcov -real 0m0.130s -user 0m0.064s -sys 0m0.066s +real 0m0.125s +user 0m0.069s +sys 0m0.057s Finished test [unoptimized + debuginfo] target(s) in 0.00s Running unittests src/lib.rs (target/llvm-cov-target/debug/deps/scrabble_score-e79c80208243ac63) @@ -361,9 +361,9 @@ test two_one_point_letters_make_a_two_point_word ... ok test result: ok. 12 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s -real 0m0.157s -user 0m0.076s -sys 0m0.081s +real 0m0.172s +user 0m0.097s +sys 0m0.076s ============================================================================== @@ -397,9 +397,9 @@ test result: ok. 12 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; fin Finished report saved to coverage-annotations.txt -real 0m0.165s -user 0m0.075s -sys 0m0.094s +real 0m0.156s +user 0m0.084s +sys 0m0.073s ============================================================================== @@ -407,9 +407,9 @@ sys 0m0.094s Running: cargo llvm-cov clean --workspace -real 0m0.127s -user 0m0.063s -sys 0m0.067s +real 0m0.141s +user 0m0.082s +sys 0m0.061s ============================================================================== @@ -421,47 +421,47 @@ Reading tracefile report.lcov Filename |Rate Num|Rate Num|Rate Num ================================================== [/home/vpayno/git_vpayno/exercism-workspace/rust/scrabble-score/src/] -lib.rs | 100% 17|50.0% 2| - 0 +lib.rs | 100% 16|50.0% 4| - 0 ================================================== - Total:| 100% 17|50.0% 2| - 0 + Total:| 100% 16|50.0% 4| - 0 -real 0m0.037s -user 0m0.033s -sys 0m0.004s +real 0m0.036s +user 0m0.030s +sys 0m0.005s Running: lcov --summary report.lcov Reading tracefile report.lcov Summary coverage rate: - lines......: 100.0% (17 of 17 lines) - functions..: 50.0% (1 of 2 functions) + lines......: 100.0% (16 of 16 lines) + functions..: 50.0% (2 of 4 functions) branches...: no data found -real 0m0.035s -user 0m0.032s -sys 0m0.003s +real 0m0.033s +user 0m0.030s +sys 0m0.004s ============================================================================== Exit code: 0 -real 0m1.555s -user 0m0.981s -sys 0m0.703s +real 0m1.584s +user 0m1.020s +sys 0m0.698s -real 0m1.556s -user 0m0.981s -sys 0m0.704s +real 0m1.586s +user 0m1.021s +sys 0m0.699s =============================================================================== Running: misspell . -real 0m0.024s -user 0m0.028s -sys 0m0.012s +real 0m0.026s +user 0m0.036s +sys 0m0.014s =============================================================================== @@ -469,9 +469,9 @@ Running: cargo doc Documenting scrabble-score v1.1.0 (/home/vpayno/git_vpayno/exercism-workspace/rust/scrabble-score) Finished dev [unoptimized + debuginfo] target(s) in 0.19s -real 0m0.203s -user 0m0.167s -sys 0m0.037s +real 0m0.198s +user 0m0.152s +sys 0m0.047s =============================================================================== @@ -479,7 +479,7 @@ Running: cargo clean real 0m0.010s user 0m0.007s -sys 0m0.004s +sys 0m0.002s =============================================================================== diff --git a/rust/scrabble-score/src/lib.rs b/rust/scrabble-score/src/lib.rs index 414041d1..8750385d 100644 --- a/rust/scrabble-score/src/lib.rs +++ b/rust/scrabble-score/src/lib.rs @@ -11,13 +11,10 @@ /// assert_eq!(got, want); /// ``` pub fn score(word: &str) -> u64 { - let mut result: u64 = 0; - - let binding = word.to_lowercase(); - let letters: &str = binding.trim(); - - for letter in letters.chars() { - result += match letter { + word.to_lowercase() + .trim() + .chars() + .map(|c| match c { 'a' | 'e' | 'i' | 'o' | 'u' | 'l' | 'n' | 'r' | 's' | 't' => 1, 'd' | 'g' => 2, 'b' | 'c' | 'm' | 'p' => 3, @@ -26,8 +23,6 @@ pub fn score(word: &str) -> u64 { 'j' | 'x' => 8, 'q' | 'z' => 10, _ => 0, - }; - } - - result + }) + .sum() }