From d03130f8241a4eb80f4e03980d07d91c84eb3709 Mon Sep 17 00:00:00 2001 From: Greacko <123205959+Greacko@users.noreply.github.com> Date: Fri, 1 Nov 2024 12:06:01 -0400 Subject: [PATCH] tried seperating tests to the lib file due to some weird errors --- crates/thermocouple-converter/src/lib.rs | 40 -------------------- crates/thermocouple-converter/tests/test.rs | 41 +++++++++++++++++++++ 2 files changed, 41 insertions(+), 40 deletions(-) create mode 100644 crates/thermocouple-converter/tests/test.rs diff --git a/crates/thermocouple-converter/src/lib.rs b/crates/thermocouple-converter/src/lib.rs index 5bb2a3d..dde29ec 100644 --- a/crates/thermocouple-converter/src/lib.rs +++ b/crates/thermocouple-converter/src/lib.rs @@ -56,44 +56,4 @@ pub fn voltage_to_celsius(voltage: f64) -> f64 { } return -1.0; -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn voltage_to_celsius_test1() { - //println!("Test 1: {}", voltage_to_celsius(20.644)); - let result:f64 = voltage_to_celsius(20.644); - assert!(499.97 <= result && 500.0 >= result); - } - - #[test] - fn voltage_to_celsius_test2() { - // println!("Test 2: {}", voltage_to_celsius(6.138)); - let result:f64 = voltage_to_celsius(6.138); - assert!(150.01 <= result && 150.03 >= result); - } - - #[test] - fn voltage_to_celsius_test3() { - // println!("Test 3: {}", voltage_to_celsius(0.039)); - let result:f64 = voltage_to_celsius(0.039); - assert!(0.97 <= result && 0.98 >= result); - } - - #[test] - fn voltage_to_celsius_test4() { - // println!("Test 4: {}", voltage_to_celsius(-0.778)); - let result:f64 = voltage_to_celsius(-0.778); - assert!(-20.03 <= result && -20.01 >= result); - } - - #[test] - fn voltage_to_celsius_test5() { - // println!("Test 5: {}", voltage_to_celsius(10.0)); - let result:f64 = voltage_to_celsius(10.0); - assert!(246.1 <= result && 246.3 >= result); - } } \ No newline at end of file diff --git a/crates/thermocouple-converter/tests/test.rs b/crates/thermocouple-converter/tests/test.rs new file mode 100644 index 0000000..81ad112 --- /dev/null +++ b/crates/thermocouple-converter/tests/test.rs @@ -0,0 +1,41 @@ +use crate::voltage_to_celsius; + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn voltage_to_celsius_test1() { + //println!("Test 1: {}", voltage_to_celsius(20.644)); + let result:f64 = voltage_to_celsius(20.644); + assert!(499.97 <= result && 500.0 >= result); + } + + #[test] + fn voltage_to_celsius_test2() { + // println!("Test 2: {}", voltage_to_celsius(6.138)); + let result:f64 = voltage_to_celsius(6.138); + assert!(150.01 <= result && 150.03 >= result); + } + + #[test] + fn voltage_to_celsius_test3() { + // println!("Test 3: {}", voltage_to_celsius(0.039)); + let result:f64 = voltage_to_celsius(0.039); + assert!(0.97 <= result && 0.98 >= result); + } + + #[test] + fn voltage_to_celsius_test4() { + // println!("Test 4: {}", voltage_to_celsius(-0.778)); + let result:f64 = voltage_to_celsius(-0.778); + assert!(-20.03 <= result && -20.01 >= result); + } + + #[test] + fn voltage_to_celsius_test5() { + // println!("Test 5: {}", voltage_to_celsius(10.0)); + let result:f64 = voltage_to_celsius(10.0); + assert!(246.1 <= result && 246.3 >= result); + } +} \ No newline at end of file