Skip to content

Commit ee60cc6

Browse files
authored
Add tests for >= (#865)
* Add tests for `>=` * Fix code spacing * Remove non-numeric, non-nil negative tests * Simplify arity 1 tests * Add tests for arity 3+ equality
1 parent faa0c2f commit ee60cc6

1 file changed

Lines changed: 119 additions & 0 deletions

File tree

test/clojure/core_test/gt_eq.cljc

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
(ns clojure.core-test.gt-eq
2+
(:require [clojure.test :as t :refer [are deftest is testing]]
3+
[clojure.core-test.portability #?(:cljs :refer-macros :default :refer) [when-var-exists] :as p]))
4+
5+
(when-var-exists >=
6+
(deftest test->=
7+
(testing "arity 1"
8+
(are [x] (= true (>= x))
9+
;; Doesn't matter what the argument is, `>=` return `true` for
10+
;; one argument.
11+
1
12+
0
13+
-1
14+
;; Doesn't check whether the argument is a number
15+
"abc"
16+
:foo
17+
nil))
18+
19+
(testing "arity 2"
20+
(are [expected x y] (= expected (>= x y))
21+
false 0 1
22+
false -1 0
23+
false 0N 1N
24+
false -1N 0N
25+
false 0.0 1.0
26+
false -1.0 0.0
27+
false 0.0M 1.0M
28+
false -1.0M 0.0M
29+
false ##-Inf -1
30+
false 1 ##Inf
31+
false 1 ##NaN ; Anything compared with ##NaN is false
32+
false ##NaN 1
33+
34+
true 1 0
35+
true 0 -1
36+
true 1N 0N
37+
true 0N -1N
38+
true 1.0 0.0
39+
true 0.0 -1.0
40+
true 1.0M 0.0M
41+
true 0.0M -1.0M
42+
true -1 ##-Inf
43+
true ##Inf 1
44+
45+
true 0 0
46+
true 1 1
47+
true -1 -1
48+
true ##Inf ##Inf
49+
true ##-Inf ##-Inf
50+
false ##NaN ##NaN ; ##NaN is never equal, even to itself
51+
52+
;; Mixing numeric types should't matter
53+
true 1.0 0
54+
true 0 -1.0
55+
true 1.0M 0N
56+
true 0.0M -1N)
57+
58+
#?(:cljs nil
59+
:default
60+
(testing "Rationals"
61+
(are [expected x y] (= expected (>= x y))
62+
true 1/2 1/16
63+
true -1/16 -1/2
64+
true 0.5 1/16
65+
true -1/16 -0.5
66+
false 1/16 1/2
67+
false 1/16 0.5
68+
false -1/2 -1/16
69+
false -0.5 -1/16
70+
true 1/2 1/2
71+
true 1/3 1/3
72+
true -1/2 -1/2
73+
true -1/3 -1/3))))
74+
75+
(testing "arity 3 and more"
76+
(are [expected x y z] (= expected (>= x y z))
77+
true 2 1 0
78+
true 0 -1 -2
79+
true 1 0 -1
80+
true 1 1 1
81+
false 2 0 1
82+
false 0 2 1
83+
false -1 -2 0
84+
false -1 0 -2
85+
true 1 0 0
86+
true 1 1 0
87+
false 0 0 1
88+
false 0 1 1
89+
true ##Inf 0 ##-Inf
90+
false ##-Inf 0 ##Inf)
91+
(is (= true (apply >= (reverse (range 10)))))
92+
(is (= true (apply >= 10 (reverse (range 10)))))
93+
(is (= false (apply >= -1 (reverse (range 10)))))
94+
(is (= true (apply >= (repeat 5 1)))))
95+
96+
(testing "negative tests"
97+
;; `<=` only compares numbers, except in ClojureScript (really
98+
;; JavaScript under the hood) where comparisons are just a bit
99+
;; of a mess.
100+
#?@(:cljs
101+
[(is (= true (>= 1 nil)))
102+
(is (= false (>= nil 1)))
103+
(is (= true (>= 2 1 nil)))
104+
(is (= false (>= nil 2 1)))]
105+
:cljr
106+
[(is (p/thrown? (>= 1 nil)))
107+
(is (p/thrown? (>= nil 1)))
108+
(is (p/thrown? (>= 2 1 nil)))
109+
(is (p/thrown? (>= nil 2 1)))]
110+
:lpy
111+
[(is (p/thrown? (>= 1 nil)))
112+
(is (p/thrown? (>= nil 1)))
113+
(is (p/thrown? (>= 2 1 nil)))
114+
(is (p/thrown? (>= nil 2 1)))]
115+
:default
116+
[(is (p/thrown? (>= 1 nil)))
117+
(is (p/thrown? (>= nil 1)))
118+
(is (p/thrown? (>= 2 1 nil)))
119+
(is (p/thrown? (>= nil 2 1)))]))))

0 commit comments

Comments
 (0)