Skip to content

Commit

Permalink
rust/series: 1st iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
vpayno committed Sep 20, 2023
1 parent 07e8cf9 commit c88ddba
Show file tree
Hide file tree
Showing 8 changed files with 685 additions and 7 deletions.
1 change: 1 addition & 0 deletions rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@
- [luhn-from](./luhn-from/README.md)
- [collatz-conjecture](./collatz-conjecture/README.md)
- [luhn-trait](./luhn-trait/README.md)
- [series](./series/README.md)
7 changes: 6 additions & 1 deletion rust/series/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,9 @@ in the input; the digits need not be *numerically consecutive*.

### Based on

A subset of the Problem 8 at Project Euler - http://projecteuler.net/problem=8
A subset of the Problem 8 at Project Euler - http://projecteuler.net/problem=8

### My Solution

- [my solution](./src/lib.rs)
- [run-tests](./run-tests-rust.txt)
110 changes: 110 additions & 0 deletions rust/series/coverage-annotations.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
1| |/// Exercise Url: <https://exercism.org/tracks/rust/exercises/series>
2| |
3| |/// Given a string of digits, output all the contiguous substrings of length n in that string in the order that they appear.
4| |///
5| |/// Not sure why we're not returning a Result here.
6| |///
7| |/// Example with a sequence of 5 digits and a span of 3:
8| |/// ```rust
9| |/// use series::*;
10| |///
11| |/// let want: Vec<String> = vec!["491".to_string(), "914".to_string(), "142".to_string()];
12| |/// let got: Vec<String> = series("49142", 3);
13| |///
14| |/// assert_eq!(got, want);
15| |/// ```
16| |///
17| |/// Example with a sequence of 5 digits and a span of 2:
18| |/// ```rust
19| |/// use series::*;
20| |///
21| |/// let want: Vec<String> = vec!["4914".to_string(), "9142".to_string()];
22| |/// let got: Vec<String> = series("49142", 4);
23| |///
24| |/// assert_eq!(got, want);
25| |/// ```
26| 15|pub fn series(sequence: &str, span: usize) -> Vec<String> {
27| 15| if span == 0 {
28| | // this corner case, with_zero_length, doesn't make sense
29| 3| return vec!["".to_string(); sequence.len() + 1];
30| 12| }
31| 12|
32| 12| if sequence.is_empty() {
33| | // why are we returning a vector with empty strings?
34| 0| return vec!["".to_string(); sequence.len()];
35| 12| }
36| 12|
37| 12| if sequence.len() == span {
38| | // this corner case makes sense
39| 3| return vec![sequence.to_string()];
40| 9| }
41| 9|
42| 9| // corner case ignored by tests
43| 9| if sequence.len() < span {
44| 6| return vec![];
45| 3| }
46| 3|
47| 3| // only one test to test the logic of the program?
48| 3| let mut groups: Vec<String> = vec![];
49| 3| let mut remaining: usize = sequence.len();
50| |
51| 15| for (index, _) in sequence.chars().enumerate() {
^3
52| 15| if remaining < span || index + span > sequence.len() {
^12
53| 3| break;
54| 12| }
55| 12| remaining -= 1;
56| 12|
57| 12| let group: String = sequence[index..span + index].to_string();
58| 12|
59| 12| groups.push(group);
60| | }
61| |
62| 3| groups
63| 15|}
------------------
| series::series:
| 26| 15|pub fn series(sequence: &str, span: usize) -> Vec<String> {
| 27| 15| if span == 0 {
| 28| | // this corner case, with_zero_length, doesn't make sense
| 29| 3| return vec!["".to_string(); sequence.len() + 1];
| 30| 12| }
| 31| 12|
| 32| 12| if sequence.is_empty() {
| 33| | // why are we returning a vector with empty strings?
| 34| 0| return vec!["".to_string(); sequence.len()];
| 35| 12| }
| 36| 12|
| 37| 12| if sequence.len() == span {
| 38| | // this corner case makes sense
| 39| 3| return vec![sequence.to_string()];
| 40| 9| }
| 41| 9|
| 42| 9| // corner case ignored by tests
| 43| 9| if sequence.len() < span {
| 44| 6| return vec![];
| 45| 3| }
| 46| 3|
| 47| 3| // only one test to test the logic of the program?
| 48| 3| let mut groups: Vec<String> = vec![];
| 49| 3| let mut remaining: usize = sequence.len();
| 50| |
| 51| 15| for (index, _) in sequence.chars().enumerate() {
| ^3
| 52| 15| if remaining < span || index + span > sequence.len() {
| ^12
| 53| 3| break;
| 54| 12| }
| 55| 12| remaining -= 1;
| 56| 12|
| 57| 12| let group: String = sequence[index..span + index].to_string();
| 58| 12|
| 59| 12| groups.push(group);
| 60| | }
| 61| |
| 62| 3| groups
| 63| 15|}
------------------
| Unexecuted instantiation: series::series
------------------
10 changes: 10 additions & 0 deletions rust/series/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 --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/series/src/lib.rs 17 1 94.12% 1 0 100.00% 32 1 96.88% 0 0 -
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL 17 1 94.12% 1 0 100.00% 32 1 96.88% 0 0 -
Uncovered Lines:
/home/vpayno/git_vpayno/exercism-workspace/rust/series/src/lib.rs: 34

44 changes: 44 additions & 0 deletions rust/series/report.lcov
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
SF:/home/vpayno/git_vpayno/exercism-workspace/rust/series/src/lib.rs
FN:26,_RNvCs3hVIKtMrduI_6series6series
FN:26,_RNvCsfpoSPjMhDZV_6series6series
FNDA:5,_RNvCs3hVIKtMrduI_6series6series
FNDA:0,_RNvCsfpoSPjMhDZV_6series6series
FNF:1
FNH:1
DA:26,5
DA:27,5
DA:29,1
DA:30,4
DA:31,4
DA:32,4
DA:34,0
DA:35,4
DA:36,4
DA:37,4
DA:39,1
DA:40,3
DA:41,3
DA:42,3
DA:43,3
DA:44,2
DA:45,1
DA:46,1
DA:47,1
DA:48,1
DA:49,1
DA:51,5
DA:52,5
DA:53,1
DA:54,4
DA:55,4
DA:56,4
DA:57,4
DA:58,4
DA:59,4
DA:62,1
DA:63,5
BRF:0
BRH:0
LF:32
LH:31
end_of_record
Loading

0 comments on commit c88ddba

Please sign in to comment.