Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support collections with a single value
For collections of a single value, percentile was raising an exception. This was resolved by simply returning the single value (converted to a Float) in this case.
- Loading branch information
1 parent
be67232
commit 23c656e
Showing
6 changed files
with
66 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
require 'bundler/setup' | ||
require 'bundler/gem_tasks' | ||
require 'rake/testtask' | ||
require 'rspec/core/rake_task' | ||
|
||
Rake::TestTask.new do |t| | ||
t.test_files = FileList['spec/*.rb','test/*.rb'] | ||
t.test_files = FileList['test/*.rb'] | ||
t.verbose = true | ||
end | ||
|
||
task :default => :test | ||
RSpec::Core::RakeTask.new(:spec) | ||
|
||
task :default => [ :test, :spec ] |
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
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" do | ||
require 'descriptive_statistics' | ||
|
||
subject { [2] } | ||
|
||
context "with a single value array" do | ||
|
||
it "calculates the number" do | ||
expect(subject.number).to eql(1.0) | ||
end | ||
|
||
it "calculates the sum" do | ||
expect(subject.sum).to eql(2.0) | ||
end | ||
|
||
it "calculates the mean" do | ||
expect(subject.mean).to eql(2.0) | ||
end | ||
|
||
it "calculates the median" do | ||
expect(subject.median).to eql(2.0) | ||
end | ||
|
||
it "calculates the variance" do | ||
expect(subject.variance).to eql(0.0) | ||
end | ||
|
||
it "calculates the standard_deviation" do | ||
expect(subject.standard_deviation).to eql(0.0) | ||
end | ||
|
||
it "calculates the percentile" do | ||
expect(subject.percentile(30)).to eql(2.0) | ||
expect(subject.percentile(50)).to eql(2.0) | ||
expect(subject.percentile(70)).to eql(2.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(0.0) | ||
end | ||
|
||
it "calculates the percentile rank" do | ||
expect(subject.percentile_rank(2)).to eql(100.0) | ||
end | ||
|
||
end | ||
|
||
end |