Permalink
Browse files

slightly better histogram tests, and two resulting bugfixes

  • Loading branch information...
1 parent 5943497 commit 404bcce5872443ab0f49d951d53771b09bf66e78 @argv0 argv0 committed Sep 1, 2011
Showing with 18 additions and 14 deletions.
  1. +1 −1 c_src/histogram_metric.hpp
  2. +2 −2 c_src/sample.hpp
  3. +15 −11 src/basho_metrics_nifs.erl
View
2 c_src/histogram_metric.hpp
@@ -163,7 +163,7 @@ class histogram
{
if (count_ <= 1)
return 0.0;
- return variance_.first / (count_- 1);
+ return variance_.second / (count_- 1);
}
void update_variance(IntType value)
View
4 c_src/sample.hpp
@@ -208,7 +208,7 @@ struct uniform_sample
std::fill_n(values_.begin(), size_, 0);
}
- std::size_t size()
+ std::size_t size() const
{
return std::min(count_, size_);
}
@@ -226,7 +226,7 @@ struct uniform_sample
std::vector<IntType> values() const
{
- return values_;
+ return std::vector<IntType>(values_.begin(), values_.begin()+size());
}
private:
View
26 src/basho_metrics_nifs.erl
@@ -123,17 +123,21 @@ meter_tick(_Ref) ->
%% ===================================================================
-ifdef(TEST).
-simple_test() ->
- {ok, H} = ?MODULE:histogram_new(),
- [?MODULE:histogram_update(H, I) || I <- lists:seq(0, 1000000)],
- [{min,0},
- {max,1000000},
- {mean,500000},
- {count,1000001},
- {stddev,0},
- {p50,514255},
- {p95,956215},
- {p99,991377}] = ?MODULE:histogram_stats(H).
+close_to(X, N, Delta) ->
+ abs(X-N) < Delta.
+
+histogram_test() ->
+ {ok, H} = ?MODULE:histogram_new([{size, 1000}]),
+ [?MODULE:histogram_update(H, I) || I <- lists:seq(1, 10000)],
+ Stats = ?MODULE:histogram_stats(H),
+ ?assertEqual(proplists:get_value(min, Stats), 1),
+ ?assertEqual(proplists:get_value(max, Stats), 10000),
+ ?assertEqual(proplists:get_value(count, Stats), 10000),
+ ?assert(close_to(proplists:get_value(stddev, Stats), 2886, 10)),
+ ?assert(close_to(proplists:get_value(mean, Stats), 5000, 100)),
+ ?assert(close_to(proplists:get_value(p50, Stats), 5000, 100)),
+ ?assert(close_to(proplists:get_value(p95, Stats), 9500, 100)),
+ ?assert(close_to(proplists:get_value(p99, Stats), 9900, 100)).
-endif.

0 comments on commit 404bcce

Please sign in to comment.