Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

use test.generative's runner, add a few generative tests

Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
  • Loading branch information...
commit 7f69246f17a559119fbad8747100bb7586ff6e92 1 parent a61a703
Stuart Halloway stuarthalloway authored
65 src/script/run_tests.clj
... ... @@ -1,63 +1,2 @@
1   -(ns clojure.test-clojure (:require clojure.test))
2   -
3   -(def test-namespaces '[
4   -clojure.test-clojure.agents
5   -clojure.test-clojure.annotations
6   -clojure.test-clojure.atoms
7   -clojure.test-clojure.clojure-set
8   -clojure.test-clojure.clojure-walk
9   -clojure.test-clojure.clojure-xml
10   -clojure.test-clojure.clojure-zip
11   -clojure.test-clojure.compilation
12   -clojure.test-clojure.control
13   -clojure.test-clojure.data
14   -clojure.test-clojure.data-structures
15   -clojure.test-clojure.def
16   -clojure.test-clojure.errors
17   -clojure.test-clojure.evaluation
18   -clojure.test-clojure.fn
19   -clojure.test-clojure.for
20   -clojure.test-clojure.genclass.examples
21   -clojure.test-clojure.genclass
22   -clojure.test-clojure.java.io
23   -clojure.test-clojure.java.javadoc
24   -clojure.test-clojure.java.shell
25   -clojure.test-clojure.java-interop
26   -clojure.test-clojure.keywords
27   -clojure.test-clojure.load
28   -clojure.test-clojure.logic
29   -clojure.test-clojure.macros
30   -clojure.test-clojure.main
31   -clojure.test-clojure.metadata
32   -clojure.test-clojure.multimethods
33   -clojure.test-clojure.ns-libs
34   -clojure.test-clojure.numbers
35   -clojure.test-clojure.other-functions
36   -clojure.test-clojure.parallel
37   -clojure.test-clojure.pprint
38   -clojure.test-clojure.predicates
39   -clojure.test-clojure.printer
40   -clojure.test-clojure.protocols
41   -clojure.test-clojure.protocols.hash-collisions
42   -clojure.test-clojure.reader
43   -clojure.test-clojure.reducers
44   -clojure.test-clojure.reflect
45   -clojure.test-clojure.refs
46   -clojure.test-clojure.repl
47   -clojure.test-clojure.rt
48   -clojure.test-clojure.sequences
49   -clojure.test-clojure.serialization
50   -clojure.test-clojure.special
51   -clojure.test-clojure.string
52   -clojure.test-clojure.test
53   -clojure.test-clojure.test-fixtures
54   -clojure.test-clojure.transients
55   -clojure.test-clojure.try-catch
56   -clojure.test-clojure.vars
57   -clojure.test-clojure.vectors
58   -])
59   -
60   -(apply require test-namespaces)
61   -
62   -(let [results (apply clojure.test/run-tests test-namespaces)]
63   - (System/exit (+ (:error results) (:fail results))))
  1 +(require '[clojure.test.generative.runner :as runner])
  2 +(runner/-main "test")
78 test/clojure/test_clojure/numbers.clj
@@ -13,7 +13,9 @@
13 13
14 14 (ns clojure.test-clojure.numbers
15 15 (:use clojure.test
16   - clojure.template))
  16 + [clojure.test.generative :exclude (is)]
  17 + clojure.template)
  18 + (:require [clojure.test.generative.generators :as gen]))
17 19
18 20
19 21 ; TODO:
@@ -563,3 +565,77 @@ Math/pow overflows to Infinity."
563 565 min
564 566 max))))
565 567
  568 +(defn integer
  569 + "Distribution of integers biased towards the small, but
  570 + including all longs."
  571 + []
  572 + (gen/one-of #(gen/uniform -1 32) gen/byte gen/short gen/int gen/long))
  573 +
  574 +(defn longable?
  575 + [n]
  576 + (try
  577 + (long n)
  578 + true
  579 + (catch Exception _)))
  580 +
  581 +(defspec integer-commutative-laws
  582 + (partial map identity)
  583 + [^{:tag `integer} a ^{:tag `integer} b]
  584 + (if (longable? (+' a b))
  585 + (assert (= (+ a b) (+ b a)
  586 + (+' a b) (+' b a)
  587 + (unchecked-add a b) (unchecked-add b a)))
  588 + (assert (= (+' a b) (+' b a))))
  589 + (if (longable? (*' a b))
  590 + (assert (= (* a b) (* b a)
  591 + (*' a b) (*' b a)
  592 + (unchecked-multiply a b) (unchecked-multiply b a)))
  593 + (assert (= (*' a b) (*' b a)))))
  594 +
  595 +(defspec integer-associative-laws
  596 + (partial map identity)
  597 + [^{:tag `integer} a ^{:tag `integer} b ^{:tag `integer} c]
  598 + (if (every? longable? [(+' a b) (+' b c) (+' a b c)])
  599 + (assert (= (+ (+ a b) c) (+ a (+ b c))
  600 + (+' (+' a b) c) (+' a (+' b c))
  601 + (unchecked-add (unchecked-add a b) c) (unchecked-add a (unchecked-add b c))))
  602 + (assert (= (+' (+' a b) c) (+' a (+' b c))
  603 + (+ (+ (bigint a) b) c) (+ a (+ (bigint b) c)))))
  604 + (if (every? longable? [(*' a b) (*' b c) (*' a b c)])
  605 + (assert (= (* (* a b) c) (* a (* b c))
  606 + (*' (*' a b) c) (*' a (*' b c))
  607 + (unchecked-multiply (unchecked-multiply a b) c) (unchecked-multiply a (unchecked-multiply b c))))
  608 + (assert (= (*' (*' a b) c) (*' a (*' b c))
  609 + (* (* (bigint a) b) c) (* a (* (bigint b) c))))))
  610 +
  611 +(defspec integer-distributive-laws
  612 + (partial map identity)
  613 + [^{:tag `integer} a ^{:tag `integer} b ^{:tag `integer} c]
  614 + (if (every? longable? [(*' a (+' b c)) (+' (*' a b) (*' a c))
  615 + (*' a b) (*' a c) (+' b c)])
  616 + (assert (= (* a (+ b c)) (+ (* a b) (* a c))
  617 + (*' a (+' b c)) (+' (*' a b) (*' a c))
  618 + (unchecked-multiply a (+' b c)) (+' (unchecked-multiply a b) (unchecked-multiply a c))))
  619 + (assert (= (*' a (+' b c)) (+' (*' a b) (*' a c))
  620 + (* a (+ (bigint b) c)) (+ (* (bigint a) b) (* (bigint a) c))))))
  621 +
  622 +(defspec addition-undoes-subtraction
  623 + (partial map identity)
  624 + [^{:tag `integer} a ^{:tag `integer} b]
  625 + (if (longable? (-' a b))
  626 + (assert (= a
  627 + (-> a (- b) (+ b))
  628 + (-> a (unchecked-subtract b) (unchecked-add b)))))
  629 + (assert (= a
  630 + (-> a (-' b) (+' b)))))
  631 +
  632 +(defspec quotient-and-remainder
  633 + (fn [a b] (sort [a b]))
  634 + [^{:tag `integer} a ^{:tag `integer} b]
  635 + (when-not (zero? (second %))
  636 + (let [[a d] %
  637 + q (quot a d)
  638 + r (rem a d)]
  639 + (assert (= a
  640 + (+ (* q d) r)
  641 + (unchecked-add (unchecked-multiply q d) r))))))

0 comments on commit 7f69246

Please sign in to comment.
Something went wrong with that request. Please try again.