Skip to content

Instantly share code, notes, and snippets.

@viebel
Last active July 17, 2022 21:52
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 viebel/87779408b73cb47f61b8faa775e6e328 to your computer and use it in GitHub Desktop.
Save viebel/87779408b73cb47f61b8faa775e6e328 to your computer and use it in GitHub Desktop.
(ns my.test
(:require [cljs.math :as m]
[clojure.test.check :as tc]
[clojure.test.check.generators :as gen]
[clojure.test.check.properties :as prop :include-macros true]))
(defn d= [a b] (or (= a b) (and (js/isNaN a) (js/isNaN b))))
(def safe-integer (gen/choose js/Number.MIN_SAFE_INTEGER js/Number.MAX_SAFE_INTEGER))
[
(:result (tc/quick-check 100
(prop/for-all [v gen/double]
(d= (m/cos v) (Math/cos v)))))
(:result (tc/quick-check 100
(prop/for-all [v gen/double]
(d= (m/tan v) (Math/tan v)))))
(:result (tc/quick-check 100
(prop/for-all [v gen/double]
(d= (m/asin v) (Math/asin v)))))
(:result (tc/quick-check 100
(prop/for-all [v gen/double]
(d= (m/acos v) (Math/acos v)))))
(:result (tc/quick-check 100
(prop/for-all [v gen/double]
(d= (m/atan v) (Math/atan v)))))
(:result (tc/quick-check 100
(prop/for-all [v gen/double]
(d= (m/exp v) (Math/exp v)))))
(:result (tc/quick-check 100
(prop/for-all [v gen/double]
(d= (m/log v) (Math/log v)))))
(:result (tc/quick-check 100
(prop/for-all [v gen/double]
(d= (m/log10 v) (Math/log10 v)))))
(:result (tc/quick-check 100
(prop/for-all [v gen/double]
(d= (m/sqrt v) (Math/sqrt v)))))
(:result (tc/quick-check 100
(prop/for-all [v gen/double]
(d= (m/cbrt v) (Math/cbrt v)))))
(:result (tc/quick-check 100
(prop/for-all [y gen/double x gen/double]
(d= (m/atan2 y x) (Math/atan2 y x)))))
(:result (tc/quick-check 100
(prop/for-all [a gen/double b gen/double]
(d= (m/pow a b) (Math/pow a b)))))
(:result (tc/quick-check 100
(prop/for-all [v gen/double]
(d= (m/sinh v) (Math/sinh v)))))
(:result (tc/quick-check 100
(prop/for-all [v gen/double]
(d= (m/cosh v) (Math/cosh v)))))
(:result (tc/quick-check 100
(prop/for-all [v gen/double]
(d= (m/tanh v) (Math/tanh v)))))
(:result (tc/quick-check 100
(prop/for-all [x gen/double y gen/double]
(d= (m/hypot x y) (Math/hypot x y)))))
(:result (tc/quick-check 100
(prop/for-all [v gen/double]
(d= (m/expm1 v) (Math/expm1 v)))))
(:result (tc/quick-check 100
(prop/for-all [v gen/double]
(d= (m/log1p v) (Math/log1p v)))))
;; The following test functions that have been implemented by cljs-math
(:result (tc/quick-check 1000
(prop/for-all [v gen/double]
(d= (m/to-radians v) (Math/toRadians v)))))
(:result (tc/quick-check 1000
(prop/for-all [v gen/double]
(d= (m/to-degrees v) (Math/toDegrees v)))))
(:result (tc/quick-check 1000
(prop/for-all [dividend gen/double divisor gen/double]
(d= (m/IEEE-remainder dividend divisor) (Math/IEEEremainder dividend divisor)))))
(:result (tc/quick-check 1000
(prop/for-all [v gen/double]
(d= (m/ceil v) (Math/ceil v)))))
(:result (tc/quick-check 1000
(prop/for-all [v gen/double]
(d= (m/floor v) (Math/floor v)))))
(:result (tc/quick-check 1000
(prop/for-all [magnitude gen/double sign gen/double]
(d= (m/copy-sign magnitude sign) (Math/copySign magnitude sign)))))
(:result (tc/quick-check 1000
(prop/for-all [a gen/double]
(d= (m/rint a) (Math/rint a)))))
(:result (tc/quick-check 1000
(prop/for-all [x safe-integer y (gen/such-that #(not= % 0) safe-integer)]
(= (m/floor-div x y) (Math/floorDiv ^long x ^long y)))))
(:result (tc/quick-check 1000
(prop/for-all [x safe-integer y (gen/such-that #(not= % 0) safe-integer)]
(= (m/floor-mod x y) (Math/floorMod ^long x ^long y))))) ;; type hints to avoid CLJ-2674
(:result (tc/quick-check 1000
(prop/for-all [d gen/double]
(d= (m/signum d) (Math/signum d)))))
(:result (tc/quick-check 1000
(prop/for-all [start gen/double direction gen/double]
(d= (m/next-after start direction) (Math/nextAfter start direction)))))
(:result (tc/quick-check 1000
(prop/for-all [d gen/double]
(d= (m/next-up d) (Math/nextUp d)))))
(:result (tc/quick-check 1000
(prop/for-all [d gen/double]
(d= (m/next-down d) (Math/nextDown d)))))
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment