Commits

Meikel Brandmeyer  committed acb0d44

Reload ClojureCheck

  • Participants
  • Parent commits cb69004

Comments (0)

Files changed (6)

+syntax: glob
+
+.gradle/*
+build/*
-Copyright 2008 (c) Meikel Brandmeyer.
+Copyright 2008,2010 © Meikel Brandmeyer.
 All rights reserved.
 
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
 
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
 
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.

File README.markdown

+# ClojureCheck – Property based testing for Clojure
+
+*ClojureCheck* is an addon for `clojure.test`. It adds property based
+testing to *clojure.test* following the lines of [*QuickCheck*][qc] for
+Haskell.
+
+## Properties
+
+Testing with *ClojureCheck* is done via so-called properties. A property
+consists of a set of bindings, which vary between trials, and „normal“
+`clojure.test` assertions. The assertions are run several times. Each
+time the defined locals are bound to new values generated automatically
+by *ClojureCheck*.
+
+## Example
+
+    (ns my.package
+      (:use clojure.test)
+      (:require [clojurecheck.core :as cc]))
+
+    (defn angular-diff
+      [a b]
+      (-> (- a b) (mod 180) Math/abs))
+
+    (deftest angular-diff-standard-test
+      (are [x y] (= x y)
+        (angular-diff   0   0) 0
+        (angular-diff  90  90) 0
+        (angular-diff   0  45) 45
+        (angular-diff  45   0) 45
+        (angular-diff   0 270) 90
+        (angular-diff (* 360 2) (+ (* 360 4) 23)) 23))
+
+    (deftest angular-diff-property
+      (cc/property "angular-diff is smallest angel between a and b"
+        [diff (cc/float :lower -180.0 :upper 180.0)
+         a    (cc/float :lower 0.0 :upper 360.0)
+         n    (cc/int)]
+        (let [b (+ a (* 360 n) diff)]
+          (is (= (angular-diff a b) (Math/abs diff))))))
+
+## Installation
+
+To use *ClojureCheck* add it to your project dependencies. lein, maven,
+gradle or ivy can then fetch it from clojars.
+
+For lein:
+
+    :dev-dependencies [[clojurecheck 1.0.0]]
+
+For gradle:
+
+    dependencies { testCompile 'clojurecheck:clojurecheck:1.0.0' }
+
+## Contact
+
+I always appreciate feedback. Please report bugs on the tracker at
+bitbucket: <http://bitbucket.org/kotarak/clojurecheck/issues>. Also
+improvement ideas etc. are always welcome!
+
+Meikel Brandmeyer <mb@kotka.de>
+Erlensee, Germany, 2010

File build.gradle

+buildscript {
+    repositories {
+        flatDir name: 'gradleHome',
+                dirs: System.getenv('GRADLE_HOME') + '/lib/plugins'
+    }
+    dependencies {
+        classpath 'clojuresque:clojuresque:1.4.0-SNAPSHOT'
+    }
+}
+
+apply plugin: 'clojure'
+
+version = '2.0.0-SNAPSHOT'
+group = 'clojurecheck'
+
+clojureSnapshotsRepo repositories
+gradleHomeRepo repositories
+
+dependencies {
+    compile 'org.clojure:clojure:1.2.0-master-SNAPSHOT'
+
+    development 'vimclojure:vimclojure:2.2.0-SNAPSHOT'
+}
+
+configureClojarsDeploy uploadArchives

File settings.gradle

+rootProject.name = 'clojurecheck'

File src/main/clojure/clojurecheck/core.clj

+; Copyright 2010 © Meikel Brandmeyer.
+; All rights reserved.
+; 
+; Permission is hereby granted, free of charge, to any person obtaining a
+; copy of this software and associated documentation files (the "Software"),
+; to deal in the Software without restriction, including without limitation
+; the rights to use, copy, modify, merge, publish, distribute, sublicense,
+; and/or sell copies of the Software, and to permit persons to whom the
+; Software is furnished to do so, subject to the following conditions:
+; 
+; The above copyright notice and this permission notice shall be included
+; in all copies or substantial portions of the Software.
+; 
+; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+; OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+; THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+; DEALINGS IN THE SOFTWARE.
+
+(ns ^{:author "Meikel Brandmeyer"
+      :doc
+  "clojurecheck - property based testing
+
+  clojurecheck is an extensions to clojure.test. It provides generators
+  for different values and datastructures. With their help random input
+  for test cases are generated to test the behaviour of the code under
+  test with more and more complex input.
+
+  Example:
+    (ns my.package
+      (:use clojure.test)
+      (:require [clojurecheck.core :as cc]))
+
+    (defn angular-diff
+      [a b]
+      (-> (- a b) (mod 180) Math/abs))
+
+    (deftest angular-diff-standard-test
+      (are [x y] (= x y)
+        (angular-diff   0   0) 0
+        (angular-diff  90  90) 0
+        (angular-diff   0  45) 45
+        (angular-diff  45   0) 45
+        (angular-diff   0 270) 90
+        (angular-diff (* 360 2) (+ (* 360 4) 23)) 23))
+
+    (deftest angular-diff-property
+      (cc/property „angular-diff is smallest angel between a and b“
+        [diff (cc/float :lower -180.0 :upper 180.0)
+         a    (cc/float :lower 0.0 :upper 360.0)
+         n    (cc/int)]
+        (let [b (+ a (* 360 n) diff)]
+          (is (= (angular-diff a b) (Math/abs diff))))))
+
+  And a result:
+    user=> (run-tests)
+    Testing my.package
+
+    FAIL in (angular-diff-property) (core.clj:288)
+    falsified angular-diff is smallest angel between a and b in 3 attempts
+    inputs where:
+      diff = 1.3374370509881066
+      a = 0.5071098240831757
+      n = -1
+    failed assertions where:
+      expected: (= (angular-diff a b) (Math/abs diff))
+        actual: (not (= 178.66256294901189 1.3374370509881066))
+
+    Ran 2 tests containing 7 assertions.
+    1 failures, 0 errors.
+    {:type :summary, :test 2, :pass 6, :fail 1, :error 0}"}
+  clojurecheck.core
+  (:use clojure.test))