Permalink
Browse files

require range to be a multiple of width in linear histogram

  • Loading branch information...
1 parent 6632476 commit 20f0380b16cf7f3f31d521c8310087946391585b @josephruscio committed Sep 12, 2009
Showing with 13 additions and 0 deletions.
  1. +4 −0 lib/aggregate.rb
  2. +9 −0 test/ts_aggregate.rb
View
@@ -48,6 +48,10 @@ def initialize (low=nil, high=nil, width=nil)
raise ArgumentError, "Histogram width must be <= histogram range"
end
+ if 0 != (high - low).modulo(width)
+ raise ArgumentError, "Histogram range (high - low) must be a multiple of width"
+ end
+
@low = low
@high = high
@width = width
View
@@ -120,9 +120,18 @@ def setup
end
def test_validation
+
+ # Range cannot be 0
assert_raise(ArgumentError) {bad_stats = Aggregate.new(32,32,4)}
+
+ # Range cannot be negative
assert_raise(ArgumentError) {bad_stats = Aggregate.new(32,16,4)}
+
+ # Range cannot be < single bucket
assert_raise(ArgumentError) {bad_stats = Aggregate.new(16,32,17)}
+
+ # Range % width must equal 0 (for now)
+ assert_raise(ArgumentError) {bad_stats = Aggregate.new(1,16384,1024)}
end
#XXX: Update test_bucket_contents() if you muck with @@DATA

0 comments on commit 20f0380

Please sign in to comment.