Mercurial > lasercutter
comparison 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 |
comparison
equal
deleted
inserted
replaced
9:35cf337adfcf | 10:ef7dbbd6452c |
---|---|
1 (ns clojure.contrib.test-math | |
2 (:use clojure.test | |
3 clojure.contrib.math)) | |
4 | |
5 (deftest test-expt | |
6 (are [x y] (= x y) | |
7 (expt 2 3) 8 | |
8 (expt (expt 2 16) 2) (expt 2 32) | |
9 (expt 4/3 2) 16/9 | |
10 (expt 2 -10) 1/1024 | |
11 (expt 0.5M 2) 0.25M | |
12 (expt 5 4.2) (Math/pow 5 4.2) | |
13 (expt 5.3 4) (Math/pow 5.3 4))) | |
14 | |
15 (deftest test-abs | |
16 (are [x y] (= x y) | |
17 (abs -2) 2 | |
18 (abs 0) 0 | |
19 (abs 5) 5 | |
20 (abs 123456789123456789) 123456789123456789 | |
21 (abs -123456789123456789) 123456789123456789 | |
22 (abs 5/3) 5/3 | |
23 (abs -4/3) 4/3 | |
24 (abs 4.3M) 4.3M | |
25 (abs -4.3M) 4.3M | |
26 (abs 2.8) 2.8 | |
27 (abs -2.8) 2.8)) | |
28 | |
29 (deftest test-gcd | |
30 (are [x y] (= x y) | |
31 (gcd 4 3) 1 | |
32 (gcd 24 12) 12 | |
33 (gcd 24 27) 3 | |
34 (gcd 1 0) 1 | |
35 (gcd 0 1) 1 | |
36 (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)))) | |
40 | |
41 (deftest test-lcm | |
42 (are [x y] (= x y) | |
43 (lcm 2 3) 6 | |
44 (lcm 3 2) 6 | |
45 (lcm -2 3) 6 | |
46 (lcm 2 -3) 6 | |
47 (lcm -2 -3) 6 | |
48 (lcm 4 10) 20 | |
49 (lcm 1 0) 0 | |
50 (lcm 0 1) 0 | |
51 (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)))) | |
55 | |
56 (deftest test-floor | |
57 (are [x y] (== x y) | |
58 (floor 6) 6 | |
59 (floor -6) -6 | |
60 (floor 123456789123456789) 123456789123456789 | |
61 (floor -123456789123456789) -123456789123456789 | |
62 (floor 4/3) 1 | |
63 (floor -4/3) -2 | |
64 (floor 4.3M) 4 | |
65 (floor -4.3M) -5 | |
66 (floor 4.3) 4.0 | |
67 (floor -4.3) -5.0)) | |
68 | |
69 (deftest test-ceil | |
70 (are [x y] (== x y) | |
71 (ceil 6) 6 | |
72 (ceil -6) -6 | |
73 (ceil 123456789123456789) 123456789123456789 | |
74 (ceil -123456789123456789) -123456789123456789 | |
75 (ceil 4/3) 2 | |
76 (ceil -4/3) -1 | |
77 (ceil 4.3M) 5 | |
78 (ceil -4.3M) -4 | |
79 (ceil 4.3) 5.0 | |
80 (ceil -4.3) -4.0)) | |
81 | |
82 (deftest test-round | |
83 (are [x y] (== x y) | |
84 (round 6) 6 | |
85 (round -6) -6 | |
86 (round 123456789123456789) 123456789123456789 | |
87 (round -123456789123456789) -123456789123456789 | |
88 (round 4/3) 1 | |
89 (round 5/3) 2 | |
90 (round 5/2) 3 | |
91 (round -4/3) -1 | |
92 (round -5/3) -2 | |
93 (round -5/2) -2 | |
94 (round 4.3M) 4 | |
95 (round 4.7M) 5 | |
96 (round -4.3M) -4 | |
97 (round -4.7M) -5 | |
98 (round 4.5M) 5 | |
99 (round -4.5M) -4 | |
100 (round 4.3) 4 | |
101 (round 4.7) 5 | |
102 (round -4.3) -4 | |
103 (round -4.7) -5 | |
104 (round 4.5) 5 | |
105 (round -4.5) -4)) | |
106 | |
107 (deftest test-sqrt | |
108 (are [x y] (= x y) | |
109 (sqrt 9) 3 | |
110 (sqrt 16/9) 4/3 | |
111 (sqrt 0.25M) 0.5M | |
112 (sqrt 2) (Math/sqrt 2))) | |
113 | |
114 (deftest test-exact-integer-sqrt | |
115 (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])) |