Skip to content

Commit

Permalink
Add tests for mean, gmean, hmean and wmean
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmyleswhite committed Sep 22, 2013
1 parent 79ba6ac commit c9d4812
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion run_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

using Stats

my_tests = ["test/01.jl"]
my_tests = ["test/01.jl"
"test/means.jl"]
#"test/statquiz.jl"]

println("Running tests:")
Expand Down
22 changes: 22 additions & 0 deletions test/means.jl
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

0 comments on commit c9d4812

Please sign in to comment.