|
5 | 5 | (when-var-exists clojure.core/compare |
6 | 6 | (deftest test-compare |
7 | 7 | (testing "numeric-types" |
8 | | - (are [r args] (= r (compare (first args) (second args))) |
9 | | - -1 [0 10] |
10 | | - 0 [0 0] |
11 | | - 1 [0 -100N] |
12 | | - 0 [1 1.0] |
| 8 | + (are [pred args] (pred (compare (first args) (second args))) |
| 9 | + neg? [0 10] |
| 10 | + zero? [0 0] |
| 11 | + pos? [0 -100N] |
| 12 | + zero? [1 1.0] |
13 | 13 | #?@(:cljs [] |
14 | 14 | :default |
15 | | - [-1 [1 100/3]]) |
16 | | - -1 [0 0x01] |
17 | | - -1 [0 2r01] |
18 | | - 1 [1 nil]) |
| 15 | + [neg? [1 100/3]]) |
| 16 | + neg? [0 0x01] |
| 17 | + neg? [0 2r01] |
| 18 | + pos? [1 nil]) |
19 | 19 |
|
20 | 20 | (is (thrown? #?(:cljs :default :clj Exception) (compare 1 [])))) |
21 | 21 |
|
22 | 22 | (testing "lexical-types" |
23 | | - (are [r args] (= r (compare (first args) (second args))) |
24 | | - -1 [\a \b] |
25 | | - 0 [\0 \0] |
26 | | - 25 [\z \a] |
27 | | - -1 ["cat" "dog"] |
28 | | - -1 ['cat 'dog] |
29 | | - -1 [:cat :dog] |
30 | | - 0 [:dog :dog] |
31 | | - -1 [:cat :animal/cat] |
32 | | - 1 ['a nil]) |
| 23 | + (are [pred args] (pred (compare (first args) (second args))) |
| 24 | + neg? [\a \b] |
| 25 | + zero? [\0 \0] |
| 26 | + pos? [\z \a] |
| 27 | + neg? ["cat" "dog"] |
| 28 | + neg? ['cat 'dog] |
| 29 | + neg? [:cat :dog] |
| 30 | + zero? [:dog :dog] |
| 31 | + neg? [:cat :animal/cat] |
| 32 | + pos? ['a nil]) |
33 | 33 |
|
34 | 34 | (is (thrown? #?(:cljs :default :clj Exception) (compare "a" []))) |
35 | 35 | (is (thrown? #?(:cljs :default :clj Exception) (compare "cat" '(\c \a \t))))) |
36 | 36 |
|
37 | 37 | (testing "collection-types" |
38 | | - (are [r args] (= r (compare (first args) (second args))) |
39 | | - 0 [[] []] |
40 | | - 1 [[3] [1]] |
41 | | - -1 [[] [1 2]] |
42 | | - -1 [[] [[]]] |
43 | | - 0 [#{} #{}] |
44 | | - 0 [{} {}] |
45 | | - 0 [(array-map) (array-map)] |
46 | | - 0 [(hash-map) (hash-map)] |
47 | | - 0 [{} (hash-map)] |
48 | | - 0 [{} (array-map)] |
49 | | - 0 ['() '()] |
50 | | - 1 [[] nil]) |
| 38 | + (are [pred args] (pred (compare (first args) (second args))) |
| 39 | + zero? [[] []] |
| 40 | + pos? [[3] [1]] |
| 41 | + neg? [[] [1 2]] |
| 42 | + neg? [[] [[]]] |
| 43 | + ;; Sets, maps, and lists don't implement java.lang.Comparable, |
| 44 | + ;; so just comment these out for now. TODO: make decision as to |
| 45 | + ;; what we want to do with these tests. |
| 46 | + ;; zero? [#{} #{}] |
| 47 | + ;; zero? [{} {}] |
| 48 | + ;; zero? [(array-map) (array-map)] |
| 49 | + ;; zero? [(hash-map) (hash-map)] |
| 50 | + ;; zero? [{} (hash-map)] |
| 51 | + ;; zero? [{} (array-map)] |
| 52 | + ;; zero? ['() '()] |
| 53 | + pos? [[] nil]) |
51 | 54 |
|
52 | 55 | (is (thrown? #?(:cljs :default :clj Exception) (compare [] '()))) |
53 | 56 | (is (thrown? #?(:cljs :default :clj Exception) (compare [1] [[]]))) |
|
57 | 60 | (is (thrown? #?(:cljs :default :clj Exception) (compare #{1} #{1}))) |
58 | 61 | (is (thrown? #?(:cljs :default :clj Exception) (compare {1 2} {1 2}))) |
59 | 62 | (is (thrown? #?(:cljs :default :clj Exception) (compare (range 5) (range 5)))) |
60 | | - (is (thrown? #?(:cljs :default :clj Exception) (compare (range 5) (range))))))) |
| 63 | + ;; Clojurescript goes into an infinite loop of some sort when compiling this. |
| 64 | + #_(is (thrown? #?(:cljs :default :clj Exception) (compare (range 5) (range))))))) |
0 commit comments