Browse Source

Improve readme for older exercises

content-update
Augusto 3 years ago
parent
commit
0f335765dc
  1. 23
      rust/tests/fibonacci2_test/src/main.rs
  2. 32
      subjects/fibonacci2/README.md
  3. 10
      subjects/groceries/README.md
  4. 14
      subjects/reverse_string/README.md

23
rust/tests/fibonacci2_test/src/main.rs

@ -1,5 +1,28 @@
use fibonacci2::*;
fn main() {
println!(
"The element in the position {} in fibonacci series is {}",
2,
fibonacci(2)
);
println!(
"The element in the position {} in fibonacci series is {}",
4,
fibonacci(4)
);
println!(
"The element in the position {} in fibonacci series is {}",
22,
fibonacci(22)
);
println!(
"The element in the position {} in fibonacci series is {}",
20,
fibonacci(20)
);
}
#[test]
fn it_works() {
assert_eq!(fibonacci(0), 0);

32
subjects/fibonacci2/README.md

@ -21,17 +21,25 @@ The Fibonacci Series starts like this: 0, 1, 1, 2, 3, 5, 8, 13... so fibonacci(2
Here is a possible test for your function:
```
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
assert_eq!(fibonacci(2), 1);
assert_eq!(fibonacci(4), 1);
assert_eq!(fibonacci(22), 17711);
assert_eq!(fibonacci(20), 6765);
}
```rust
use fibonacci2::fibonacci;
fn main() {
println!("The element in the position {} in fibonacci series is {}",2, fibonacci(2));
println!("The element in the position {} in fibonacci series is {}",4, fibonacci(4));
println!("The element in the position {} in fibonacci series is {}",22, fibonacci(22));
println!("The element in the position {} in fibonacci series is {}", 20, fibonacci(20));
}
```
And its output:
```console
student@ubuntu:~/[[ROOT]]/test$ cargo run
The element in the position 2 in fibonacci series is 1
The element in the position 4 in fibonacci series is 3
The element in the position 22 in fibonacci series is 17711
The element in the position 20 in fibonacci series is 6765
student@ubuntu:~/[[ROOT]]/test$
```

10
subjects/groceries/README.md

@ -6,6 +6,10 @@ Create a function called `insert` that inserts a new element at the end of the V
And another function `at_index` that returns the value found at the index passed as an argument
### Notions
[Common Collections]( https://doc.rust-lang.org/stable/book/ch08-00-common-collections.html)
### Expected Functions
```rust
@ -18,6 +22,8 @@ pub fn at_index(vec: &Vec<String>, index: ) -> String {
### Usage
Here is a possible program to test your function:
```rust
use groceries::{insert, at_index}
@ -39,7 +45,9 @@ fn main() {
And its output:
```rust
```console
student@ubuntu:~/[[ROOT]]/test$ cargo run
The groceries list now = ["yogurt", "panetone", "bread", "cheese", "nuts"]
The second element of the grocery list is "panetone"
student@ubuntu:~/[[ROOT]]/test$
```

14
subjects/reverse_string/README.md

@ -13,24 +13,28 @@ pub fn rev_str(input: &str) -> String {
### Usage
Here is a possible program to test your function :
```rust
use reverse_string::rev_str;
fn main() {
println!("{}", rev_str("Hello, world!"));
println!("{}", rev_str("Hello, my name is Roman"));
println!("{}", rev_str("I have a nice car!"));
println!("{}", rev_str("How old are You"));
println!("{}", rev_str("ex: this is an example água"));
println!("{}", rev_str("Hello, world!"));
println!("{}", rev_str("Hello, my name is Roman"));
println!("{}", rev_str("I have a nice car!"));
println!("{}", rev_str("How old are You"));
println!("{}", rev_str("ex: this is an example água"));
}
```
And it's output:
```console
student@ubuntu:~/[[ROOT]]/test$ cargo run
!dlrow ,olleH
namoR si eman ym ,olleH
!rac ecin a evah I
uoY era dlo woH
augá elpmaxe na si siht :xe
student@ubuntu:~/[[ROOT]]/test$
```

Loading…
Cancel
Save