Browse Source

Add exercise temperature_conv

content-update
Augusto 4 years ago
parent
commit
3287558307
  1. 12
      rust/tests/temperature_conv_test/Cargo.lock
  2. 10
      rust/tests/temperature_conv_test/Cargo.toml
  3. 20
      rust/tests/temperature_conv_test/src/main.rs
  4. 27
      subjects/temperature_conv/README.md

12
rust/tests/temperature_conv_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 = "temperature_conv"
version = "0.1.0"
[[package]]
name = "temperature_conv_test"
version = "0.1.0"
dependencies = [
"temperature_conv",
]

10
rust/tests/temperature_conv_test/Cargo.toml

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

20
rust/tests/temperature_conv_test/src/main.rs

@ -0,0 +1,20 @@
use temperature_conv::*;
use std::f64::EPSILON;
fn eql(a: f64, b: f64) -> bool {
(b - a).abs() < EPSILON
}
#[test]
fn test_f_to_c() {
println!("{}", fahrenheit_to_celsius(83.0));
assert!(eql(fahrenheit_to_celsius(20.0), -6.666666666666666));
assert!(eql(fahrenheit_to_celsius(83.0), 28.333333333333332));
}
#[test]
fn test_c_to_f() {
assert!(eql(celsius_to_fahrenheit(27.0), 80.6));
assert!(eql(celsius_to_fahrenheit(0.0), 32.0))
}

27
subjects/temperature_conv/README.md

@ -0,0 +1,27 @@
## temperature_conv
### Instructions
Write two functions to transform values of temperatures from celcius to fahrenheit and the other way arraound:
### Expected funcions
```rust
fn fahrenheit_to_celsius(f: f64) -> f64 {
}
fn celsius_to_fahrenheit(c: f64) -> f64 {
}
```
### Usage
```rust
use temperature_conv::*;
fn main() {
println!("{} F = {} C", -459.67, fahrenheit_to_celsius(-459.67));
println!("{} C = {} F", 0.0, celsius_to_fahrenheit(0.0));
}
```
Loading…
Cancel
Save