-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
685 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
------------------ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.