-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* basic properties for statistex * Fix lists full of negative floats breaking the ratio property We want to be the display of percentage to be always positive which wasn't the case if the average was negative. * Harden test suite showing why the length 1 clause is necessary property tests would catch this as well with an arithmetic error but I think the dicymentation gain from the doc tests is still very much worth it. * Failing percentile property No Internet atm to research what correct behaviour even looks like it. * I obviously know how to mark something pending... cough * fix our percentile misfortunes, we missed a clause * fix formatter error with access to stream_data
- Loading branch information
Showing
7 changed files
with
126 additions
and
36 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 |
---|---|---|
|
@@ -5,5 +5,6 @@ | |
"mix/**/*.{ex,exs}", | ||
"./mix.exs", | ||
"samples/**/*.{ex,exs}" | ||
] | ||
], | ||
import_deps: [:stream_data] | ||
] |
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
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,4 +1,56 @@ | ||
defmodule Statistex.StatistexTest do | ||
use ExUnit.Case, async: true | ||
doctest Statistex | ||
|
||
use ExUnitProperties | ||
import Statistex | ||
import StreamData | ||
|
||
describe "property testing as we might get loads of data" do | ||
property "doesn't blow up no matter what kind of nonempty list of floats it's given" do | ||
check all samples <- list_of(float(), min_length: 1) do | ||
stats = statistics(samples) | ||
|
||
assert stats.sample_size >= 1 | ||
assert stats.minimum <= stats.maximum | ||
|
||
assert stats.minimum <= stats.average | ||
assert stats.average <= stats.maximum | ||
|
||
assert stats.minimum <= stats.median | ||
assert stats.median <= stats.maximum | ||
|
||
assert stats.median == stats.percentiles[50] | ||
|
||
assert stats.standard_deviation >= 0 | ||
assert stats.standard_deviation_ratio >= 0 | ||
|
||
# mode actually occurs in the samples | ||
case stats.mode do | ||
[_ | _] -> | ||
Enum.each(stats.mode, fn mode -> | ||
assert(mode in samples) | ||
end) | ||
|
||
# nothing to do there is no real mode | ||
nil -> | ||
nil | ||
|
||
mode -> | ||
assert mode in samples | ||
end | ||
end | ||
end | ||
|
||
property "percentiles are correctly related to each other" do | ||
check all samples <- list_of(float(), min_length: 1) do | ||
percies = percentiles(samples, [25, 50, 75, 90, 99]) | ||
|
||
assert percies[25] <= percies[50] | ||
assert percies[50] <= percies[75] | ||
assert percies[75] <= percies[90] | ||
assert percies[90] <= percies[99] | ||
end | ||
end | ||
end | ||
end |