metrics-clojure / test / metrics / test / histograms.clj

(ns metrics.test.histograms
  (:require [metrics.histograms :as histograms])
  (:use [metrics.test.utils])
  (:use [clojure.test]))


(deftest test-mean
  (let [h (histograms/histogram ["test" "histograms" "test-mean"])]
    (is (= (histograms/mean h) 0))
    (histograms/update! h 5)
    (is (= (histograms/mean h) 5))
    (histograms/update! h 15)
    (is (= (histograms/mean h) 10))))

(deftest test-number-recorded
  (let [h (histograms/histogram ["test" "histograms" "test-number-recorded"])]
    (is (= (histograms/number-recorded h) 0))
    (histograms/update! h 0)
    (is (= (histograms/number-recorded h) 1))
    (histograms/update! h 0)
    (is (= (histograms/number-recorded h) 2))))

(deftest test-std-dev
  (let [h (histograms/histogram ["test" "histograms" "test-std-dev"])]
    (is (= (histograms/std-dev h) 0))
    (histograms/update! h 2)
    (histograms/update! h 4)
    (histograms/update! h 6)
    (is (= (histograms/std-dev h) 2))))

(deftest test-smallest
  (let [h (histograms/histogram ["test" "histograms" "test-smallest"])]
    (is (= (histograms/smallest h) 0))
    (histograms/update! h 1)
    (histograms/update! h 9)
    (histograms/update! h 3)
    (is (= (histograms/smallest h) 1))))

(deftest test-largest
  (let [h (histograms/histogram ["test" "histograms" "test-largest"])]
    (is (= (histograms/largest h) 0))
    (histograms/update! h 1)
    (histograms/update! h 9)
    (histograms/update! h 3)
    (is (= (histograms/largest h) 9))))

(deftest test-percentiles
  (let [h (histograms/histogram ["test" "histograms" "test-percentiles"])]
    (is (maps-within-one (histograms/percentiles h)
                    {0.75 0, 0.95 0, 0.99 0, 0.999 0, 1.00 0}))

    (dorun (map (partial histograms/update! h) (range 1 101)))

    (is (maps-within-one (histograms/percentiles h)
                    {0.75 75, 0.95 95, 0.99 99, 0.999 100, 1.00 100}))

    (is (maps-within-one (histograms/percentiles h [0.10 0.50])
                    {0.10 10, 0.50 50}))))

(deftest test-clear
  (let [h (histograms/histogram ["test" "histograms" "test-clear"])]
    (is (= (histograms/mean h) 0))
    (histograms/update! h 5)
    (is (= (histograms/mean h) 5))
    (histograms/clear! h)
    (is (= (histograms/mean h) 0))))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.