Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Commit

Permalink
Add min/max delegations
Browse files Browse the repository at this point in the history
  • Loading branch information
jtescher committed Oct 2, 2012
1 parent 17af1da commit d2e0e32
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,6 +3,7 @@
.bundle
.config
.yardoc
.idea
Gemfile.lock
InstalledFiles
_yardoc
Expand Down
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -33,6 +33,8 @@ stats.mode #=> 1
```ruby
stats = DescriptiveStatistics.new([1,1,2,3,10])
stats.range #=> 9
stats.min #=> 1
stats.range #=> 10
stats.percentile_from_value(10) #=> 80
stats.value_from_percentile(60) #=> 3
```
Expand Down
2 changes: 1 addition & 1 deletion lib/descriptive-statistics.rb
Expand Up @@ -15,5 +15,5 @@ def initialize(data)
@data = data
end

def_delegators :@data, :length, :inject, :sort, :each, :each_with_object
def_delegators :@data, :length, :inject, :sort, :each, :each_with_object, :min, :max
end
20 changes: 20 additions & 0 deletions spec/lib/descriptive-statistics/dispersion_spec.rb
Expand Up @@ -11,6 +11,26 @@
end
end

describe '#min' do
it 'delegates to array' do
DescriptiveStatistics.new([1,2,6]).min.should == 1
end

it 'returns nil if empty' do
DescriptiveStatistics.new([]).min.should be_nil
end
end

describe '#max' do
it 'delegates to array' do
DescriptiveStatistics.new([1,2,6]).max.should == 6
end

it 'returns nil if empty' do
DescriptiveStatistics.new([]).max.should be_nil
end
end

describe '#percentile_from_value' do
it 'returns the precise percentile of each value' do
data = [95.1772, 95.1567, 95.1937, 95.1959, 95.1442, 95.061, 95.1591, 95.1195,95.1065, 95.0925, 95.199, 95.1682]
Expand Down

0 comments on commit d2e0e32

Please sign in to comment.