File tree Expand file tree Collapse file tree 1 file changed +55
-0
lines changed
Expand file tree Collapse file tree 1 file changed +55
-0
lines changed Original file line number Diff line number Diff line change 1+ (ns clojure.core-test.compare
2+ (:require [clojure.test :as t]))
3+
4+ (t/deftest numeric-types
5+ (t/are [r args] (= r (compare (first args) (second args)))
6+ -1 [0 10 ]
7+ 0 [0 0 ]
8+ 1 [0 -100N ]
9+ 0 [1 1.0 ]
10+ -1 [1 100/3 ]
11+ -1 [0 0x01 ]
12+ -1 [0 2r01 ]
13+ 1 [1 nil ])
14+
15+ (t/is (thrown? Exception (compare 1 []))))
16+
17+ (t/deftest lexical-types
18+ (t/are [r args] (= r (compare (first args) (second args)))
19+ -1 [\a \b]
20+ 0 [\0 \0 ]
21+ 25 [\z \a]
22+ -1 [" cat" " dog" ]
23+ -1 ['cat 'dog]
24+ -1 [:cat :dog ]
25+ 0 [:dog :dog ]
26+ -1 [:cat :animal/cat ]
27+ 1 ['a nil ])
28+
29+ (t/is (thrown? Exception (compare " a" [])))
30+ (t/is (thrown? Exception (compare " cat" '(\c \a \t)))))
31+
32+ (t/deftest collection-types
33+ (t/are [r args] (= r (compare (first args) (second args)))
34+ 0 [[] []]
35+ 1 [[3 ] [1 ]]
36+ -1 [[] [1 2 ]]
37+ -1 [[] [[]]]
38+ 0 [#{} #{}]
39+ 0 [{} {}]
40+ 0 [(array-map ) (array-map )]
41+ 0 [(hash-map ) (hash-map )]
42+ 0 [{} (hash-map )]
43+ 0 [{} (array-map )]
44+ 0 ['() '()]
45+ 1 [[] nil ])
46+
47+ (t/is (thrown? Exception (compare [] '())))
48+ (t/is (thrown? Exception (compare [1 ] [[]])))
49+ (t/is (thrown? Exception (compare [] {})))
50+ (t/is (thrown? Exception (compare [] #{})))
51+ (t/is (thrown? Exception (compare #{} (sorted-set ))))
52+ (t/is (thrown? Exception (compare #{1 } #{1 })))
53+ (t/is (thrown? Exception (compare {1 2 } {1 2 })))
54+ (t/is (thrown? Exception (compare (range 5 ) (range 5 ))))
55+ (t/is (thrown? Exception (compare (range 5 ) (range )))))
You can’t perform that action at this time.
0 commit comments