Skip to content

Commit a656eca

Browse files
committed
- test ObjMap & HashMap
1 parent 2b4a937 commit a656eca

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

src/test/cljs/cljs/collections_test.cljs

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1168,10 +1168,63 @@
11681168
(is (every? keyword? (keys c)))
11691169
(is (= (set [:a :b :c]) (set (keys c)))))
11701170
(is (= (obj-map :a 1 :b 2 :c 3)
1171-
(obj-map :a 1 :b 2 :c 3))))
1171+
(obj-map :a 1 :b 2 :c 3)))
1172+
(is (= (obj-map :a 1 :b 2)
1173+
(into (obj-map) [[:a 1] [:b 2]])))
1174+
(is (= (merge-with +
1175+
(obj-map :a 1 :b 2)
1176+
(obj-map :a 1 :b 2))
1177+
(into (obj-map) [[:a 2] [:b 4]])))
1178+
(is (= (transient (obj-map :a 1 :b 2))
1179+
(obj-map :a 1 :b 2))))
1180+
1181+
(deftest test-hash-map
1182+
(let [a (simple-hash-map)]
1183+
(is (empty? a))
1184+
(is (zero? (count a))))
1185+
(let [b (simple-hash-map :a 1)]
1186+
(is (not (empty? b)))
1187+
(is (== 1 (count b))))
1188+
(let [c (simple-hash-map :a 1 :b 2 :c 3)]
1189+
(is (== 3 (count c)))
1190+
(is (= 1 (get c :a)))
1191+
(is (= 1 (:a c)))
1192+
(is (every? keyword? (keys c)))
1193+
(is (= (set [:a :b :c]) (set (keys c)))))
1194+
(is (= (simple-hash-map :a 1 :b 2 :c 3)
1195+
(simple-hash-map :a 1 :b 2 :c 3)))
1196+
(is (= (simple-hash-map :a 1 :b 2)
1197+
(into (simple-hash-map) [[:a 1] [:b 2]])))
1198+
(is (= (merge-with +
1199+
(simple-hash-map :a 1 :b 2)
1200+
(simple-hash-map :a 1 :b 2))
1201+
(into (simple-hash-map) [[:a 2] [:b 4]])))
1202+
(is (= (transient (simple-hash-map :a 1 :b 2))
1203+
(simple-hash-map :a 1 :b 2))))
11721204

11731205
(comment
11741206

11751207
(run-tests)
11761208

1209+
(defn simple-group-by
1210+
[f coll]
1211+
(persistent!
1212+
(reduce
1213+
(fn [ret x]
1214+
(let [k (f x)]
1215+
(assoc! ret k (conj (get ret k (. Vector -EMPTY)) x))))
1216+
(transient (. ObjMap -EMPTY)) coll)))
1217+
1218+
(simple-group-by
1219+
:ns
1220+
'[{:ns foo :name woz}
1221+
{:ns bar :name goz}
1222+
{:ns bar :name baz}
1223+
{:ns foo :name naz}])
1224+
1225+
(get (simple-hash-map :a 1 :b 2 :c 3) :a)
1226+
1227+
(#'scan-array-equiv 2 :a
1228+
(unchecked-get (. (simple-hash-map :a 1 :b 2 :c 3) -hashobj) (hash :a)))
1229+
11771230
)

0 commit comments

Comments
 (0)