Commit dc718335 authored by Mathias Goldau's avatar Mathias Goldau
Browse files

[FIX #244] Now the last interval is explicitly queried, resulting in slower but more correct code.

parent ea6891c3
......@@ -35,7 +35,7 @@
WHistogramBasic::WHistogramBasic( double min, double max, size_t buckets ):
WHistogram( min, max, buckets ),
m_bins( buckets, 0 ),
m_intervalWidth( ( m_maximum - m_minimum ) / static_cast< double >( m_nbBuckets ) )
m_intervalWidth( std::abs( m_maximum - m_minimum ) / static_cast< double >( m_nbBuckets ) )
{
}
......@@ -91,9 +91,13 @@ void WHistogramBasic::insert( double value )
{
m_bins.at( m_nbBuckets - 1 )++;
}
else if( value >= ( m_maximum - m_intervalWidth ) && value <= m_maximum ) // last bucket deserves extra treatment due to possible out of bounds index
{
m_bins.at( m_nbBuckets - 1 )++;
}
else
{
m_bins.at( static_cast< size_t >( ( value - m_minimum ) / std::abs( m_maximum - m_minimum ) * ( m_nbBuckets - 1 ) ) )++;
m_bins.at( static_cast< size_t >( ( value - m_minimum ) / std::abs( m_maximum - m_minimum ) * ( m_nbBuckets ) ) )++;
}
}
......
......@@ -64,7 +64,7 @@ public:
h.insert( 0.7234 );
TS_ASSERT_EQUALS( h.size(), 1000 );
TS_ASSERT_EQUALS( h.valuesSize(), 1 );
TS_ASSERT_EQUALS( h[722], 1 );
TS_ASSERT_EQUALS( h[723], 1 );
}
/**
......@@ -74,11 +74,11 @@ public:
{
WHistogramBasic h( 0.0, 1.0 );
h.insert( 0.001 );
TS_ASSERT_EQUALS( h[0], 1 );
TS_ASSERT_EQUALS( h[1], 1 );
h.insert( 0.0039999 );
TS_ASSERT_EQUALS( h[3], 1 );
h.insert( 0.0070001 );
TS_ASSERT_EQUALS( h[6], 1 );
TS_ASSERT_EQUALS( h[7], 1 );
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment