Skip to content

Commit ae305fc

Browse files
authored
Merge pull request #18 from marshallpierce/split-unit-tests
Split the unit tests into several files. Also addresses rust-lang/rust#37872.
2 parents ed7f3e0 + 865a2e8 commit ae305fc

File tree

4 files changed

+22
-21
lines changed

4 files changed

+22
-21
lines changed

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1467,5 +1467,6 @@ impl<T: Counter, F: Counter> PartialEq<Histogram<F>> for Histogram<T>
14671467
// TODO: timestamps and tags
14681468
// TODO: textual output
14691469

1470+
#[path = "tests/tests.rs"]
14701471
#[cfg(test)]
14711472
mod tests;

src/tests/helpers.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use super::Histogram;
2+
3+
#[cfg(test)]
4+
pub fn histo64(lowest_discernible_value: u64, highest_trackable_value: u64, num_significant_digits: u8)
5+
-> Histogram<u64> {
6+
Histogram::<u64>::new_with_bounds(lowest_discernible_value, highest_trackable_value,
7+
num_significant_digits).unwrap()
8+
}

src/tests.rs renamed to src/tests/init.rs

+1-21
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::Histogram;
1+
use tests::helpers::histo64;
22

33
#[test]
44
fn init_fields_smallest_possible_array() {
@@ -250,23 +250,3 @@ fn init_fields_max_value_max_unit_magnitude_max_precision() {
250250

251251
assert_eq!(64 - 62 - 1, h.leading_zero_count_base);
252252
}
253-
254-
#[test]
255-
fn new_err_lowest_value_too_large_for_precision() {
256-
let res = Histogram::<u64>::new_with_bounds(u64::max_value() / 2, u64::max_value(), 0);
257-
assert_eq!("Cannot represent significant figures' worth of measurements beyond lowest value",
258-
res.unwrap_err());
259-
}
260-
261-
#[test]
262-
fn new_err_high_not_double_low() {
263-
let res = Histogram::<u64>::new_with_bounds(10, 15, 0);
264-
assert_eq!("highest trackable value must be >= 2 * lowest discernible value", res.unwrap_err());
265-
}
266-
267-
#[cfg(test)]
268-
fn histo64(lowest_discernible_value: u64, highest_trackable_value: u64, num_significant_digits: u8)
269-
-> Histogram<u64> {
270-
Histogram::<u64>::new_with_bounds(lowest_discernible_value, highest_trackable_value,
271-
num_significant_digits).unwrap()
272-
}

src/tests/tests.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use super::Histogram;
2+
3+
#[path = "helpers.rs"]
4+
mod helpers;
5+
#[path = "init.rs"]
6+
mod init;
7+
8+
#[test]
9+
fn new_err_high_not_double_low() {
10+
let res = Histogram::<u64>::new_with_bounds(10, 15, 0);
11+
assert_eq!("highest trackable value must be >= 2 * lowest discernible value", res.unwrap_err());
12+
}

0 commit comments

Comments
 (0)