Skip to content

Commit 93a0028

Browse files
authored
Merge pull request jank-lang#35 from dgr/dgr-min-max
Add tests for `min` and `max`
2 parents 2c1eb3e + 5de2777 commit 93a0028

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

test/clojure/core_test/max.cljc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
(ns clojure.core-test.max
2+
(:require [clojure.test :as t :refer [deftest testing is are]]))
3+
4+
(deftest test-max
5+
(are [expected x y] (= expected (max x y) (max y x))
6+
2 1 2
7+
2N 1N 2N
8+
2 1N 2
9+
2N 1 2N
10+
2.0 1.0 2.0
11+
2.0 1 2.0
12+
2 1.0 2
13+
1 1/2 1
14+
##Inf 1 ##Inf
15+
1 1 ##-Inf
16+
##Inf ##-Inf ##Inf)
17+
18+
;; Single arg just returns argument
19+
(is (= 1 (max 1)))
20+
(is (= 2 (max 2)))
21+
(is (= "x" (max "x"))) ; doesn't check single arg for Number
22+
23+
;; Multi-arg
24+
(is (= 5 (max 1 2 3 4 5)))
25+
(is (= 5 (max 5 4 3 2 1)))
26+
(is (= 5 (max 1 2 3 4 5 ##-Inf)))
27+
(is (= ##Inf (max 1 2 3 4 5 ##Inf)))
28+
29+
(is (NaN? (max ##NaN 1)))
30+
(is (NaN? (max 1 ##NaN)))
31+
(is (NaN? (max 1 2 3 4 ##NaN)))
32+
(is (NaN? (max ##-Inf ##NaN ##Inf)))
33+
(is (NaN? (max ##NaN)))
34+
35+
(is (thrown? Exception (max "x" "y")))
36+
(is (thrown? Exception (max nil 1)))
37+
(is (thrown? Exception (max 1 nil))))

test/clojure/core_test/min.cljc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
(ns clojure.core-test.min
2+
(:require [clojure.test :as t :refer [deftest testing is are]]))
3+
4+
(deftest test-min
5+
(are [expected x y] (= expected (min x y) (min y x))
6+
1 1 2
7+
1N 1N 2N
8+
1N 1N 2
9+
1 1 2N
10+
1.0 1.0 2.0
11+
1 1 2.0
12+
1.0 1.0 2
13+
1/2 1/2 1
14+
1 1 ##Inf
15+
##-Inf 1 ##-Inf
16+
##-Inf ##-Inf ##Inf)
17+
18+
;; Single arg just returns argument
19+
(is (= 1 (min 1)))
20+
(is (= 2 (min 2)))
21+
(is (= "x" (min "x"))) ; doesn't check single arg for Number
22+
23+
;; Multi-arg
24+
(is (= 1 (min 1 2 3 4 5)))
25+
(is (= 1 (min 5 4 3 2 1)))
26+
(is (= ##-Inf (min 1 2 3 4 5 ##-Inf)))
27+
(is (= 1 (min 1 2 3 4 5 ##Inf)))
28+
29+
(is (NaN? (min ##NaN 1)))
30+
(is (NaN? (min 1 ##NaN)))
31+
(is (NaN? (min 1 2 3 4 ##NaN)))
32+
(is (NaN? (min ##-Inf ##NaN ##Inf)))
33+
(is (NaN? (min ##NaN)))
34+
35+
(is (thrown? Exception (min "x" "y")))
36+
(is (thrown? Exception (min nil 1)))
37+
(is (thrown? Exception (min 1 nil))))

0 commit comments

Comments
 (0)