Skip to content

Commit 485de6b

Browse files
dgrCopilot
andauthored
Rework <=, <, and > (#871)
* Convert `<=` arity 1 tests to use `are` * Add `<=` test for five equal numbers * Remove some negative tests outside the function contract * Fix comment * Convert `<` arity 1 tests to use `are` * Add some tests of equal rationals to `<` * Add test of five equal numbers to `<` * Convert `>` arity 1 tests to use `are` * Fix spacing * Add some tests of equal rationals to `>` * Add test of five equal numbers to `>` * Remove neg tests from outside the function contracts of `<` and `>` * Fix comment grammar Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Fix grammar in comments and one bug caught by CoPilot review --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent c55d585 commit 485de6b

3 files changed

Lines changed: 82 additions & 105 deletions

File tree

test/clojure/core_test/gt.cljc

Lines changed: 45 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,40 @@
55
(when-var-exists >
66
(deftest test->
77
(testing "arity 1"
8-
;; Doesn't matter what the argument is, `>` return `true` for
9-
;; one argument.
10-
(is (> 1))
11-
(is (> 0))
12-
(is (> -1))
13-
;; Doesn't check whether arg is a number
14-
(is (> "abc"))
15-
(is (> :foo))
16-
(is (> nil)))
8+
(are [x] (= true (> x))
9+
;; Doesn't matter what the argument is, `>` returns `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))
1718

1819
(testing "arity 2"
1920
(are [expected x y] (= expected (> x y))
2021
true 1 0
21-
true 0 -1
22-
true 1N 0N
23-
true 0N -1N
24-
true 1.0 0.0
25-
true 0.0 -1.0
26-
true 1.0M 0.0M
27-
true 0.0M -1.0M
28-
true -1 ##-Inf
29-
true ##Inf 1
22+
true 0 -1
23+
true 1N 0N
24+
true 0N -1N
25+
true 1.0 0.0
26+
true 0.0 -1.0
27+
true 1.0M 0.0M
28+
true 0.0M -1.0M
29+
true -1 ##-Inf
30+
true ##Inf 1
3031

3132
false 0 1
32-
false -1 0
33-
false 0N 1N
34-
false -1N 0N
35-
false 0.0 1.0
36-
false -1.0 0.0
37-
false 0.0M 1.0M
38-
false -1.0M 0.0M
39-
false ##-Inf -1
40-
false 1 ##Inf
33+
false -1 0
34+
false 0N 1N
35+
false -1N 0N
36+
false 0.0 1.0
37+
false -1.0 0.0
38+
false 0.0M 1.0M
39+
false -1.0M 0.0M
40+
false ##-Inf -1
41+
false 1 ##Inf
4142

4243
false 1 ##NaN ; Anything compared with ##NaN is false
4344
false ##NaN 1
@@ -60,15 +61,18 @@
6061
:default
6162
(testing "Rationals"
6263
(are [expected x y] (= expected (> x y))
63-
true 1/2 1/16
64-
true 0.5 1/16
65-
true -1/16 -1/2
66-
true -1/16 -0.5
67-
6864
false 1/16 1/2
69-
false -1/2 -1/16
70-
false 1/16 0.5
71-
false -0.5 -1/16))))
65+
false -1/2 -1/16
66+
false 1/16 0.5
67+
false -0.5 -1/16
68+
true 1/2 1/16
69+
true 0.5 1/16
70+
true -1/16 -1/2
71+
true -1/16 -0.5
72+
false 1/2 1/2
73+
false 1/3 1/3
74+
false -1/2 -1/2
75+
false -1/3 -1/3))))
7276

7377
(testing "arity 3 and more"
7478
(are [expected x y z] (= expected (> x y z))
@@ -80,7 +84,8 @@
8084
false -1 -2 0
8185
false -1 0 -2)
8286
(is (= true (apply > (reverse (range 10)))))
83-
(is (= false (apply > -1 (reverse (range 10))))))
87+
(is (= false (apply > -1 (reverse (range 10)))))
88+
(is (= false (apply > (repeat 5 1)))))
8489

