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)

lément Lassieur 2023-12-27gnu: Add torbrowser....* gnu/packages/tor.scm (torbrowser): New variable. (torbrowser-assets): New variable. * gnu/packages/browser-extensions.scm (noscript): New variable. (noscript/icecat): New variable. Co-authored-by: André Batista <nandre@riseup.net> Change-Id: I73dc53905e4a028108bb34aae07e44256cf16c85 Clément Lassieur 2023-12-18gnu: ublock-origin: Update to 1.54.0....* gnu/packages/browser-extensions.scm (ublock-origin): Update to 1.54.0. (ublock-main-assets): Update to 76bd7cb53036a36f7e7df5ee9173f588ba8aa966. (ublock-prod-assets): Update to a379a168fc149ffbd6d10cd0700d4ab4801e57f2. Change-Id: I0296b45b684562afaef859b0144c875ff05cd2d8 Clément Lassieur 2023-12-10gnu: Add KeePassXC-Browser....* gnu/packages/browser-extensions.scm (keepassxc-browser) (keepassxc-browser-icecat): New variable. Change-Id: I6f85228e4e012f3e5f8c913fda38287255573604 Ludovic Courtès 2023-11-10gnu: ublock-origin: Update to 1.53.2....* gnu/packages/browser-extensions.scm (ublock-origin): Update to 1.53.2. (ublock-main-assets): Update to d93605b8584df8cd47bcc91b3d932feecd9e3a2a. (ublock-prod-assets): Update to 1d3df32ef6672763f44b27a95fd5cb3b5770d5e2. Change-Id: Ifd853835137ad7be5a0322d6a8e438f23e7ecb09 Clément Lassieur 2023-11-06gnu: ublock-origin: Update to 1.53.0....* gnu/packages/browser-extensions.scm (ublock-origin): Update to 1.53.0. (ublock-main-assets): Update to d573d4db0bccb3f99fa8845c2b1dcb79103007d3. (ublock-prod-assets): Update to c7cfd8fb7e4ea07051f55f370d504c78e6a8e023. Change-Id: I1c9ac9e130bb8146904229f951de9b42d5c84479 Clément Lassieur 2023-11-04gnu: passff-host: Add explicit references to inputs and remove some....This removes ‘coreutils’, ‘grep’, ‘sed’, ‘which’, ‘bash-minimal’ and ‘gnu-make’ inputs, which were only used by the Makefile and install_host_app.sh. Instead of running install_host_app.sh (through ‘make’) which does a few text substitutions, do the text substitutions with Scheme code. This simplifies things and avoids unnecessary native inputs. * gnu/packages/browser-extensions.scm (passff-host)[build-system]: Change to copy-build-system. [arguments]: Copy passff.json and passff.py. Do text substitutions on them rather than running make. Refer to ‘password-store’ and ‘python’ through inputs rather than directly. [inputs]: Add PASSWORD-STORE and PYTHON. Change-Id: I8fdb757516a7c30eae36b15f2a8d91e1445b19a5 Clément Lassieur 2023-10-29gnu: passff-host: Fix builder issues....* gnu/packages/browser-extensions.scm (passff-host)[arguments]: Use `patch-shebang` instead of wrong `substitute*`, add newline after substitution. Change-Id: I6cd1d681e9e84bdeb24943dfe1d85d996f1a262b Clément Lassieur 2023-10-28gnu: passff-host: Refactor builder....* gnu/packages/browser-extensions.scm (passff-host)[arguments]: Refactor builder. Change-Id: I42cb5e6b4808a8b2025d20654c57392f79c01a5c Clément Lassieur 2023-10-25gnu: Add passff....* gnu/packages/browser-extensions.scm (passff-host): New variable. (passff): New variable. Change-Id: I0f6f4b0c319e5cffd0940421a4d8bdc73d8d806b Clément Lassieur 2023-10-23gnu: icecat: Support Guix packaged extensions and native manifests....* gnu/build/icecat-extension.scm: New file with a MAKE-ICECAT-EXTENSION procedure that makes sure the add-on directory is a symlink, so that Icecat can normalize it into a package store path. * gnu/local.mk (dist_patch_DATA): Register it, as well as new patches. * gnu/packages/browser-extensions.scm (ublock-origin)[properties]: Store the add-on ID so that it is accessible in MAKE-ICECAT-EXTENSION. [arguments]: Use the add-on ID as root directory. (ublock-origin/icecat): New procedure. * gnu/packages/gnuzilla.scm (icecat-minimal)[arguments]: Rewrite the unused 'apply-guix-specific-patches' phase so that it applies the following two patches. [native-search-paths]: New field. * gnu/packages/patches/icecat-compare-paths.patch: New patch that compares add-on paths (which are package store paths) to detect package changes. * gnu/packages/patches/icecat-use-system-wide-dir.patch: New patch that replaces "/usr/lib/mozilla" (the system-wide directory for extensions and native manifests) with "$ICECAT_SYSTEM_DIR". Clément Lassieur 2023-09-28gnu: ublock-origin: Update to 1.51.0....* gnu/packages/browser-extensions.scm (ublock-main-assets): Add origin. (ublock-prod-assets): Add origin. (ublock-origin): Update to 1.51.0. [source]: Dropped (recursive? #t). [arguments]: Rewrite phase do-not-depend-on-git. Use gexp. Signed-off-by: Ludovic Courtès <ludo@gnu.org> Nicolas Graves