forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for mean, gmean, hmean and wmean
- Loading branch information
1 parent
79ba6ac
commit c9d4812
Showing
2 changed files
with
24 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using Stats | ||
using Base.Test | ||
|
||
@test_approx_eq mean([1, 2, 3]) 2.0 | ||
@test_approx_eq mean(1:3) 2.0 | ||
|
||
@test_approx_eq gmean([1, 2, 3]) (6.0)^(1/3) | ||
@test_approx_eq gmean(1:3) (6.0)^(1/3) | ||
@test_approx_eq gmean([2, 8]) 4.0 | ||
@test_approx_eq gmean([4, 1, 1/32]) 0.5 | ||
|
||
@test_approx_eq hmean([1, 2, 3]) 3 / (1 + 1/2 + 1/3) | ||
@test_approx_eq hmean(1:3) 3 / (1 + 1/2 + 1/3) | ||
@test_approx_eq hmean([1, 2, 4]) 12 / 7 | ||
|
||
@test_approx_eq wmean([1, 2, 3], [1/3, 1/3, 1/3]) 2.0 | ||
@test_approx_eq wmean([1, 2, 3], [1.0, 0.0, 0.0]) 1.0 | ||
@test_approx_eq wmean([1, 2, 3], [0.0, 1.0, 0.0]) 2.0 | ||
@test_approx_eq wmean([1, 2, 3], [0.0, 0.0, 1.0]) 3.0 | ||
@test_approx_eq wmean([1, 2, 3], [0.5, 0.0, 0.5]) 2.0 | ||
@test_approx_eq wmean([1, 2, 3], [0.5, 0.5, 0.0]) 1.5 | ||
@test_approx_eq wmean([1, 2, 3], [0.0, 0.5, 0.5]) 2.5 |