summaryrefslogtreecommitdiff
path: root/test/core.fnl
diff options
context:
space:
mode:
authorAndrey Orst <andreyorst@gmail.com>2020-11-10 09:59:12 +0300
committerAndrey Orst <andreyorst@gmail.com>2020-11-10 09:59:12 +0300
commit61345c5ace172f3c6f133f8ffb09722c5b9a9b08 (patch)
tree43ef5626edbac44f14762ba024d82294c3220324 /test/core.fnl
parentd69cf3fb7a39f6007acd59a7dfb4e49fc70f6e4d (diff)
fix(tests): fix reduce test, and add more docstrings
Diffstat (limited to 'test/core.fnl')
-rw-r--r--test/core.fnl20
1 files changed, 10 insertions, 10 deletions
diff --git a/test/core.fnl b/test/core.fnl
index 01a7e0c..2a5e38f 100644
--- a/test/core.fnl
+++ b/test/core.fnl
@@ -66,18 +66,17 @@
(require :core))
(deftest equality
- (testing "eq"
+ (testing "comparing basetypes"
(assert* (not (pcall eq)))
- ;; comparing basetypes
(assert-eq 1 1)
(assert-ne 1 2)
(assert* (eq 1 1 1 1 1))
(assert-eq 1.0 1.0)
(assert* (eq 1.0 1.0 1.0))
(assert* (eq 1.0 1.0 1.0))
- (assert* (eq "1" "1" "1" "1" "1"))
+ (assert* (eq "1" "1" "1" "1" "1")))
- ;; deep comparison
+ (testing "deep comparison"
(assert* (eq []))
(assert-eq [] [])
(assert-eq [] {})
@@ -248,19 +247,20 @@
(assert-eq (reduce add 10 [1]) 11)
(assert-eq (reduce add 10 nil) 10)
(assert* (not (pcall reduce)))
- (assert* (not (pcall reduce add)))
+ (assert* (not (pcall reduce add))))
+ (testing "reduce reference implementation"
(fn mapping [f]
(fn [reducing]
(fn [result input]
(reducing result (f input)))))
- (fn reduce- [f init tbl]
- (if (and tbl (> (length tbl) 0))
- (reduce f (f init (first tbl)) (rest tbl))
- init))
+ (fn reduce- [f init [x & tbl]]
+ (if x (reduce- f (f init x) tbl) init))
- (assert-eq (reduce add (range 10)) (reduce- add 0 (range 10))))
+ (assert-eq (reduce add (range 10)) (reduce- add 0 (range 10)))
+ (assert-eq (reduce ((mapping inc) add) 0 (range 10))
+ (reduce- ((mapping inc) add) 0 (range 10))))
(testing "filter"
(assert* (not (pcall filter)))