-
Notifications
You must be signed in to change notification settings - Fork 780
/
reducers_test.cljs
37 lines (35 loc) · 1.51 KB
/
reducers_test.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
;; Copyright (c) Rich Hickey. All rights reserved.
;; The use and distribution terms for this software are covered by the
;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
;; which can be found in the file epl-v10.html at the root of this distribution.
;; By using this software in any fashion, you are agreeing to be bound by
;; the terms of this license.
;; You must not remove this notice, or any other, from this software.
(ns cljs.reducers-test
(:require [cljs.test :refer-macros [deftest is]]
[clojure.core.reducers :as r]))
(deftest test-builtin-impls
(is (= 0 (r/fold + nil)))
(is (= [1 2 3 4] (seq (r/reduce r/append! (r/cat) [1 2 3 4]))))
(is (= 10 (r/reduce + (array 1 2 3 4))))
(is (= 11 (r/reduce + 1 (array 1 2 3 4))))
(is (= 10 (r/reduce + (list 1 2 3 4))))
(is (= 11 (r/reduce + 1 (list 1 2 3 4))))
(is (= (r/fold + + [1 2 3])
(r/fold + [1 2 3])
(r/reduce + [1 2 3])
6))
(is (= (r/fold + + (vec (range 2048)))
(r/reduce + (vec (range 2048)))))
(letfn [(f [[ks vs] k v]
[(conj ks k) (conj vs v)])
(g ([] [#{} #{}])
([[ks1 vs1] [ks2 vs2]]
[(into ks1 ks2) (into vs1 vs2)]))]
(is (= (r/reduce f (g) {:a 1 :b 2 :c 3})
(r/fold g f {:a 1 :b 2 :c 3})
[#{:a :b :c} #{1 2 3}]))
(let [m (into {} (for [x (range 2048)] [x (- x)]))]
(is (= (r/reduce f (g) m) (r/fold g f m)))))
;; CLJS-792
(is (= (into [] (r/map identity {})) [])))