Skip to content

Instantly share code, notes, and snippets.

@luxbock
Created January 24, 2017 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luxbock/ecb263750f61cc6fab7a736e5bd96008 to your computer and use it in GitHub Desktop.
Save luxbock/ecb263750f61cc6fab7a736e5bd96008 to your computer and use it in GitHub Desktop.
Instrumenting generators trouble
(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)))
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