Mercurial > lasercutter
diff 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 diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/clojure/contrib/test_contrib/test_math.clj Sat Aug 21 06:25:44 2010 -0400 1.3 @@ -0,0 +1,118 @@ 1.4 +(ns clojure.contrib.test-math 1.5 + (:use clojure.test 1.6 + clojure.contrib.math)) 1.7 + 1.8 +(deftest test-expt 1.9 + (are [x y] (= x y) 1.10 + (expt 2 3) 8 1.11 + (expt (expt 2 16) 2) (expt 2 32) 1.12 + (expt 4/3 2) 16/9 1.13 + (expt 2 -10) 1/1024 1.14 + (expt 0.5M 2) 0.25M 1.15 + (expt 5 4.2) (Math/pow 5 4.2) 1.16 + (expt 5.3 4) (Math/pow 5.3 4))) 1.17 + 1.18 +(deftest test-abs 1.19 + (are [x y] (= x y) 1.20 + (abs -2) 2 1.21 + (abs 0) 0 1.22 + (abs 5) 5 1.23 + (abs 123456789123456789) 123456789123456789 1.24 + (abs -123456789123456789) 123456789123456789 1.25 + (abs 5/3) 5/3 1.26 + (abs -4/3) 4/3 1.27 + (abs 4.3M) 4.3M 1.28 + (abs -4.3M) 4.3M 1.29 + (abs 2.8) 2.8 1.30 + (abs -2.8) 2.8)) 1.31 + 1.32 +(deftest test-gcd 1.33 + (are [x y] (= x y) 1.34 + (gcd 4 3) 1 1.35 + (gcd 24 12) 12 1.36 + (gcd 24 27) 3 1.37 + (gcd 1 0) 1 1.38 + (gcd 0 1) 1 1.39 + (gcd 0 0) 0) 1.40 + (is (thrown? IllegalArgumentException (gcd nil 0))) 1.41 + (is (thrown? IllegalArgumentException (gcd 0 nil))) 1.42 + (is (thrown? IllegalArgumentException (gcd 7.0 0)))) 1.43 + 1.44 +(deftest test-lcm 1.45 + (are [x y] (= x y) 1.46 + (lcm 2 3) 6 1.47 + (lcm 3 2) 6 1.48 + (lcm -2 3) 6 1.49 + (lcm 2 -3) 6 1.50 + (lcm -2 -3) 6 1.51 + (lcm 4 10) 20 1.52 + (lcm 1 0) 0 1.53 + (lcm 0 1) 0 1.54 + (lcm 0 0)) 1.55 + (is (thrown? IllegalArgumentException (lcm nil 0))) 1.56 + (is (thrown? IllegalArgumentException (lcm 0 nil))) 1.57 + (is (thrown? IllegalArgumentException (lcm 7.0 0)))) 1.58 + 1.59 +(deftest test-floor 1.60 + (are [x y] (== x y) 1.61 + (floor 6) 6 1.62 + (floor -6) -6 1.63 + (floor 123456789123456789) 123456789123456789 1.64 + (floor -123456789123456789) -123456789123456789 1.65 + (floor 4/3) 1 1.66 + (floor -4/3) -2 1.67 + (floor 4.3M) 4 1.68 + (floor -4.3M) -5 1.69 + (floor 4.3) 4.0 1.70 + (floor -4.3) -5.0)) 1.71 + 1.72 +(deftest test-ceil 1.73 + (are [x y] (== x y) 1.74 + (ceil 6) 6 1.75 + (ceil -6) -6 1.76 + (ceil 123456789123456789) 123456789123456789 1.77 + (ceil -123456789123456789) -123456789123456789 1.78 + (ceil 4/3) 2 1.79 + (ceil -4/3) -1 1.80 + (ceil 4.3M) 5 1.81 + (ceil -4.3M) -4 1.82 + (ceil 4.3) 5.0 1.83 + (ceil -4.3) -4.0)) 1.84 + 1.85 +(deftest test-round 1.86 + (are [x y] (== x y) 1.87 + (round 6) 6 1.88 + (round -6) -6 1.89 + (round 123456789123456789) 123456789123456789 1.90 + (round -123456789123456789) -123456789123456789 1.91 + (round 4/3) 1 1.92 + (round 5/3) 2 1.93 + (round 5/2) 3 1.94 + (round -4/3) -1 1.95 + (round -5/3) -2 1.96 + (round -5/2) -2 1.97 + (round 4.3M) 4 1.98 + (round 4.7M) 5 1.99 + (round -4.3M) -4 1.100 + (round -4.7M) -5 1.101 + (round 4.5M) 5 1.102 + (round -4.5M) -4 1.103 + (round 4.3) 4 1.104 + (round 4.7) 5 1.105 + (round -4.3) -4 1.106 + (round -4.7) -5 1.107 + (round 4.5) 5 1.108 + (round -4.5) -4)) 1.109 + 1.110 +(deftest test-sqrt 1.111 + (are [x y] (= x y) 1.112 + (sqrt 9) 3 1.113 + (sqrt 16/9) 4/3 1.114 + (sqrt 0.25M) 0.5M 1.115 + (sqrt 2) (Math/sqrt 2))) 1.116 + 1.117 +(deftest test-exact-integer-sqrt 1.118 + (are [x y] (= x y) 1.119 + (exact-integer-sqrt 15) [3 6] 1.120 + (exact-integer-sqrt (inc (expt 2 32))) [(expt 2 16) 1] 1.121 + (exact-integer-sqrt 1000000000000) [1000000 0]))