Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix edge case on outlier detection i.e. use [low, high) not [low, high]

  • Loading branch information...
commit 0efd394a1f9a401d0f24a227336d03fd16ea17d7 1 parent 20f0380
@josephruscio authored
Showing with 8 additions and 5 deletions.
  1. +4 −2 lib/aggregate.rb
  2. +4 −3 test/ts_aggregate.rb
View
6 lib/aggregate.rb
@@ -36,7 +36,9 @@ def initialize (low=nil, high=nil, width=nil)
@outliers_low = 0
@outliers_high = 0
- # If the user asks we maintain a linear histogram
+ # If the user asks we maintain a linear histogram where
+ # values in the range [low, high) are bucketed in multiples
+ # of width
if (nil != low && nil != high && nil != width)
#Validate linear specification
@@ -204,7 +206,7 @@ def outlier? (data)
if data < @low
@outliers_low += 1
- elsif data > @high
+ elsif data >= @high
@outliers_high += 1
else
return false
View
7 test/ts_aggregate.rb
@@ -135,17 +135,18 @@ def test_validation
end
#XXX: Update test_bucket_contents() if you muck with @@DATA
- @@DATA = [ 1, 5, 4, 6, 1028, 1972, 16384, 16385, 16383 ]
+ # 32768 is an outlier
+ @@DATA = [ 0, 1, 5, 4, 6, 1028, 1972, 16384, 16385, 16383, 32768]
def test_bucket_contents
#XXX: This is the only test so far that cares about the actual contents
# of @@DATA, so if you update that array ... update this method too
expected_buckets = [0, 1024, 15360, 16384]
- expected_counts = [4, 2, 1, 2]
+ expected_counts = [5, 2, 1, 2]
i = 0
@stats.each_nonzero do |bucket, count|
assert_equal expected_buckets[i], bucket
- assert_equal expected_counts[i], count
+ assert_equal expected_counts[i], count
# Increment for the next test
i += 1
end
Please sign in to comment.
Something went wrong with that request. Please try again.