8590
(testing "negative tests"
8691
;; `>` only compares numbers, except in ClojureScript (really
@@ -91,31 +96,19 @@
9196
[(is (= true (> 1 nil)))
9297
(is (= false (> nil 1)))
9398
(is (= true (> 2 1 nil)))
94-
(is (= false (> 1 2 nil)))
95-
(is (= true (> "2" "1")))
96-
(is (= false (> "bar" "foo")))
97-
(is (= false (> :bar :foo)))]
99+
(is (= false (> 1 2 nil)))]
98100
:cljr
99101
[(is (p/thrown? (> 1 nil)))
100102
(is (p/thrown? (> nil 1)))
101103
(is (p/thrown? (> 1 nil 2)))
102-
(is (p/thrown? (> 2 1 nil)))
103-
(is (= true (> "2" "1")))
104-
(is (p/thrown? (> "bar" "foo")))
105-
(is (p/thrown? (> :bar :foo)))]
104+
(is (p/thrown? (> 2 1 nil)))]
106105
:lpy
107106
[(is (p/thrown? (> 1 nil)))
108107
(is (p/thrown? (> nil 1)))
109108
(is (p/thrown? (> 1 nil 2)))
110-
(is (p/thrown? (> 2 1 nil)))
111-
(is (= true (> "2" "1")))
112-
(is (= false (> "bar" "foo")))
113-
(is (= false (> :bar :foo)))]
109+
(is (p/thrown? (> 2 1 nil)))]
114110
:default
115111
[(is (p/thrown? (> 1 nil)))
116112
(is (p/thrown? (> nil 1)))
117113
(is (p/thrown? (> 1 nil 2)))
118-
(is (p/thrown? (> 2 1 nil)))
119-
(is (p/thrown? (> "2" "1")))
120-
(is (p/thrown? (> "bar" "foo")))
121-
(is (p/thrown? (> :bar :foo)))]))))
114+
(is (p/thrown? (> 2 1 nil)))]))))

test/clojure/core_test/lt.cljc

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
(when-var-exists <
66
(deftest test-<
77
(testing "arity 1"
8-
;; Doesn't matter what the argument is, `<` return `true` for
9-
;; one argument.
10-
(is (< 1))
11-
(is (< 0))
12-
(is (< -1))
13-
;; Doesn't check whether arg is a number
14-
(is (< "abc"))
15-
(is (< :foo))
16-
(is (< nil)))
8+
(are [x] (= true (< x))
9+
;; Doesn't matter what the argument is, `<` returns `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))
1718

1819
(testing "arity 2"
1920
(are [expected x y] (= expected (< x y))
@@ -66,7 +67,11 @@
6667
false 1/2 1/16
6768
false 0.5 1/16
6869
false -1/16 -1/2
69-
false -1/16 -0.5))))
70+
false -1/16 -0.5
71+
false 1/2 1/2
72+
false 1/3 1/3
73+
false -1/2 -1/2
74+
false -1/3 -1/3))))
7075

7176
(testing "arity 3 and more"
7277
(are [expected x y z] (= expected (< x y z))
@@ -78,7 +83,8 @@
7883
false 0 -2 -1
7984
false -2 0 -1)
8085
(is (= true (apply < (range 10))))
81-
(is (= false (apply < 100 (range 10)))))
86+
(is (= false (apply < 100 (range 10))))
87+
(is (= false (apply < (repeat 5 1)))))
8288

