Skip to content

Commit

Permalink
Merge pull request #18 from marshallpierce/split-unit-tests
Browse files Browse the repository at this point in the history
Split the unit tests into several files.

Also addresses rust-lang/rust#37872.
  • Loading branch information
jonhoo authored Feb 20, 2017
2 parents ed7f3e0 + 865a2e8 commit ae305fc
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1467,5 +1467,6 @@ impl<T: Counter, F: Counter> PartialEq<Histogram<F>> for Histogram<T>
// TODO: timestamps and tags
// TODO: textual output

#[path = "tests/tests.rs"]
#[cfg(test)]
mod tests;
8 changes: 8 additions & 0 deletions src/tests/helpers.rs
Original file line number Diff line number Diff line change
@@ -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<u64> {
Histogram::<u64>::new_with_bounds(lowest_discernible_value, highest_trackable_value,
num_significant_digits).unwrap()
}
22 changes: 1 addition & 21 deletions src/tests.rs → src/tests/init.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::Histogram;
use tests::helpers::histo64;

#[test]
fn init_fields_smallest_possible_array() {
Expand Down Expand Up @@ -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::<u64>::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::<u64>::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<u64> {
Histogram::<u64>::new_with_bounds(lowest_discernible_value, highest_trackable_value,
num_significant_digits).unwrap()
}
12 changes: 12 additions & 0 deletions src/tests/tests.rs
Original file line number Diff line number Diff line change
@@ -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::<u64>::new_with_bounds(10, 15, 0);
assert_eq!("highest trackable value must be >= 2 * lowest discernible value", res.unwrap_err());
}

0 comments on commit ae305fc

Please sign in to comment.