Skip to content

Commit 1e80ede

Browse files
authored
Merge pull request #36 from dgr/dgr-numerator-denominator
Add tests for `numerator` and `denominator`
2 parents 93a0028 + eee708c commit 1e80ede

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
(ns clojure.core-test.denominator
2+
(:require [clojure.test :as t :refer [deftest testing is are]]
3+
[clojure.core-test.portability :as p]))
4+
5+
(p/when-var-exists 'clojure.core/denominator
6+
(deftest test-denominator
7+
(is (= 2 (denominator 1/2)))
8+
(is (= 3 (denominator 2/3)))
9+
(is (= 4 (denominator 3/4)))
10+
11+
(is (thrown? Exception (denominator 1)))
12+
(is (thrown? Exception (denominator 1.0)))
13+
(is (thrown? Exception (denominator 1N)))
14+
(is (thrown? Exception (denominator 1.0M)))
15+
(is (thrown? Exception (denominator ##Inf)))
16+
(is (thrown? Exception (denominator ##NaN)))
17+
(is (thrown? Exception (denominator nil)))))
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
(ns clojure.core-test.numerator
2+
(:require [clojure.test :as t :refer [deftest testing is are]]
3+
[clojure.core-test.portability :as p]))
4+
5+
(p/when-var-exists 'clojure.core/numerator
6+
(deftest test-numerator
7+
(is (= 1 (numerator 1/2)))
8+
(is (= 2 (numerator 2/3)))
9+
(is (= 3 (numerator 3/4)))
10+
11+
(is (thrown? Exception (numerator 1)))
12+
(is (thrown? Exception (numerator 1.0)))
13+
(is (thrown? Exception (numerator 1N)))
14+
(is (thrown? Exception (numerator 1.0M)))
15+
(is (thrown? Exception (numerator ##Inf)))
16+
(is (thrown? Exception (numerator ##NaN)))
17+
(is (thrown? Exception (numerator nil)))))
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
(ns clojure.core-test.portability)
22

3+
(defmacro when-var-exists [var-sym & body]
4+
`(let [s# ~var-sym
5+
v# (resolve s#)]
6+
(if v#
7+
(do
8+
~@body)
9+
(println "SKIP -" s#))))
10+
311
(defn big-int? [n]
412
(and (integer? n)
513
(not (int? n))))

0 commit comments

Comments
 (0)