Fix constant width histograms for ranges not starting at 0

This commit is contained in:
Vinzent Steinberg 2018-03-07 17:37:06 +01:00
parent c04ce8887e
commit 0259728bb8
2 changed files with 3 additions and 3 deletions

View File

@ -34,7 +34,7 @@ macro_rules! define_histogram {
let step = (end - start) / (LEN as f64);
let mut range = [0.; LEN + 1];
for (i, r) in range.iter_mut().enumerate() {
*r = step * (i as f64);
*r = start + step * (i as f64);
}
Self {

View File

@ -10,8 +10,8 @@ define_histogram!(Histogram10, 10);
#[test]
fn with_const_width() {
let mut h = Histogram10::with_const_width(0., 100.);
for i in 0..100 {
let mut h = Histogram10::with_const_width(-30., 70.);
for i in -30..70 {
h.add(f64::from(i)).unwrap();
}
assert_eq!(h.bins(), &[10, 10, 10, 10, 10, 10, 10, 10, 10, 10]);