8389
(testing "negative tests"
8490
;; `<` only compares numbers, except in ClojureScript (really
@@ -88,31 +94,19 @@
8894
[(is (= true (< nil 1)))
8995
(is (= false (< 1 nil)))
9096
(is (= true (< nil 1 2)))
91-
(is (= false (< 1 2 nil)))
92-
(is (= true (< "1" "2")))
93-
(is (= false (< "foo" "bar")))
94-
(is (= false (< :foo :bar)))]
97+
(is (= false (< 1 2 nil)))]
9598
:cljr
9699
[(is (p/thrown? (< nil 1)))
97100
(is (p/thrown? (< 1 nil)))
98101
(is (p/thrown? (< nil 1 2)))
99-
(is (p/thrown? (< 1 2 nil)))
100-
(is (= true (< "1" "2")))
101-
(is (p/thrown? (< "foo" "bar")))
102-
(is (p/thrown? (< :foo :bar)))]
102+
(is (p/thrown? (< 1 2 nil)))]
103103
:lpy
104104
[(is (p/thrown? (< nil 1)))
105105
(is (p/thrown? (< 1 nil)))
106106
(is (p/thrown? (< nil 1 2)))
107-
(is (p/thrown? (< 1 2 nil)))
108-
(is (= true (< "1" "2")))
109-
(is (= false (< "foo" "bar")))
110-
(is (= false (< :foo :bar)))]
107+
(is (p/thrown? (< 1 2 nil)))]
111108
:default
112109
[(is (p/thrown? (< nil 1)))
113110
(is (p/thrown? (< 1 nil)))
114111
(is (p/thrown? (< nil 1 2)))
115-
(is (p/thrown? (< 1 2 nil)))
116-
(is (p/thrown? (< "1" "2")))
117-
(is (p/thrown? (< "foo" "bar")))
118-
(is (p/thrown? (< :foo :bar)))]))))
112+
(is (p/thrown? (< 1 2 nil)))]))))

test/clojure/core_test/lt_eq.cljc

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
(when-var-exists <=
66
(deftest test-<=
77
(testing "arity 1"
8-
;; Doesn't matter what the argument is, `<=` return `true` for
9-
;; one argument.
10-
(is (<= 1))
11-
(is (<= 0))
12-
(is (<= -1))
13-
;; Doesn't check whether arg is a number
14-
(is (<= "abc"))
15-
(is (<= :foo))
16-
(is (<= nil)))
8+
(are [x] (= true (<= x))
9+
;; Doesn't matter what the argument is, `<=` returns `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))
1718

1819
(testing "arity 2"
1920
(are [expected x y] (= expected (<= x y))
@@ -88,7 +89,8 @@
8889
false ##Inf 0 ##-Inf)
8990
(is (= true (apply <= (range 10))))
9091
(is (= true (apply <= 0 (range 10))))
91-
(is (= false (apply <= 100 (range 10)))))
92+
(is (= false (apply <= 100 (range 10))))
93+
(is (= true (apply <= (repeat 5 1)))))
9294

9395
(testing "negative tests"
9496
;; `<=` only compares numbers, except in ClojureScript (really
@@ -98,31 +100,19 @@
98100
[(is (= true (<= nil 1)))
99101
(is (= false (<= 1 nil)))
100102
(is (= true (<= nil 1 2)))
101-
(is (= false (<= 1 2 nil)))
102-
(is (= true (<= "1" "2")))
103-
(is (= false (<= "foo" "bar")))
104-
(is (= false (<= :foo :bar)))]
103+
(is (= false (<= 1 2 nil)))]
105104
:cljr
106105
[(is (p/thrown? (<= nil 1)))
107106
(is (p/thrown? (<= 1 nil)))
108107
(is (p/thrown? (<= nil 1 2)))
109-
(is (p/thrown? (<= 1 2 nil)))
110-
(is (= true (<= "1" "2")))
111-
(is (p/thrown? (<= "foo" "bar")))
112-
(is (p/thrown? (<= :foo :bar)))]
108+
(is (p/thrown? (<= 1 2 nil)))]
113109
:lpy
114110
[(is (p/thrown? (<= nil 1)))
115111
(is (p/thrown? (<= 1 nil)))
116112
(is (p/thrown? (<= nil 1 2)))
117-
(is (p/thrown? (<= 1 2 nil)))
118-
(is (= true (<= "1" "2")))
119-
(is (= false (<= "foo" "bar")))
120-
(is (= false (<= :foo :bar)))]
113+
(is (p/thrown? (<= 1 2 nil)))]
121114
:default
122115
[(is (p/thrown? (<= nil 1)))
123116
(is (p/thrown? (<= 1 nil)))
124117
(is (p/thrown? (<= nil 1 2)))
125-
(is (p/thrown? (<= 1 2 nil)))
126-
(is (p/thrown? (<= "1" "2")))
127-
(is (p/thrown? (<= "foo" "bar")))
128-
(is (p/thrown? (<= :foo :bar)))]))))
118+
(is (p/thrown? (<= 1 2 nil)))]))))

0 commit comments

Comments
 (0)