Mercurial > lasercutter
view src/clojure/contrib/test_contrib/test_math.clj @ 10:ef7dbbd6452c
added clojure source goodness
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 21 Aug 2010 06:25:44 -0400 |
parents | |
children |
line wrap: on
line source
1 (ns clojure.contrib.test-math2 (:use clojure.test3 clojure.contrib.math))5 (deftest test-expt6 (are [x y] (= x y)7 (expt 2 3) 88 (expt (expt 2 16) 2) (expt 2 32)9 (expt 4/3 2) 16/910 (expt 2 -10) 1/102411 (expt 0.5M 2) 0.25M12 (expt 5 4.2) (Math/pow 5 4.2)13 (expt 5.3 4) (Math/pow 5.3 4)))15 (deftest test-abs16 (are [x y] (= x y)17 (abs -2) 218 (abs 0) 019 (abs 5) 520 (abs 123456789123456789) 12345678912345678921 (abs -123456789123456789) 12345678912345678922 (abs 5/3) 5/323 (abs -4/3) 4/324 (abs 4.3M) 4.3M25 (abs -4.3M) 4.3M26 (abs 2.8) 2.827 (abs -2.8) 2.8))29 (deftest test-gcd30 (are [x y] (= x y)31 (gcd 4 3) 132 (gcd 24 12) 1233 (gcd 24 27) 334 (gcd 1 0) 135 (gcd 0 1) 136 (gcd 0 0) 0)37 (is (thrown? IllegalArgumentException (gcd nil 0)))38 (is (thrown? IllegalArgumentException (gcd 0 nil)))39 (is (thrown? IllegalArgumentException (gcd 7.0 0))))41 (deftest test-lcm42 (are [x y] (= x y)43 (lcm 2 3) 644 (lcm 3 2) 645 (lcm -2 3) 646 (lcm 2 -3) 647 (lcm -2 -3) 648 (lcm 4 10) 2049 (lcm 1 0) 050 (lcm 0 1) 051 (lcm 0 0))52 (is (thrown? IllegalArgumentException (lcm nil 0)))53 (is (thrown? IllegalArgumentException (lcm 0 nil)))54 (is (thrown? IllegalArgumentException (lcm 7.0 0))))56 (deftest test-floor57 (are [x y] (== x y)58 (floor 6) 659 (floor -6) -660 (floor 123456789123456789) 12345678912345678961 (floor -123456789123456789) -12345678912345678962 (floor 4/3) 163 (floor -4/3) -264 (floor 4.3M) 465 (floor -4.3M) -566 (floor 4.3) 4.067 (floor -4.3) -5.0))69 (deftest test-ceil70 (are [x y] (== x y)71 (ceil 6) 672 (ceil -6) -673 (ceil 123456789123456789) 12345678912345678974 (ceil -123456789123456789) -12345678912345678975 (ceil 4/3) 276 (ceil -4/3) -177 (ceil 4.3M) 578 (ceil -4.3M) -479 (ceil 4.3) 5.080 (ceil -4.3) -4.0))82 (deftest test-round83 (are [x y] (== x y)84 (round 6) 685 (round -6) -686 (round 123456789123456789) 12345678912345678987 (round -123456789123456789) -12345678912345678988 (round 4/3) 189 (round 5/3) 290 (round 5/2) 391 (round -4/3) -192 (round -5/3) -293 (round -5/2) -294 (round 4.3M) 495 (round 4.7M) 596 (round -4.3M) -497 (round -4.7M) -598 (round 4.5M) 599 (round -4.5M) -4100 (round 4.3) 4101 (round 4.7) 5102 (round -4.3) -4103 (round -4.7) -5104 (round 4.5) 5105 (round -4.5) -4))107 (deftest test-sqrt108 (are [x y] (= x y)109 (sqrt 9) 3110 (sqrt 16/9) 4/3111 (sqrt 0.25M) 0.5M112 (sqrt 2) (Math/sqrt 2)))114 (deftest test-exact-integer-sqrt115 (are [x y] (= x y)116 (exact-integer-sqrt 15) [3 6]117 (exact-integer-sqrt (inc (expt 2 32))) [(expt 2 16) 1]118 (exact-integer-sqrt 1000000000000) [1000000 0]))