Skip to content

Commit

Permalink
Merge pull request #14 from josephruscio/fix_warnings
Browse files Browse the repository at this point in the history
Modernize some code to fix warnings
  • Loading branch information
nextmat authored Aug 1, 2023
2 parents b84d7e8 + 6b8f5ef commit cb2154b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions lib/aggregate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Aggregate
# Create a new Aggregate that maintains a binary logarithmic histogram
# by default. Specifying values for low, high, and width configures
# the aggregate to maintain a linear histogram with (high - low)/width buckets
def initialize (low=nil, high=nil, width=nil)
def initialize(low=nil, high=nil, width=nil)
@count = 0
@sum = 0.0
@sum2 = 0.0
Expand Down Expand Up @@ -204,7 +204,7 @@ def linear?
nil != @width
end

def outlier? (data)
def outlier?(data)

if data < @low
@outliers_low += 1
Expand All @@ -231,7 +231,7 @@ def to_bucket(index)
end
end

def right_bucket? index, data
def right_bucket?(index, data)

# check invariant
raise unless linear?
Expand Down Expand Up @@ -262,7 +262,7 @@ def find_bucket(lower, upper, target)
# A data point is added to the bucket[n] where the data point
# is less than the value represented by bucket[n], but greater
# than the value represented by bucket[n+1]
def to_index (data)
def to_index(data)

# basic case is simple
return log2(data).to_i if !linear?
Expand Down
10 changes: 5 additions & 5 deletions test/ts_aggregate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_bucket_counts
i = 0
@stats.each do |bucket, count|
assert_equal 2**i, bucket

total_bucket_sum += count
i += 1
end
Expand Down Expand Up @@ -129,16 +129,16 @@ def setup
def test_validation

# Range cannot be 0
assert_raises(ArgumentError) {bad_stats = Aggregate.new(32,32,4)}
assert_raises(ArgumentError) { Aggregate.new(32,32,4) }

# Range cannot be negative
assert_raises(ArgumentError) {bad_stats = Aggregate.new(32,16,4)}
assert_raises(ArgumentError) { Aggregate.new(32,16,4) }

# Range cannot be < single bucket
assert_raises(ArgumentError) {bad_stats = Aggregate.new(16,32,17)}
assert_raises(ArgumentError) { Aggregate.new(16,32,17) }

# Range % width must equal 0 (for now)
assert_raises(ArgumentError) {bad_stats = Aggregate.new(1,16384,1024)}
assert_raises(ArgumentError) { Aggregate.new(1,16384,1024) }
end

#XXX: Update test_bucket_contents() if you muck with @@DATA
Expand Down

0 comments on commit cb2154b

Please sign in to comment.