active-group / active-quickcheck Goto Github PK
View Code? Open in Web Editor NEWQuickCheck clone
QuickCheck clone
If a spec is defined with an explicit generator (via the :gen
) option, I would expect the property
macro to generate values using that generator.
property
seems to ignore the :gen
clause. Example:
(ns example.check
(:use [active.quickcheck])
(:require [clojure.spec.alpha :as s]
[clojure.test :as t]
[clojure.test.check.generators :as gen]))
(s/def ::nat pos-int?)
(def sure-its-always-4-elems
"A spec that always generates a list of exactly four distinct positive
integers."
(s/spec (s/coll-of ::nat :into [])
:gen (fn []
(gen/list-distinct (s/gen ::nat) {:num-elements 4}))))
;; This works
(s/exercise sure-its-always-4-elems)
;; This doesn't work but instead generates examples with `nil` cases.
(quickcheck
(property [ks (spec sure-its-always-4-elems)]
(let [[a b c d] ks]
(t/is (distinct? a b c d)))))
In this example, exercise
always generates a vector of exactly four distinct numbers. Quickcheck, on the other hand, also generates lists with nil
in them:
FAIL in () (NO_SOURCE_FILE:23)
expected: (distinct? a b c d)
actual: (not (distinct? nil nil nil nil))
Falsifiable, after 0 tests:
ks = []
I would expect quickcheck
to respect the provided gen. Is this a bug or a user-error?
When integrating active.quickcheck
with clojure.test
, one is required to import QuickCheck via :use
. Otherwise, the tests QuickCheck runs will pass but an exception is reported.
(ns active-quickcheck-example.core-test
(:use [active.quickcheck])
(:require [clojure.test :refer :all]))
;; This will pass and NOT produce an exception
(deftest trivial-test
(is (quickcheck
(property [x integer]
(= x x)))))
;; => OK, passed 100 tests.
(ns active-quickcheck-example.core2-test
(:require [clojure.test :refer :all]
[active.quickcheck :as qc]))
;; This will report success but produce an exception
(deftest trivial-test
(is (qs/quickcheck
(qs/property [x integer]
(= x x)))))
;; => OK, passed 100 tests.
Fail in trivial-test
expected: (qs/quickcheck (qs/property [x integer] (= x x)))
actual: (not
(qs/quickcheck
#active.quickcheck.Property-type{:func
#function[active-quickcheck-example.core2-test/fn--17615/fn--17616],
:arg-names (x),
:args
(#active.quickcheck.Arbitrary-type{:generator
#active.clojure.monad.Bind{:monad
#active.quickcheck.Get-size-type{},
:cont
#function[active.quickcheck/sized/fn--14763]}})}))
Using the property
-macro for generating functions, it will run forever when choosing an "unknown" codomain (such as int
instead of integer
in the example below).
(ns active-quickcheck-example.core-test
(:require [active.quickcheck :as qs]))
;; This one works.
(qs/quickcheck
(qs/property [f (boolean -> boolean)]
(boolean? (f))))
;; => OK, passed 100 tests.
;; This will run forever (?).
(qs/quickcheck
(qs/property [i int
f (int -> int)]
(int? (f i))))
It would be helpful to notify the user that something went wrong.
You can currently use spec only to generate data but not to generate functions that take a spec as domain or range. In order to get there we need to implement coarbitraries for the such-that
and generate-one-of
combinators.
A lot of the combinators such as map-of
take kwargs that modify the specs in some regards. We already implemented some of these kwargs with coll-of
. We should make this implementation work with the other combinators as well.
We need to support more base generators such as symbol? etc. This requires a bit of research first. What base generators does Clojure spec generators support?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.