From 865a2e8db1431c75a4178b61c3e277636a958fbb Mon Sep 17 00:00:00 2001 From: Marshall Pierce Date: Sun, 19 Feb 2017 20:17:32 -0800 Subject: [PATCH] Split the unit tests into several files. --- src/lib.rs | 1 + src/tests/helpers.rs | 8 ++++++++ src/{tests.rs => tests/init.rs} | 22 +--------------------- src/tests/tests.rs | 12 ++++++++++++ 4 files changed, 22 insertions(+), 21 deletions(-) create mode 100644 src/tests/helpers.rs rename src/{tests.rs => tests/init.rs} (91%) create mode 100644 src/tests/tests.rs diff --git a/src/lib.rs b/src/lib.rs index ffea191..d6e4e44 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1468,5 +1468,6 @@ impl PartialEq> for Histogram // TODO: timestamps and tags // TODO: textual output +#[path = "tests/tests.rs"] #[cfg(test)] mod tests; diff --git a/src/tests/helpers.rs b/src/tests/helpers.rs new file mode 100644 index 0000000..88d82f6 --- /dev/null +++ b/src/tests/helpers.rs @@ -0,0 +1,8 @@ +use super::Histogram; + +#[cfg(test)] +pub fn histo64(lowest_discernible_value: u64, highest_trackable_value: u64, num_significant_digits: u8) + -> Histogram { + Histogram::::new_with_bounds(lowest_discernible_value, highest_trackable_value, + num_significant_digits).unwrap() +} diff --git a/src/tests.rs b/src/tests/init.rs similarity index 91% rename from src/tests.rs rename to src/tests/init.rs index 6478463..707d0ab 100644 --- a/src/tests.rs +++ b/src/tests/init.rs @@ -1,4 +1,4 @@ -use super::Histogram; +use tests::helpers::histo64; #[test] fn init_fields_smallest_possible_array() { @@ -250,23 +250,3 @@ fn init_fields_max_value_max_unit_magnitude_max_precision() { assert_eq!(64 - 62 - 1, h.leading_zero_count_base); } - -#[test] -fn new_err_lowest_value_too_large_for_precision() { - let res = Histogram::::new_with_bounds(u64::max_value() / 2, u64::max_value(), 0); - assert_eq!("Cannot represent significant figures' worth of measurements beyond lowest value", - res.unwrap_err()); -} - -#[test] -fn new_err_high_not_double_low() { - let res = Histogram::::new_with_bounds(10, 15, 0); - assert_eq!("highest trackable value must be >= 2 * lowest discernible value", res.unwrap_err()); -} - -#[cfg(test)] -fn histo64(lowest_discernible_value: u64, highest_trackable_value: u64, num_significant_digits: u8) - -> Histogram { - Histogram::::new_with_bounds(lowest_discernible_value, highest_trackable_value, - num_significant_digits).unwrap() -} diff --git a/src/tests/tests.rs b/src/tests/tests.rs new file mode 100644 index 0000000..42038bf --- /dev/null +++ b/src/tests/tests.rs @@ -0,0 +1,12 @@ +use super::Histogram; + +#[path = "helpers.rs"] +mod helpers; +#[path = "init.rs"] +mod init; + +#[test] +fn new_err_high_not_double_low() { + let res = Histogram::::new_with_bounds(10, 15, 0); + assert_eq!("highest trackable value must be >= 2 * lowest discernible value", res.unwrap_err()); +}