Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a way to access descriptive statistics in case it is desired to keep the collection pristine.
- Loading branch information
1 parent
23c656e
commit ad3a69a
Showing
8 changed files
with
105 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require 'forwardable' | ||
|
||
module DescriptiveStatistics | ||
|
||
class Stats | ||
extend Forwardable | ||
|
||
DescriptiveStatistics.instance_methods.each do |m| | ||
def_delegator :@collection, m | ||
end | ||
|
||
def initialize(collection) | ||
@collection = collection.clone.extend(DescriptiveStatistics) | ||
end | ||
|
||
end | ||
|
||
end |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
require 'rspec' | ||
|
||
describe "DescriptiveStatistics::Stats" do | ||
require 'descriptive_statistics/safe' | ||
|
||
context "calculated from a Stats object" do | ||
|
||
subject { DescriptiveStatistics::Stats.new([2,6,9,3,5,1,8,3,6,9,2]) } | ||
|
||
it "calculates the number" do | ||
expect(subject.number).to eql(11.0) | ||
end | ||
|
||
it "calculates the sum" do | ||
expect(subject.sum).to eql(54.0) | ||
end | ||
|
||
it "calculates the mean" do | ||
expect(subject.mean).to eql(4.909090909090909) | ||
end | ||
|
||
it "calculates the median" do | ||
expect(subject.median).to eql(5.0) | ||
end | ||
|
||
it "calculates the variance" do | ||
expect(subject.variance).to eql(7.7190082644628095) | ||
end | ||
|
||
it "calculates the standard_deviation" do | ||
expect(subject.standard_deviation).to eql(2.778310325442932) | ||
end | ||
|
||
it "calculates the percentile" do | ||
expect(subject.percentile(30)).to eql(3.0) | ||
expect(subject.percentile(50)).to eql(5.0) | ||
expect(subject.percentile(70)).to eql(6.0) | ||
end | ||
|
||
it "calculates the same value for the 50th percentile and median" do | ||
expect(subject.percentile(50)).to eql(subject.median) | ||
end | ||
|
||
it "calculates the mode" do | ||
expect(subject.mode).to eql(2) | ||
end | ||
|
||
it "calculates the range" do | ||
expect(subject.range).to eql(8.0) | ||
end | ||
|
||
it "calculates the percentile rank" do | ||
expect(subject.percentile_rank(8)).to eql(81.81818181818183) | ||
end | ||
|
||
end | ||
|
||
end |