forked from root/public
![aug.ornelas@gmail.com](/git/assets/img/avatar_default.png)
4 changed files with 69 additions and 0 deletions
@ -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", |
||||
] |
@ -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"} |
@ -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)) |
||||
} |
@ -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…
Reference in new issue