mirror of https://github.com/01-edu/public.git
Augusto
4 years ago
4 changed files with 94 additions and 0 deletions
@ -0,0 +1,12 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
[[package]] |
||||
name = "division_and_remainder" |
||||
version = "0.1.0" |
||||
|
||||
[[package]] |
||||
name = "division_and_reminder_test" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"division_and_remainder", |
||||
] |
@ -0,0 +1,10 @@
|
||||
[package] |
||||
name = "division_and_reminder_test" |
||||
version = "0.1.0" |
||||
authors = ["Augusto <aug.ornelas@gmail.com>"] |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
division_and_remainder = { path = "../../../../rust-piscine-solutions/division_and_remainder" } |
@ -0,0 +1,35 @@
|
||||
use division_and_remainder::*; |
||||
|
||||
fn main() { |
||||
let x = 9; |
||||
let y = 4; |
||||
let (division, remainder) = divide(x, y); |
||||
println!( |
||||
"\t{}/{}: division = {}, remainder = {}", |
||||
x, y, division, remainder |
||||
); |
||||
} |
||||
|
||||
#[test] |
||||
#[should_panic] |
||||
fn divide_by_0() { |
||||
divide(40, 0); |
||||
} |
||||
|
||||
#[test] |
||||
fn test_divide() { |
||||
let (div, rem) = divide(40, 3); |
||||
|
||||
assert_eq!(div, 13); |
||||
assert_eq!(rem, 1); |
||||
|
||||
let (div, rem) = divide(389, 39); |
||||
|
||||
assert_eq!(div, 9); |
||||
assert_eq!(rem, 38); |
||||
|
||||
let (div, rem) = divide(29, 332); |
||||
|
||||
assert_eq!(div, 0); |
||||
assert_eq!(rem, 29); |
||||
} |
@ -0,0 +1,37 @@
|
||||
## division_and_remainder |
||||
|
||||
### Instructions |
||||
|
||||
Create a function divide that receives two i32 and returns a tuple in which the first element is the result of the integer division between the two numbers and the second is the remainder of the division. |
||||
|
||||
### Expected Function |
||||
|
||||
```rust |
||||
fn divide(x: i32, y: i32) -> (i32, i32) { |
||||
|
||||
} |
||||
``` |
||||
|
||||
### Usage |
||||
|
||||
Here is a program to test you're function |
||||
|
||||
```rust |
||||
fn main() { |
||||
let x = 9; |
||||
let y = 4; |
||||
let (division, remainder) = divide(x, y); |
||||
println!( |
||||
"\t{}/{}: division = {}, remainder = {}", |
||||
x, y, division, remainder |
||||
); |
||||
} |
||||
``` |
||||
|
||||
And its output |
||||
|
||||
```console |
||||
student@ubuntu:~/[[ROOT]]/test$ cargo run |
||||
9/4: division = 2, remainder = 1 |
||||
student@ubuntu:~/[[ROOT]]/test$ |
||||
``` |
Loading…
Reference in new issue