Permalink
Browse files

Add tests for bootstrap-estimate and bootstrap-bca

  • Loading branch information...
1 parent 9ed9016 commit 5cba0c5dc184305c2136fa37aebfec5335c2b14e @hugoduncan committed Aug 17, 2012
Showing with 24 additions and 4 deletions.
  1. +15 −0 test/criterium/core_test.clj
  2. +9 −4 test/criterium/stats_test.clj
View
15 test/criterium/core_test.clj
@@ -44,3 +44,18 @@
(juxt criterium.stats/mean criterium.stats/variance)
100
criterium.well/well-rng-1024a))))
+
+(deftest bootstrap-bca-test
+ (let [ci 0.95]
+ (is (= [1 [1 1]]
+ (bootstrap-bca (take 20 (repeatedly (constantly 1)))
+ criterium.stats/mean
+ 100
+ [0.5 ci (- 1.0 ci)]
+ criterium.well/well-rng-1024a)))
+ (is (= [ [1 [1 1]] [0.0 [0.0 0.0]]]
+ (bootstrap-bca (take 20 (repeatedly (constantly 1)))
+ (juxt criterium.stats/mean criterium.stats/variance)
+ 100
+ [0.5 ci (- 1.0 ci)]
+ criterium.well/well-rng-1024a)))))
View
13 test/criterium/stats_test.clj
@@ -3,6 +3,9 @@
criterium.stats)
(:require criterium.well))
+(defmacro test-max-error [expected actual max-error]
+ `(is (< (Math/abs (- ~expected ~actual)) ~max-error)))
+
(deftest mean-test
(is (= 1 (mean (take 20 (repeatedly (constantly 1))))))
(is (= 3 (mean (range 0 7)))))
@@ -37,15 +40,17 @@
(deftest bootstrap-estimate-test
(is (= [1 0.0 [1.0 1.0]]
- (bootstrap-estimate (take 20 (repeatedly (constantly 1)))))))
+ (bootstrap-estimate (take 20 (repeatedly (constantly 1))))))
+ (let [[m s [l u]] (bootstrap-estimate (take 1000000 (repeatedly rand)))]
+ (is (test-max-error 0.5 m 1e-2))
+ (is (test-max-error 0 l 0.2))
+ (is (test-max-error 1 u 0.2))
+ (is (test-max-error 0.0833 s 0.2))))
(deftest bootstrap-estimate-scale-test
(is (= [1e-9 [1e-8 1e-8]]
(scale-bootstrap-estimate [1 1 [10 10]] 1e-9))))
-(defmacro test-max-error [expected actual max-error]
- `(is (< (Math/abs (- ~expected ~actual)) ~max-error)))
-
;; Values from R, qnorm (with options(digits=15))
(deftest normal-quantile-test
(is (pos? (normal-quantile 0.5001)))

0 comments on commit 5cba0c5

Please sign in to comment.