From 6fe433b57993a50eb365f0a2efec40c846084ae8 Mon Sep 17 00:00:00 2001 From: Peter Taoussanis Date: Thu, 13 Jun 2013 00:00:29 +0700 Subject: [PATCH] Update tests, migrate to Expectations lib --- project.clj | 11 ++++++++--- src/taoensso/nippy/benchmarks.clj | 12 +++++++++--- test/taoensso/nippy/tests/main.clj | 26 ++++++++++++++++++++++++++ test/test_nippy/main.clj | 30 ------------------------------ 4 files changed, 43 insertions(+), 36 deletions(-) create mode 100644 test/taoensso/nippy/tests/main.clj delete mode 100644 test/test_nippy/main.clj diff --git a/project.clj b/project.clj index ef4fc72..0d236b5 100644 --- a/project.clj +++ b/project.clj @@ -4,13 +4,18 @@ :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} :dependencies [[org.clojure/clojure "1.3.0"] + [expectations "1.4.43"] [org.iq80.snappy/snappy "0.3"]] :profiles {:1.3 {:dependencies [[org.clojure/clojure "1.3.0"]]} :1.4 {:dependencies [[org.clojure/clojure "1.4.0"]]} :1.5 {:dependencies [[org.clojure/clojure "1.5.1"]]} :dev {:dependencies []} :test {:dependencies [[org.xerial.snappy/snappy-java "1.0.5-M3"]]}} - :aliases {"test-all" ["with-profile" "test,1.3:test,1.4:test,1.5" "test"]} - :plugins [[codox "0.6.4"]] + :aliases {"test-all" ["with-profile" "test,1.3:test,1.4:test,1.5" "expectations"] + "test-auto" ["with-profile" "test" "autoexpect"] + "start-dev" ["with-profile" "dev,test" "repl" ":headless"]} + :plugins [[lein-expectations "0.0.7"] + [lein-autoexpect "0.2.5"] + [codox "0.6.4"]] :min-lein-version "2.0.0" - :warn-on-reflection true) \ No newline at end of file + :warn-on-reflection true) diff --git a/src/taoensso/nippy/benchmarks.clj b/src/taoensso/nippy/benchmarks.clj index 3765b94..64c5012 100644 --- a/src/taoensso/nippy/benchmarks.clj +++ b/src/taoensso/nippy/benchmarks.clj @@ -6,7 +6,7 @@ ;; Remove stuff from stress-data that breaks reader (def data (dissoc nippy/stress-data :queue :queue-empty :bytes)) -(defmacro bench [& body] `(utils/bench 10000 (do ~@body) :warmup-laps 1000)) +(defmacro bench [& body] `(utils/bench 10000 (do ~@body) :warmup-laps 2000)) (defn reader-freeze [x] (binding [*print-dup* false] (pr-str x))) (defn reader-thaw [x] (binding [*read-eval* false] (read-string x))) @@ -18,8 +18,14 @@ (def roundtrip-fast (comp #(nippy/thaw-from-bytes % :compressed? false) #(nippy/freeze-to-bytes % :compress? false))) -(defn autobench [] {:defaults (bench (roundtrip-defaults data)) - :encrypted (bench (roundtrip-encrypted data))}) +(defn autobench [] + (println "Benchmarking roundtrips") + (println "-----------------------") + (let [results {:defaults (bench (roundtrip-defaults data)) + :encrypted (bench (roundtrip-encrypted data)) + :fast (bench (roundtrip-fast data))}] + (println results) + results)) (comment diff --git a/test/taoensso/nippy/tests/main.clj b/test/taoensso/nippy/tests/main.clj new file mode 100644 index 0000000..aa1ff62 --- /dev/null +++ b/test/taoensso/nippy/tests/main.clj @@ -0,0 +1,26 @@ +(ns taoensso.nippy.tests.main + (:use [expectations :as test]) + (:require [taoensso.nippy :as nippy] + [taoensso.nippy.benchmarks :as benchmarks])) + +;; Remove stuff from stress-data that breaks roundtrip equality +(def test-data (dissoc nippy/stress-data :bytes)) + +(def roundtrip-defaults (comp nippy/thaw-from-bytes nippy/freeze-to-bytes)) +(def roundtrip-encrypted (comp #(nippy/thaw-from-bytes % :password [:cached "secret"]) + #(nippy/freeze-to-bytes % :password [:cached "secret"]))) + +(expect test-data (roundtrip-defaults test-data)) +(expect test-data (roundtrip-encrypted test-data)) +(expect ; Snappy lib compatibility + (let [thaw #(nippy/thaw-from-bytes % :compressed? false) + ^bytes raw-ba (nippy/freeze-to-bytes test-data :compress? false) + ^bytes xerial-ba (org.xerial.snappy.Snappy/compress raw-ba) + ^bytes iq80-ba (org.iq80.snappy.Snappy/compress raw-ba)] + (= (thaw raw-ba) + (thaw (org.xerial.snappy.Snappy/uncompress xerial-ba)) + (thaw (org.xerial.snappy.Snappy/uncompress iq80-ba)) + (thaw (org.iq80.snappy.Snappy/uncompress iq80-ba 0 (alength iq80-ba))) + (thaw (org.iq80.snappy.Snappy/uncompress xerial-ba 0 (alength xerial-ba)))))) + +(expect (benchmarks/autobench)) \ No newline at end of file diff --git a/test/test_nippy/main.clj b/test/test_nippy/main.clj deleted file mode 100644 index 30a11d1..0000000 --- a/test/test_nippy/main.clj +++ /dev/null @@ -1,30 +0,0 @@ -(ns test-nippy.main - (:use [clojure.test]) - (:require [taoensso.nippy :as nippy] - [taoensso.nippy.benchmarks :as benchmarks])) - -;; Remove stuff from stress-data that breaks roundtrip equality -(def test-data (dissoc nippy/stress-data :bytes)) - -(def roundtrip-defaults (comp nippy/thaw-from-bytes nippy/freeze-to-bytes)) -(def roundtrip-encrypted (comp #(nippy/thaw-from-bytes % :password [:cached "secret"]) - #(nippy/freeze-to-bytes % :password [:cached "secret"]))) -(deftest test-roundtrip-defaults (is (= test-data (roundtrip-defaults test-data)))) -(deftest test-roundtrip-encrypted (is (= test-data (roundtrip-encrypted test-data)))) - -(println "Benchmarking roundtrips (x3)") -(println "----------------------------") -(println (benchmarks/autobench)) -(println (benchmarks/autobench)) -(println (benchmarks/autobench)) - -(deftest test-snappy-library-compatibility - (let [thaw #(nippy/thaw-from-bytes % :compressed? false) - ^bytes raw-ba (nippy/freeze-to-bytes test-data :compress? false) - ^bytes xerial-ba (org.xerial.snappy.Snappy/compress raw-ba) - ^bytes iq80-ba (org.iq80.snappy.Snappy/compress raw-ba)] - (is (= (thaw raw-ba) - (thaw (org.xerial.snappy.Snappy/uncompress xerial-ba)) - (thaw (org.xerial.snappy.Snappy/uncompress iq80-ba)) - (thaw (org.iq80.snappy.Snappy/uncompress iq80-ba 0 (alength iq80-ba))) - (thaw (org.iq80.snappy.Snappy/uncompress xerial-ba 0 (alength xerial-ba))))))) \ No newline at end of file