Browse Source

Add exercise `speed_transformation` subject and test

content-update
Augusto 3 years ago
parent
commit
7847670d1c
  1. 12
      rust/tests/speed_transformation_test/Cargo.lock
  2. 10
      rust/tests/speed_transformation_test/Cargo.toml
  3. 18
      rust/tests/speed_transformation_test/src/main.rs
  4. 31
      subjects/speed_transformation/README.md

12
rust/tests/speed_transformation_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 = "speed_transformation"
version = "0.1.0"
[[package]]
name = "speed_transformation_test"
version = "0.1.0"
dependencies = [
"speed_transformation",
]

10
rust/tests/speed_transformation_test/Cargo.toml

@ -0,0 +1,10 @@
[package]
name = "speed_transformation_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]
speed_transformation = { path = "../../../../rust-piscine-solutions/speed_transformation"}

18
rust/tests/speed_transformation_test/src/main.rs

@ -0,0 +1,18 @@
// Create a function that receives the speed in km/h (kilometers per hour) and returns the
// equivalent in m/s (meters per second)
use speed_transformation::*;
fn main() {
let km_h = 100.0;
let m_s = km_per_hour_to_meters_per_second(km_h);
println!("{} km/h is equivalent to {} m/s", km_h, m_s);
}
#[test]
fn kmh_to_ms() {
assert_eq!(km_per_hour_to_meters_per_second(90.0), 25.0);
assert_eq!(km_per_hour_to_meters_per_second(50.0), 13.88888888888889);
assert_eq!(km_per_hour_to_meters_per_second(10.0), 2.7777777777777777);
assert_eq!(km_per_hour_to_meters_per_second(100.0), 27.77777777777778);
}

31
subjects/speed_transformation/README.md

@ -0,0 +1,31 @@
## speed_transformation
### Instructions
Create a function that receives the speed in km/h (kilometers per hour) and returns the equivalent in m/s (meters per second)
### Expected Function
```rust
pub fn km_per_hour_to_meters_per_second(km_h: f64) -> f64 {
(10.0 / 36.0) * km_h
}
```
### Usage
```rust
fn main() {
let km_h = 100.0;
let m_s = km_per_hour_to_meters_per_second(km_h);
println!("{} km/h is equivalent to {} m/s", km_h, m_s);
}
```
And its output:
```console
student@ubuntu:~/[[ROOT]]/test$ cargo run
100 km/h is equivalent to 27.77777777777778 m/s
student@ubuntu:~/[[ROOT]]/test$
```
Loading…
Cancel
Save