Mercurial > lasercutter
view src/clojure/test_clojure/data_structures.clj @ 10:ef7dbbd6452c
added clojure source goodness
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 21 Aug 2010 06:25:44 -0400 |
parents | |
children |
line wrap: on
line source
1 ; Copyright (c) Rich Hickey. All rights reserved.2 ; The use and distribution terms for this software are covered by the3 ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)4 ; which can be found in the file epl-v10.html at the root of this distribution.5 ; By using this software in any fashion, you are agreeing to be bound by6 ; the terms of this license.7 ; You must not remove this notice, or any other, from this software.9 ; Author: Frantisek Sodomka12 (ns clojure.test-clojure.data-structures13 (:use clojure.test))16 ;; *** Helper functions ***18 (defn diff [s1 s2]19 (seq (reduce disj (set s1) (set s2))))22 ;; *** General ***24 (defstruct equality-struct :a :b)26 (deftest test-equality27 ; nil is not equal to any other value28 (are [x] (not (= nil x))29 true false30 0 0.031 \space32 "" #""33 () [] #{} {}34 (lazy-seq nil) ; SVN 1292: fixed (= (lazy-seq nil) nil)35 (lazy-seq ())36 (lazy-seq [])37 (lazy-seq {})38 (lazy-seq #{})39 (lazy-seq "")40 (lazy-seq (into-array []))41 (new Object) )43 ; numbers equality across types (see tests below - NOT IMPLEMENTED YET)45 ; ratios46 (is (= 1/2 0.5))47 (is (= 1/1000 0.001))48 (is (not= 2/3 0.6666666666666666))50 ; vectors equal other seqs by items equality51 (are [x y] (= x y)52 '() [] ; regression fixed in r1208; was not equal53 '(1) [1]54 '(1 2) [1 2]56 [] '() ; same again, but vectors first57 [1] '(1)58 [1 2] '(1 2) )59 (is (not= [1 2] '(2 1))) ; order of items matters61 ; list and vector vs. set and map62 (are [x y] (not= x y)63 ; only () equals []64 () #{}65 () {}66 [] #{}67 [] {}68 #{} {}69 ; only '(1) equals [1]70 '(1) #{1}71 [1] #{1} )73 ; sorted-map, hash-map and array-map - classes differ, but content is equal75 ;; TODO: reimplement all-are with new do-template?76 ;; (all-are (not= (class _1) (class _2))77 ;; (sorted-map :a 1)78 ;; (hash-map :a 1)79 ;; (array-map :a 1))80 ;; (all-are (= _1 _2)81 ;; (sorted-map)82 ;; (hash-map)83 ;; (array-map))84 ;; (all-are (= _1 _2)85 ;; (sorted-map :a 1)86 ;; (hash-map :a 1)87 ;; (array-map :a 1))88 ;; (all-are (= _1 _2)89 ;; (sorted-map :a 1 :z 3 :c 2)90 ;; (hash-map :a 1 :z 3 :c 2)91 ;; (array-map :a 1 :z 3 :c 2))93 ; struct-map vs. sorted-map, hash-map and array-map94 (are [x] (and (not= (class (struct equality-struct 1 2)) (class x))95 (= (struct equality-struct 1 2) x))96 (sorted-map-by compare :a 1 :b 2)97 (sorted-map :a 1 :b 2)98 (hash-map :a 1 :b 2)99 (array-map :a 1 :b 2))101 ; sorted-set vs. hash-set102 (is (not= (class (sorted-set 1)) (class (hash-set 1))))103 (are [x y] (= x y)104 (sorted-set-by <) (hash-set)105 (sorted-set-by < 1) (hash-set 1)106 (sorted-set-by < 3 2 1) (hash-set 3 2 1)107 (sorted-set) (hash-set)108 (sorted-set 1) (hash-set 1)109 (sorted-set 3 2 1) (hash-set 3 2 1) ))112 ;; *** Collections ***114 (deftest test-count115 (are [x y] (= x y)116 (count nil) 0118 (count ()) 0119 (count '(1)) 1120 (count '(1 2 3)) 3122 (count []) 0123 (count [1]) 1124 (count [1 2 3]) 3126 (count #{}) 0127 (count #{1}) 1128 (count #{1 2 3}) 3130 (count {}) 0131 (count {:a 1}) 1132 (count {:a 1 :b 2 :c 3}) 3134 (count "") 0135 (count "a") 1136 (count "abc") 3138 (count (into-array [])) 0139 (count (into-array [1])) 1140 (count (into-array [1 2 3])) 3142 (count (java.util.ArrayList. [])) 0143 (count (java.util.ArrayList. [1])) 1144 (count (java.util.ArrayList. [1 2 3])) 3146 (count (java.util.HashMap. {})) 0147 (count (java.util.HashMap. {:a 1})) 1148 (count (java.util.HashMap. {:a 1 :b 2 :c 3})) 3 )150 ; different types151 (are [x] (= (count [x]) 1)152 nil true false153 0 0.0 "" \space154 () [] #{} {} ))157 (deftest test-conj158 ; doesn't work on strings or arrays159 (is (thrown? ClassCastException (conj "" \a)))160 (is (thrown? ClassCastException (conj (into-array []) 1)))162 (are [x y] (= x y)163 (conj nil 1) '(1)164 (conj nil 3 2 1) '(1 2 3)166 (conj nil nil) '(nil)167 (conj nil nil nil) '(nil nil)168 (conj nil nil nil 1) '(1 nil nil)170 ; list -> conj puts the item at the front of the list171 (conj () 1) '(1)172 (conj () 1 2) '(2 1)174 (conj '(2 3) 1) '(1 2 3)175 (conj '(2 3) 1 4 3) '(3 4 1 2 3)177 (conj () nil) '(nil)178 (conj () ()) '(())180 ; vector -> conj puts the item at the end of the vector181 (conj [] 1) [1]182 (conj [] 1 2) [1 2]184 (conj [2 3] 1) [2 3 1]185 (conj [2 3] 1 4 3) [2 3 1 4 3]187 (conj [] nil) [nil]188 (conj [] []) [[]]190 ; map -> conj expects another (possibly single entry) map as the item,191 ; and returns a new map which is the old map plus the entries192 ; from the new, which may overwrite entries of the old.193 ; conj also accepts a MapEntry or a vector of two items (key and value).194 (conj {} {}) {}195 (conj {} {:a 1}) {:a 1}196 (conj {} {:a 1 :b 2}) {:a 1 :b 2}197 (conj {} {:a 1 :b 2} {:c 3}) {:a 1 :b 2 :c 3}198 (conj {} {:a 1 :b 2} {:a 3 :c 4}) {:a 3 :b 2 :c 4}200 (conj {:a 1} {:a 7}) {:a 7}201 (conj {:a 1} {:b 2}) {:a 1 :b 2}202 (conj {:a 1} {:a 7 :b 2}) {:a 7 :b 2}203 (conj {:a 1} {:a 7 :b 2} {:c 3}) {:a 7 :b 2 :c 3}204 (conj {:a 1} {:a 7 :b 2} {:b 4 :c 5}) {:a 7 :b 4 :c 5}206 (conj {} (first {:a 1})) {:a 1} ; MapEntry207 (conj {:a 1} (first {:b 2})) {:a 1 :b 2}208 (conj {:a 1} (first {:a 7})) {:a 7}209 (conj {:a 1} (first {:b 2}) (first {:a 5})) {:a 5 :b 2}211 (conj {} [:a 1]) {:a 1} ; vector212 (conj {:a 1} [:b 2]) {:a 1 :b 2}213 (conj {:a 1} [:a 7]) {:a 7}214 (conj {:a 1} [:b 2] [:a 5]) {:a 5 :b 2}216 (conj {} {nil {}}) {nil {}}217 (conj {} {{} nil}) {{} nil}218 (conj {} {{} {}}) {{} {}}220 ; set221 (conj #{} 1) #{1}222 (conj #{} 1 2 3) #{1 2 3}224 (conj #{2 3} 1) #{3 1 2}225 (conj #{3 2} 1) #{1 2 3}227 (conj #{2 3} 2) #{2 3}228 (conj #{2 3} 2 3) #{2 3}229 (conj #{2 3} 4 1 2 3) #{1 2 3 4}231 (conj #{} nil) #{nil}232 (conj #{} #{}) #{#{}} ))235 ;; *** Lists and Vectors ***237 (deftest test-peek238 ; doesn't work for sets and maps239 (is (thrown? ClassCastException (peek #{1})))240 (is (thrown? ClassCastException (peek {:a 1})))242 (are [x y] (= x y)243 (peek nil) nil245 ; list = first246 (peek ()) nil247 (peek '(1)) 1248 (peek '(1 2 3)) 1250 (peek '(nil)) nil ; special cases251 (peek '(1 nil)) 1252 (peek '(nil 2)) nil253 (peek '(())) ()254 (peek '(() nil)) ()255 (peek '(() 2 nil)) ()257 ; vector = last258 (peek []) nil259 (peek [1]) 1260 (peek [1 2 3]) 3262 (peek [nil]) nil ; special cases263 (peek [1 nil]) nil264 (peek [nil 2]) 2265 (peek [[]]) []266 (peek [[] nil]) nil267 (peek [[] 2 nil]) nil ))270 (deftest test-pop271 ; doesn't work for sets and maps272 (is (thrown? ClassCastException (pop #{1})))273 (is (thrown? ClassCastException (pop #{:a 1})))275 ; collection cannot be empty276 (is (thrown? IllegalStateException (pop ())))277 (is (thrown? IllegalStateException (pop [])))279 (are [x y] (= x y)280 (pop nil) nil282 ; list - pop first283 (pop '(1)) ()284 (pop '(1 2 3)) '(2 3)286 (pop '(nil)) ()287 (pop '(1 nil)) '(nil)288 (pop '(nil 2)) '(2)289 (pop '(())) ()290 (pop '(() nil)) '(nil)291 (pop '(() 2 nil)) '(2 nil)293 ; vector - pop last294 (pop [1]) []295 (pop [1 2 3]) [1 2]297 (pop [nil]) []298 (pop [1 nil]) [1]299 (pop [nil 2]) [nil]300 (pop [[]]) []301 (pop [[] nil]) [[]]302 (pop [[] 2 nil]) [[] 2] ))305 ;; *** Lists (IPersistentList) ***307 (deftest test-list308 (are [x] (list? x)309 ()310 '()311 (list)312 (list 1 2 3) )314 ; order is important315 (are [x y] (not (= x y))316 (list 1 2) (list 2 1)317 (list 3 1 2) (list 1 2 3) )319 (are [x y] (= x y)320 '() ()321 (list) '()322 (list 1) '(1)323 (list 1 2) '(1 2)325 ; nesting326 (list 1 (list 2 3) (list 3 (list 4 5 (list 6 (list 7)))))327 '(1 (2 3) (3 (4 5 (6 (7)))))329 ; different data structures330 (list true false nil)331 '(true false nil)332 (list 1 2.5 2/3 "ab" \x 'cd :kw)333 '(1 2.5 2/3 "ab" \x cd :kw)334 (list (list 1 2) [3 4] {:a 1 :b 2} #{:c :d})335 '((1 2) [3 4] {:a 1 :b 2} #{:c :d})337 ; evaluation338 (list (+ 1 2) [(+ 2 3) 'a] (list (* 2 3) 8))339 '(3 [5 a] (6 8))341 ; special cases342 (list nil) '(nil)343 (list 1 nil) '(1 nil)344 (list nil 2) '(nil 2)345 (list ()) '(())346 (list 1 ()) '(1 ())347 (list () 2) '(() 2) ))350 ;; *** Maps (IPersistentMap) ***352 (deftest test-find353 (are [x y] (= x y)354 (find {} :a) nil356 (find {:a 1} :a) [:a 1]357 (find {:a 1} :b) nil359 (find {:a 1 :b 2} :a) [:a 1]360 (find {:a 1 :b 2} :b) [:b 2]361 (find {:a 1 :b 2} :c) nil363 (find {} nil) nil364 (find {:a 1} nil) nil365 (find {:a 1 :b 2} nil) nil ))368 (deftest test-contains?369 ; contains? is designed to work preferably on maps and sets370 (are [x y] (= x y)371 (contains? {} :a) false372 (contains? {} nil) false374 (contains? {:a 1} :a) true375 (contains? {:a 1} :b) false376 (contains? {:a 1} nil) false378 (contains? {:a 1 :b 2} :a) true379 (contains? {:a 1 :b 2} :b) true380 (contains? {:a 1 :b 2} :c) false381 (contains? {:a 1 :b 2} nil) false383 ; sets384 (contains? #{} 1) false385 (contains? #{} nil) false387 (contains? #{1} 1) true388 (contains? #{1} 2) false389 (contains? #{1} nil) false391 (contains? #{1 2 3} 1) true392 (contains? #{1 2 3} 3) true393 (contains? #{1 2 3} 10) false394 (contains? #{1 2 3} nil) false)396 ; numerically indexed collections (e.g. vectors and Java arrays)397 ; => test if the numeric key is WITHIN THE RANGE OF INDEXES398 (are [x y] (= x y)399 (contains? [] 0) false400 (contains? [] -1) false401 (contains? [] 1) false403 (contains? [1] 0) true404 (contains? [1] -1) false405 (contains? [1] 1) false407 (contains? [1 2 3] 0) true408 (contains? [1 2 3] 2) true409 (contains? [1 2 3] 3) false410 (contains? [1 2 3] -1) false412 ; arrays413 (contains? (into-array []) 0) false414 (contains? (into-array []) -1) false415 (contains? (into-array []) 1) false417 (contains? (into-array [1]) 0) true418 (contains? (into-array [1]) -1) false419 (contains? (into-array [1]) 1) false421 (contains? (into-array [1 2 3]) 0) true422 (contains? (into-array [1 2 3]) 2) true423 (contains? (into-array [1 2 3]) 3) false424 (contains? (into-array [1 2 3]) -1) false)426 ; 'contains?' operates constant or logarithmic time,427 ; it WILL NOT perform a linear search for a value.428 (are [x] (= x false)429 (contains? '(1 2 3) 0)430 (contains? '(1 2 3) 1)431 (contains? '(1 2 3) 3)432 (contains? '(1 2 3) 10)433 (contains? '(1 2 3) nil)434 (contains? '(1 2 3) ()) ))437 (deftest test-keys438 (are [x y] (= x y) ; other than map data structures439 (keys ()) nil440 (keys []) nil441 (keys #{}) nil442 (keys "") nil )444 (are [x y] (= x y)445 ; (class {:a 1}) => clojure.lang.PersistentArrayMap446 (keys {}) nil447 (keys {:a 1}) '(:a)448 (diff (keys {:a 1 :b 2}) '(:a :b)) nil ; (keys {:a 1 :b 2}) '(:a :b)450 ; (class (sorted-map :a 1)) => clojure.lang.PersistentTreeMap451 (keys (sorted-map)) nil452 (keys (sorted-map :a 1)) '(:a)453 (diff (keys (sorted-map :a 1 :b 2)) '(:a :b)) nil ; (keys (sorted-map :a 1 :b 2)) '(:a :b)455 ; (class (hash-map :a 1)) => clojure.lang.PersistentHashMap456 (keys (hash-map)) nil457 (keys (hash-map :a 1)) '(:a)458 (diff (keys (hash-map :a 1 :b 2)) '(:a :b)) nil )) ; (keys (hash-map :a 1 :b 2)) '(:a :b)461 (deftest test-vals462 (are [x y] (= x y) ; other than map data structures463 (vals ()) nil464 (vals []) nil465 (vals #{}) nil466 (vals "") nil )468 (are [x y] (= x y)469 ; (class {:a 1}) => clojure.lang.PersistentArrayMap470 (vals {}) nil471 (vals {:a 1}) '(1)472 (diff (vals {:a 1 :b 2}) '(1 2)) nil ; (vals {:a 1 :b 2}) '(1 2)474 ; (class (sorted-map :a 1)) => clojure.lang.PersistentTreeMap475 (vals (sorted-map)) nil476 (vals (sorted-map :a 1)) '(1)477 (diff (vals (sorted-map :a 1 :b 2)) '(1 2)) nil ; (vals (sorted-map :a 1 :b 2)) '(1 2)479 ; (class (hash-map :a 1)) => clojure.lang.PersistentHashMap480 (vals (hash-map)) nil481 (vals (hash-map :a 1)) '(1)482 (diff (vals (hash-map :a 1 :b 2)) '(1 2)) nil )) ; (vals (hash-map :a 1 :b 2)) '(1 2)485 (deftest test-key486 (are [x] (= (key (first (hash-map x :value))) x)487 nil488 false true489 0 42490 0.0 3.14491 2/3492 0M 1M493 \c494 "" "abc"495 'sym496 :kw497 () '(1 2)498 [] [1 2]499 {} {:a 1 :b 2}500 #{} #{1 2} ))503 (deftest test-val504 (are [x] (= (val (first (hash-map :key x))) x)505 nil506 false true507 0 42508 0.0 3.14509 2/3510 0M 1M511 \c512 "" "abc"513 'sym514 :kw515 () '(1 2)516 [] [1 2]517 {} {:a 1 :b 2}518 #{} #{1 2} ))520 (deftest test-get521 (let [m {:a 1, :b 2, :c {:d 3, :e 4}, :f nil, :g false, nil {:h 5}}]522 (is (thrown? IllegalArgumentException (get-in {:a 1} 5)))523 (are [x y] (= x y)524 (get m :a) 1525 (get m :e) nil526 (get m :e 0) 0527 (get m :b 0) 2528 (get m :f 0) nil530 (get-in m [:c :e]) 4531 (get-in m '(:c :e)) 4532 (get-in m [:c :x]) nil533 (get-in m [:f]) nil534 (get-in m [:g]) false535 (get-in m [:h]) nil536 (get-in m []) m537 (get-in m nil) m539 (get-in m [:c :e] 0) 4540 (get-in m '(:c :e) 0) 4541 (get-in m [:c :x] 0) 0542 (get-in m [:b] 0) 2543 (get-in m [:f] 0) nil544 (get-in m [:g] 0) false545 (get-in m [:h] 0) 0546 (get-in m [:x :y] {:y 1}) {:y 1}547 (get-in m [] 0) m548 (get-in m nil 0) m)))550 ;; *** Sets ***552 (deftest test-hash-set553 (are [x] (set? x)554 #{}555 #{1 2}556 (hash-set)557 (hash-set 1 2) )559 ; order isn't important560 (are [x y] (= x y)561 #{1 2} #{2 1}562 #{3 1 2} #{1 2 3}563 (hash-set 1 2) (hash-set 2 1)564 (hash-set 3 1 2) (hash-set 1 2 3) )567 (are [x y] (= x y)568 ; equal classes569 (class #{}) (class (hash-set))570 (class #{1 2}) (class (hash-set 1 2))572 ; creating573 (hash-set) #{}574 (hash-set 1) #{1}575 (hash-set 1 2) #{1 2}577 ; nesting578 (hash-set 1 (hash-set 2 3) (hash-set 3 (hash-set 4 5 (hash-set 6 (hash-set 7)))))579 #{1 #{2 3} #{3 #{4 5 #{6 #{7}}}}}581 ; different data structures582 (hash-set true false nil)583 #{true false nil}584 (hash-set 1 2.5 2/3 "ab" \x 'cd :kw)585 #{1 2.5 2/3 "ab" \x 'cd :kw}586 (hash-set (list 1 2) [3 4] {:a 1 :b 2} #{:c :d})587 #{'(1 2) [3 4] {:a 1 :b 2} #{:c :d}}589 ; evaluation590 (hash-set (+ 1 2) [(+ 2 3) :a] (hash-set (* 2 3) 8))591 #{3 [5 :a] #{6 8}}593 ; special cases594 (hash-set nil) #{nil}595 (hash-set 1 nil) #{1 nil}596 (hash-set nil 2) #{nil 2}597 (hash-set #{}) #{#{}}598 (hash-set 1 #{}) #{1 #{}}599 (hash-set #{} 2) #{#{} 2} ))602 (deftest test-sorted-set603 ; only compatible types can be used604 (is (thrown? ClassCastException (sorted-set 1 "a")))605 (is (thrown? ClassCastException (sorted-set '(1 2) [3 4])))607 ; creates set?608 (are [x] (set? x)609 (sorted-set)610 (sorted-set 1 2) )612 ; equal and unique613 (are [x] (and (= (sorted-set x) #{x})614 (= (sorted-set x x) (sorted-set x)))615 nil616 false true617 0 42618 0.0 3.14619 2/3620 0M 1M621 \c622 "" "abc"623 'sym624 :kw625 () ; '(1 2)626 [] [1 2]627 {} ; {:a 1 :b 2}628 #{} ; #{1 2}629 )630 ; cannot be cast to java.lang.Comparable631 (is (thrown? ClassCastException (sorted-set '(1 2) '(1 2))))632 (is (thrown? ClassCastException (sorted-set {:a 1 :b 2} {:a 1 :b 2})))633 (is (thrown? ClassCastException (sorted-set #{1 2} #{1 2})))635 (are [x y] (= x y)636 ; generating637 (sorted-set) #{}638 (sorted-set 1) #{1}639 (sorted-set 1 2) #{1 2}641 ; sorting642 (seq (sorted-set 5 4 3 2 1)) '(1 2 3 4 5)644 ; special cases645 (sorted-set nil) #{nil}646 (sorted-set 1 nil) #{nil 1}647 (sorted-set nil 2) #{nil 2}648 (sorted-set #{}) #{#{}} ))651 (deftest test-sorted-set-by652 ; only compatible types can be used653 ; NB: not a ClassCastException, but a RuntimeException is thrown,654 ; requires discussion on whether this should be symmetric with test-sorted-set655 (is (thrown? Exception (sorted-set-by < 1 "a")))656 (is (thrown? Exception (sorted-set-by < '(1 2) [3 4])))658 ; creates set?659 (are [x] (set? x)660 (sorted-set-by <)661 (sorted-set-by < 1 2) )663 ; equal and unique664 (are [x] (and (= (sorted-set-by compare x) #{x})665 (= (sorted-set-by compare x x) (sorted-set-by compare x)))666 nil667 false true668 0 42669 0.0 3.14670 2/3671 0M 1M672 \c673 "" "abc"674 'sym675 :kw676 () ; '(1 2)677 [] [1 2]678 {} ; {:a 1 :b 2}679 #{} ; #{1 2}680 )681 ; cannot be cast to java.lang.Comparable682 ; NB: not a ClassCastException, but a RuntimeException is thrown,683 ; requires discussion on whether this should be symmetric with test-sorted-set684 (is (thrown? Exception (sorted-set-by compare '(1 2) '(1 2))))685 (is (thrown? Exception (sorted-set-by compare {:a 1 :b 2} {:a 1 :b 2})))686 (is (thrown? Exception (sorted-set-by compare #{1 2} #{1 2})))688 (are [x y] (= x y)689 ; generating690 (sorted-set-by >) #{}691 (sorted-set-by > 1) #{1}692 (sorted-set-by > 1 2) #{1 2}694 ; sorting695 (seq (sorted-set-by < 5 4 3 2 1)) '(1 2 3 4 5)697 ; special cases698 (sorted-set-by compare nil) #{nil}699 (sorted-set-by compare 1 nil) #{nil 1}700 (sorted-set-by compare nil 2) #{nil 2}701 (sorted-set-by compare #{}) #{#{}} ))704 (deftest test-set705 ; set?706 (are [x] (set? (set x))707 () '(1 2)708 [] [1 2]709 #{} #{1 2}710 {} {:a 1 :b 2}711 (into-array []) (into-array [1 2])712 "" "abc" )714 ; unique715 (are [x] (= (set [x x]) #{x})716 nil717 false true718 0 42719 0.0 3.14720 2/3721 0M 1M722 \c723 "" "abc"724 'sym725 :kw726 () '(1 2)727 [] [1 2]728 {} {:a 1 :b 2}729 #{} #{1 2} )731 ; conversion732 (are [x y] (= (set x) y)733 () #{}734 '(1 2) #{1 2}736 [] #{}737 [1 2] #{1 2}739 #{} #{} ; identity740 #{1 2} #{1 2} ; identity742 {} #{}743 {:a 1 :b 2} #{[:a 1] [:b 2]}745 (into-array []) #{}746 (into-array [1 2]) #{1 2}748 "" #{}749 "abc" #{\a \b \c} ))752 (deftest test-disj753 ; doesn't work on lists, vectors or maps754 (is (thrown? ClassCastException (disj '(1 2) 1)))755 (is (thrown? ClassCastException (disj [1 2] 1)))756 (is (thrown? ClassCastException (disj {:a 1} :a)))758 ; identity759 (are [x] (= (disj x) x)760 nil761 #{}762 #{1 2 3}763 ; different data types764 #{nil765 false true766 0 42767 0.0 3.14768 2/3769 0M 1M770 \c771 "" "abc"772 'sym773 :kw774 [] [1 2]775 {} {:a 1 :b 2}776 #{} #{1 2}} )778 ; type identity779 (are [x] (= (class (disj x)) (class x))780 (hash-set)781 (hash-set 1 2)782 (sorted-set)783 (sorted-set 1 2) )785 (are [x y] (= x y)786 (disj nil :a) nil787 (disj nil :a :b) nil789 (disj #{} :a) #{}790 (disj #{} :a :b) #{}792 (disj #{:a} :a) #{}793 (disj #{:a} :a :b) #{}794 (disj #{:a} :c) #{:a}796 (disj #{:a :b :c :d} :a) #{:b :c :d}797 (disj #{:a :b :c :d} :a :d) #{:b :c}798 (disj #{:a :b :c :d} :a :b :c) #{:d}799 (disj #{:a :b :c :d} :d :a :c :b) #{}801 (disj #{nil} :a) #{nil}802 (disj #{nil} #{}) #{nil}803 (disj #{nil} nil) #{}805 (disj #{#{}} nil) #{#{}}806 (disj #{#{}} #{}) #{}807 (disj #{#{nil}} #{nil}) #{} ))810 ;; *** Queues ***812 (deftest test-queues813 (let [EMPTY clojure.lang.PersistentQueue/EMPTY]814 (are [x y] (= x y)815 EMPTY EMPTY816 (into EMPTY (range 50)) (into EMPTY (range 50))817 (range 5) (into EMPTY (range 5))818 (range 1 6) (-> EMPTY819 (into (range 6))820 pop))821 (are [x y] (not= x y)822 (range 5) (into EMPTY (range 6))823 (range 6) (into EMPTY (range 5))824 (range 0 6) (-> EMPTY825 (into (range 6))826 pop)827 (range 1 6) (-> EMPTY828 (into (range 7))829 pop))))