summaryrefslogtreecommitdiff
path: root/tests/utils.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2013-04-14 16:56:08 +0200
committerLudovic Courtès <ludo@gnu.org>2013-04-14 16:56:08 +0200
commit04fd96cac33fa7557e574e54575252564ba27111 (patch)
tree42f0ca2251cf6effb82b9d38f7789e2ad54842a8 /tests/utils.scm
parent77ffd691bfbb152cde94b60aa8df5135d39727c3 (diff)
utils: Add `fold2'.
* gnu/packages.scm (fold2): Remove. * guix/utils.scm (fold2): New procedure. Generalization of the above to one and two lists. * tests/utils.scm ("fold2, 1 list", "fold2, 2 lists"): New tests.
Diffstat (limited to 'tests/utils.scm')
-rw-r--r--tests/utils.scm25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/utils.scm b/tests/utils.scm
index bcdd120a74c..fa7d7b03fd6 100644
--- a/tests/utils.scm
+++ b/tests/utils.scm
@@ -64,6 +64,31 @@
64 ("nixpkgs" "1.0pre22125_a28fe19") 64 ("nixpkgs" "1.0pre22125_a28fe19")
65 ("gtk2" "2.38.0")))) 65 ("gtk2" "2.38.0"))))
66 66
67(test-equal "fold2, 1 list"
68 (list (reverse (iota 5))
69 (map - (reverse (iota 5))))
70 (call-with-values
71 (lambda ()
72 (fold2 (lambda (i r1 r2)
73 (values (cons i r1)
74 (cons (- i) r2)))
75 '() '()
76 (iota 5)))
77 list))
78
79(test-equal "fold2, 2 lists"
80 (list (reverse '((a . 0) (b . 1) (c . 2) (d . 3)))
81 (reverse '((a . 0) (b . -1) (c . -2) (d . -3))))
82 (call-with-values
83 (lambda ()
84 (fold2 (lambda (k v r1 r2)
85 (values (alist-cons k v r1)
86 (alist-cons k (- v) r2)))
87 '() '()
88 '(a b c d)
89 '(0 1 2 3)))
90 list))
91
67(test-assert "define-record-type*" 92(test-assert "define-record-type*"
68 (begin 93 (begin
69 (define-record-type* <foo> foo make-foo 94 (define-record-type* <foo> foo make-foo