From 3287558307ea211fa0515d78e9641dc3d191b353 Mon Sep 17 00:00:00 2001 From: Augusto Date: Thu, 24 Dec 2020 18:36:08 +0000 Subject: [PATCH] Add exercise temperature_conv --- rust/tests/temperature_conv_test/Cargo.lock | 12 +++++++++ rust/tests/temperature_conv_test/Cargo.toml | 10 ++++++++ rust/tests/temperature_conv_test/src/main.rs | 20 +++++++++++++++ subjects/temperature_conv/README.md | 27 ++++++++++++++++++++ 4 files changed, 69 insertions(+) create mode 100644 rust/tests/temperature_conv_test/Cargo.lock create mode 100644 rust/tests/temperature_conv_test/Cargo.toml create mode 100644 rust/tests/temperature_conv_test/src/main.rs create mode 100644 subjects/temperature_conv/README.md diff --git a/rust/tests/temperature_conv_test/Cargo.lock b/rust/tests/temperature_conv_test/Cargo.lock new file mode 100644 index 000000000..60474937b --- /dev/null +++ b/rust/tests/temperature_conv_test/Cargo.lock @@ -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", +] diff --git a/rust/tests/temperature_conv_test/Cargo.toml b/rust/tests/temperature_conv_test/Cargo.toml new file mode 100644 index 000000000..892c2cab6 --- /dev/null +++ b/rust/tests/temperature_conv_test/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "temperature_conv_test" +version = "0.1.0" +authors = ["Augusto "] +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"} diff --git a/rust/tests/temperature_conv_test/src/main.rs b/rust/tests/temperature_conv_test/src/main.rs new file mode 100644 index 000000000..c0c927f78 --- /dev/null +++ b/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)) +} diff --git a/subjects/temperature_conv/README.md b/subjects/temperature_conv/README.md new file mode 100644 index 000000000..0c0a86715 --- /dev/null +++ b/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)); +} +```