aboutsummaryrefslogtreecommitdiff
path: root/tests/combinators.scm
blob: 1e4bb236b72af1767c899ddb7d15651e4246262c (about) (plain)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2012, 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2014 Eric Bavier <bavier@member.fsf.org>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (test-combinators)
  #:use-module (guix combinators)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-64)
  #:use-module (ice-9 vlist))

(test-begin "combinators")

(test-equal "fold2, 1 list"
    (list (reverse (iota 5))
          (map - (reverse (iota 5))))
  (call-with-values
      (lambda ()
        (fold2 (lambda (i r1 r2)
                 (values (cons i r1)
                         (cons (- i) r2)))
               '() '()
               (iota 5)))
    list))

(test-equal "fold2, 2 lists"
    (list (reverse '((a . 0) (b . 1) (c . 2) (d . 3)))
          (reverse '((a . 0) (b . -1) (c . -2) (d . -3))))
  (call-with-values
      (lambda ()
        (fold2 (lambda (k v r1 r2)
                 (values (alist-cons k v r1)
                         (alist-cons k (- v) r2)))
               '() '()
               '(a b c d)
               '(0 1 2 3)))
    list))

(let* ((tree (alist->vhash
              '((0 2 3) (1 3 4) (2) (3 5 6) (4 6) (5) (6))
              hashq))
       (add-one (lambda (_ r) (1+ r)))
       (tree-lookup (lambda (n) (cdr (vhash-assq n tree)))))
  (test-equal "fold-tree, single root"
    5 (fold-tree add-one 0 tree-lookup '(0)))
  (test-equal "fold-tree, two roots"
    7 (fold-tree add-one 0 tree-lookup '(0 1)))
  (test-equal "fold-tree, sum"
    16 (fold-tree + 0 tree-lookup '(0)))
  (test-equal "fold-tree, internal"
    18 (fold-tree + 0 tree-lookup '(3 4)))
  (test-equal "fold-tree, cons"
    '(1 3 4 5 6)
    (sort (fold-tree cons '() tree-lookup '(1)) <))
  (test-equal "fold-tree, overlapping paths"
    '(1 3 4 5 6)
    (sort (fold-tree cons '() tree-lookup '(1 4)) <))
  (test-equal "fold-tree, cons, two roots"
    '(0 2 3 4 5 6)
    (sort (fold-tree cons '() tree-lookup '(0 4)) <))
  (test-equal "fold-tree-leaves, single root"
    2 (fold-tree-leaves add-one 0 tree-lookup '(1)))
  (test-equal "fold-tree-leaves, single root, sum"
    11 (fold-tree-leaves + 0 tree-lookup '(1)))
  (test-equal "fold-tree-leaves, two roots"
    3 (fold-tree-leaves add-one 0 tree-lookup '(0 1)))
  (test-equal "fold-tree-leaves, two roots, sum"
    13 (fold-tree-leaves + 0 tree-lookup '(0 1))))

(test-end)

le='2021-11-17 23:05:57 +0100'>2021-11-17gnu: xfce4-cpugraph-plugin: Update to 1.2.5....* gnu/packages/xfce.scm (xfce4-cpugraph-plugin): Update to 1.2.5. Signed-off-by: Ludovic Courtès <ludo@gnu.org> Michael Rohleder 2021-10-31Merge remote-tracking branch 'origin/master' into core-updates-frozenEfraim Flashner 2021-10-28gnu: Add xfce4-dev-tools...This is now needed to build newer lightdm-gtk-greeter versions * gnu/packages/xfce.scm (xfce4-dev-tools): New variable. Signed-off-by: Ludovic Courtès <ludo@gnu.org> Denis 'GNUtoo' Carikli 2021-10-12Merge remote-tracking branch 'origin/master' into core-updates-frozen.Mathieu Othacehe 2021-10-06gnu: mousepad: Update to 0.5.7....* gnu/packages/xfce.scm (mousepad): Update to 0.5.7. [arguments]: Don't explicitly return #t from phases. Tobias Geerinckx-Rice 2021-10-05gnu: catfish: Update to 4.16.3....* gnu/packages/xfce.scm (catfish): Update to 4.16.3. Tobias Geerinckx-Rice 2021-09-26gnu: libxfce4ui: Update to 4.16.1....* gnu/packages/xfce.scm (libxfce4ui): Update to 4.16.1. Signed-off-by: Efraim Flashner <efraim@flashner.co.il> Michael Rohleder 2021-09-26gnu: thunar: Update to 4.16.10....* gnu/packages/xfce.scm (thunar): Update to 4.16.10. Signed-off-by: Efraim Flashner <efraim@flashner.co.il> Michael Rohleder 2021-09-26gnu: xfce4-whiskermenu-plugin: Update to 2.6.0....* gnu/packages/xfce.scm (xfce4-whiskermenu-plugin): Update to 2.6.0. Signed-off-by: Efraim Flashner <efraim@flashner.co.il> Michael Rohleder 2021-09-17Merge branch 'master' into core-updates-frozen... Conflicts: gnu/packages/bioinformatics.scm gnu/packages/chez.scm gnu/packages/docbook.scm gnu/packages/ebook.scm gnu/packages/gnome.scm gnu/packages/linux.scm gnu/packages/networking.scm gnu/packages/python-web.scm gnu/packages/python-xyz.scm gnu/packages/tex.scm gnu/packages/version-control.scm gnu/packages/xml.scm guix/build-system/dune.scm guix/build-system/go.scm guix/build-system/linux-module.scm guix/packages.scm Marius Bakke 2021-09-16gnu: thunar: Revert to 4.16.8 (from 4.17.x development series)....Partly reverts 39cee0f817091fdb482c7a5d518bfaa7bde554d3. Reported by Michael Rohleder <mike@rohleder.de>. * gnu/packages/xfce.scm (thunar): Revert to 4.16.8. Ludovic Courtès 2021-09-15gnu: thunar: Update to 4.17.1....* gnu/packages/xfce.scm (thunar): Update to 4.17.1. [inputs]: Add gvfs. Signed-off-by: Ludovic Courtès <ludo@gnu.org> André A. Gomes 2021-08-12Merge branch 'master' into core-updates-frozen... Conflicts: gnu/packages/algebra.scm gnu/packages/games.scm gnu/packages/golang.scm gnu/packages/kerberos.scm gnu/packages/mail.scm gnu/packages/python.scm gnu/packages/ruby.scm gnu/packages/scheme.scm gnu/packages/tex.scm gnu/packages/tls.scm gnu/packages/version-control.scm Marius Bakke 2021-07-29Merge branch 'master' into core-updates-frozen... Conflicts: gnu/packages/bioinformatics.scm gnu/packages/cmake.scm gnu/packages/curl.scm gnu/packages/emacs-xyz.scm gnu/packages/gpodder.scm gnu/packages/music.scm gnu/packages/patches/glibc-bootstrap-system.patch gnu/packages/python-xyz.scm gnu/packages/shells.scm gnu/packages/statistics.scm Marius Bakke