Skip to content

Instantly share code, notes, and snippets.

@luxbock luxbock/core.clj
Created Jan 24, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.