Browse Source

Add the exercise division_and_remainder's subject and tests

pull/692/head
Augusto 4 years ago
parent
commit
95d1e5d365
  1. 12
      rust/tests/division_and_remainder_test/Cargo.lock
  2. 10
      rust/tests/division_and_remainder_test/Cargo.toml
  3. 35
      rust/tests/division_and_remainder_test/src/main.rs
  4. 37
      subjects/division_and_remainder/README.md

12
rust/tests/division_and_remainder_test/Cargo.lock diff.generated

@ -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",
]

10
rust/tests/division_and_remainder_test/Cargo.toml

@ -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" }

35
rust/tests/division_and_remainder_test/src/main.rs

@ -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);
}

37
subjects/division_and_remainder/README.md

@ -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…
Cancel
Save