From 490e4bffbd59ad2ec400069d980ba098ca84bdbf Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Mon, 16 May 2022 14:52:06 -0400 Subject: [PATCH] cleanup --- src/misc.rs | 26 ++++++++------------------ tests/misc.rs | 38 +++++++++++++++++++------------------- 2 files changed, 27 insertions(+), 37 deletions(-) diff --git a/src/misc.rs b/src/misc.rs index 1f2c066..ed52d19 100644 --- a/src/misc.rs +++ b/src/misc.rs @@ -201,13 +201,15 @@ impl EguiHelper for Vec { fn to_tuple(&self) -> Vec<(f64, f64)> { self.iter().map(|ele| (ele.x, ele.y)).collect() } } -// /// Rounds f64 to `n` decimal places -// pub fn decimal_round(x: f64, n: usize) -> f64 { -// let large_number: f64 = 10.0_f64.powf(n as f64); // 10^n +/* +/// Rounds f64 to `n` decimal places +pub fn decimal_round(x: f64, n: usize) -> f64 { + let large_number: f64 = 10.0_f64.powf(n as f64); // 10^n -// // round and devide in order to cutoff after the `n`th decimal place -// (x * large_number).round() / large_number -// } + // round and devide in order to cutoff after the `n`th decimal place + (x * large_number).round() / large_number +} +*/ /// Helper that assists with using newton's method of finding roots, iterating over data `data` /// `threshold` is the target accuracy threshold @@ -219,12 +221,6 @@ pub fn newtons_method_helper( threshold: &f64, range: &std::ops::Range, data: &[Value], f: &dyn Fn(f64) -> f64, f_1: &dyn Fn(f64) -> f64, ) -> Vec { - debug_assert!(!data.is_empty()); - - unsafe { - assume(!data.is_empty()); - } - data.iter() .tuple_windows() .filter(|(prev, curr)| prev.y.is_finite() && curr.y.is_finite()) @@ -268,12 +264,6 @@ pub fn option_vec_printer(data: &[Option]) -> String where T: ToString, { - debug_assert!(!data.is_empty()); - - unsafe { - assume(!data.is_empty()); - } - let max_i: i32 = (data.len() as i32) - 1; [ "[", diff --git a/tests/misc.rs b/tests/misc.rs index 913d289..325d5d5 100644 --- a/tests/misc.rs +++ b/tests/misc.rs @@ -26,28 +26,28 @@ fn stepped_vector() { assert_eq!(stepped_vector.get_index((max + 1) as f64), None); } -// /// Ensures [`decimal_round`] returns correct values -// #[test] -// fn decimal_round() { -// use ytbn_graphing_software::decimal_round; +/* +/// Ensures [`decimal_round`] returns correct values +#[test] +fn decimal_round() { + use ytbn_graphing_software::decimal_round; -// assert_eq!(decimal_round(0.00001, 1), 0.0); -// assert_eq!(decimal_round(0.00001, 2), 0.0); -// assert_eq!(decimal_round(0.00001, 3), 0.0); -// assert_eq!(decimal_round(0.00001, 4), 0.0); -// assert_eq!(decimal_round(0.00001, 5), 0.00001); + assert_eq!(decimal_round(0.00001, 1), 0.0); + assert_eq!(decimal_round(0.00001, 2), 0.0); + assert_eq!(decimal_round(0.00001, 3), 0.0); + assert_eq!(decimal_round(0.00001, 4), 0.0); + assert_eq!(decimal_round(0.00001, 5), 0.00001); -// assert_eq!(decimal_round(0.12345, 1), 0.1); -// assert_eq!(decimal_round(0.12345, 2), 0.12); -// assert_eq!(decimal_round(0.12345, 3), 0.123); -// assert_eq!(decimal_round(0.12345, 4), 0.1235); // rounds up -// assert_eq!(decimal_round(0.12345, 5), 0.12345); + assert_eq!(decimal_round(0.12345, 1), 0.1); + assert_eq!(decimal_round(0.12345, 2), 0.12); + assert_eq!(decimal_round(0.12345, 3), 0.123); + assert_eq!(decimal_round(0.12345, 4), 0.1235); // rounds up + assert_eq!(decimal_round(0.12345, 5), 0.12345); -// assert_eq!(decimal_round(1.9, 0), 2.0); -// assert_eq!(decimal_round(1.9, 1), 1.9); -// } - -/// Tests [`resolution_helper`] to make sure it returns expected output + assert_eq!(decimal_round(1.9, 0), 2.0); + assert_eq!(decimal_round(1.9, 1), 1.9); +} +*/ #[test] fn step_helper() {