Fix constant width histograms for ranges not starting at 0
This commit is contained in:
parent
c04ce8887e
commit
0259728bb8
@ -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 {
|
||||
|
@ -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]);
|
||||
|
Loading…
Reference in New Issue
Block a user