refactor: extract a crate with our custom assertions

There's probably an existing crate that we should use directly, but I
haven't found an exact match yet.
pull/24376/head
Jake Goulding 2020-05-01 12:52:00 -04:00
parent acb0c3f2d0
commit e369ada35a
8 changed files with 30 additions and 15 deletions

5
Cargo.lock generated
View File

@ -373,6 +373,7 @@ dependencies = [
"criterion 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"croaring 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
"csv 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"delorean_test_helpers 0.1.0",
"dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"dotenv 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)",
"either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
@ -400,6 +401,10 @@ dependencies = [
"tonic-build 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "delorean_test_helpers"
version = "0.1.0"
[[package]]
name = "delorean_utilities"
version = "0.1.0"

View File

@ -6,7 +6,10 @@ edition = "2018"
default-run = "delorean"
[workspace]
members = ["delorean_utilities"]
members = [
"delorean_test_helpers",
"delorean_utilities",
]
[profile.release]
debug = true
@ -52,6 +55,7 @@ either = "1.5.3"
smallvec = "1.2.0"
[dev-dependencies]
delorean_test_helpers = { path = "delorean_test_helpers" }
criterion = "0.3"
assert_cmd = "1.0.0"
tempfile = "3.1.0"

View File

@ -0,0 +1,9 @@
[package]
name = "delorean_test_helpers"
version = "0.1.0"
authors = ["Paul Dix <paul@pauldix.net>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View File

@ -0,0 +1,8 @@
use std::f64;
/// A test helper function for asserting floating point numbers are within the machine epsilon
/// because strict comparison of floating point numbers is incorrect
pub fn approximately_equal(f1: f64, f2: f64) -> bool {
(f1 - f2).abs() < f64::EPSILON
}

View File

@ -491,7 +491,7 @@ pub fn decode(src: &[u8], dst: &mut Vec<f64>) -> Result<(), Box<dyn Error>> {
#[allow(clippy::unreadable_literal)]
#[allow(clippy::excessive_precision)] // TODO: Audit test values for truncation
mod tests {
use crate::tests::approximately_equal;
use delorean_test_helpers::approximately_equal;
#[test]
fn encode_no_values() {

View File

@ -32,14 +32,3 @@ impl error::Error for Error {
None
}
}
#[cfg(test)]
pub mod tests {
use std::f64;
/// A test helper function for asserting floating point numbers are within the machine epsilon
/// because strict comparison of floating point numbers is incorrect
pub fn approximately_equal(f1: f64, f2: f64) -> bool {
(f1 - f2).abs() < f64::EPSILON
}
}

View File

@ -791,7 +791,7 @@ fn map_fail<'a, R1, R2>(
#[cfg(test)]
mod test {
use super::*;
use crate::tests::approximately_equal;
use delorean_test_helpers::approximately_equal;
type Error = Box<dyn std::error::Error>;
type Result<T = (), E = Error> = std::result::Result<T, E>;

View File

@ -948,7 +948,7 @@ where
#[cfg(test)]
mod test {
use super::*;
use crate::tests::approximately_equal;
use delorean_test_helpers::approximately_equal;
use std::io::Cursor;
#[test]