rust-practice / cargo-leet

Program to make working on leetcode problems locally more convenient
Apache License 2.0
5 stars 3 forks source link

Handle assertion for Vec<f64> #43

Open c-git opened 1 year ago

c-git commented 1 year ago

Discussed in https://github.com/rust-practice/cargo-leet/discussions/34

Originally posted by **sak96** June 28, 2023 ```rust else if Some(FunctionArgType::VecF64) = &self.return_type { r#" assert!(actual.len(), expected.len(), "actual {actual} not same length as {expected}"); actual.iter().zip(expected.iter()).enumerate().for_each(|(i, (actual, expected))| { assert!((actual - expected).abs() < 1e-5, "Assertion failed: {i}th element in actual {actual:.5} but expected {expected:.5}. Diff is more than 1e-5."); }) "# } else ``` use match statement if it helps
c-git commented 1 year ago

Converted from discussion to make it easier to to link to the PR that implements it