Created
January 24, 2017 16:48
-
-
Save luxbock/ecb263750f61cc6fab7a736e5bd96008 to your computer and use it in GitHub Desktop.
Instrumenting generators trouble
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns test.core | |
(:require [clojure.spec :as s] | |
[clojure.spec.test :as stest] | |
[clojure.test.check.generators :as gen])) | |
(s/def ::file-count nat-int?) | |
(s/def ::operations (s/map-of keyword? pos-int?)) | |
(s/def ::time-total (s/and double? (complement neg?))) | |
(s/def ::summary-res | |
(s/keys :req-un [::file-count | |
::operations | |
::time-total])) | |
(s/fdef combine-summaries | |
:args (s/cat :xs (s/coll-of ::summary-res :min-count 1)) | |
:ret ::summary-res) | |
(defn combine-summaries | |
[summaries] | |
(letfn [(deep-merge [a b] | |
(merge-with (fn [x y] | |
(if (map? y) | |
(deep-merge x y) | |
(+ x y))) | |
a b))] | |
(reduce deep-merge summaries))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test.core> (->> (stest/check | |
`combine-summaries | |
{:clojure.spec.test.check/opts {:num-tests 1000}}) | |
first | |
stest/abbrev-result) | |
{:spec (fspec | |
:args (cat :xs (coll-of :test.core/summary-res :min-count 1)) | |
:ret :test.core/summary-res | |
:fn nil), | |
:sym test.core/combine-summaries, | |
:failure #object[java.lang.ArithmeticException "0x1c497200" "java.lang.ArithmeticException: integer overflow"]} | |
test.core> (stest/instrument (stest/enumerate-namespace 'test.core) | |
{:gen {::file-count (s/gen (s/int-in 0 1000)) | |
::operations (s/gen (s/map-of keyword? (s/int-in 1 1000))) | |
::time-total (s/gen (s/double-in 0.0 1000.0))}}) | |
[test.core/combine-summaries] | |
test.core> (->> (stest/check | |
`combine-summaries | |
{:clojure.spec.test.check/opts {:num-tests 1000}}) | |
first | |
stest/abbrev-result) | |
{:spec (fspec | |
:args (cat :xs (coll-of :test.core/summary-res :min-count 1)) | |
:ret :test.core/summary-res | |
:fn nil), | |
:sym test.core/combine-summaries, | |
:failure #object[java.lang.ArithmeticException "0x3894d917" "java.lang.ArithmeticException: integer overflow"]} | |
test.core> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment