diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2016-05-04 17:35:47 +0200 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2016-05-04 23:35:55 +0200 |
| commit | 958dd3ce68733bcd5c1231424c7e4ad39e67594a (patch) | |
| tree | 1f062198e8ab2fe1c8eeb7843f6a27f268fd37a9 /tests | |
| parent | 4b6fa8b33970be414ae035f63ed80b147dcd8200 (diff) | |
utils: Move combinators to (guix combinators).
* guix/utils.scm (compile-time-value, memoize, fold2)
(fold-tree, fold-tree-leaves): Move to...
* guix/combinators: ... here. New file.
* tests/utils.scm ("fold2, 1 list", "fold2, 2 lists")
(fold-tree tests): Move to...
* tests/combinators.scm: ... here. New file.
* Makefile.am (MODULES, SCM_TESTS): Add them.
* gnu/packages.scm, gnu/packages/bootstrap.scm,
gnu/services/herd.scm, guix/build-system/gnu.scm,
guix/build-system/python.scm, guix/derivations.scm,
guix/gnu-maintenance.scm, guix/import/elpa.scm,
guix/scripts/archive.scm, guix/scripts/build.scm,
guix/scripts/graph.scm, guix/scripts/lint.scm,
guix/scripts/size.scm, guix/scripts/substitute.scm,
guix/serialization.scm, guix/store.scm, guix/ui.scm: Adjust imports
accordingly.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/combinators.scm | 85 | ||||
| -rw-r--r-- | tests/utils.scm | 56 |
2 files changed, 85 insertions, 56 deletions
diff --git a/tests/combinators.scm b/tests/combinators.scm new file mode 100644 index 00000000000..1e4bb236b72 --- /dev/null +++ b/tests/combinators.scm | |||
| @@ -0,0 +1,85 @@ | |||
| 1 | ;;; GNU Guix --- Functional package management for GNU | ||
| 2 | ;;; Copyright © 2012, 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org> | ||
| 3 | ;;; Copyright © 2014 Eric Bavier <bavier@member.fsf.org> | ||
| 4 | ;;; | ||
| 5 | ;;; This file is part of GNU Guix. | ||
| 6 | ;;; | ||
| 7 | ;;; GNU Guix is free software; you can redistribute it and/or modify it | ||
| 8 | ;;; under the terms of the GNU General Public License as published by | ||
| 9 | ;;; the Free Software Foundation; either version 3 of the License, or (at | ||
| 10 | ;;; your option) any later version. | ||
| 11 | ;;; | ||
| 12 | ;;; GNU Guix is distributed in the hope that it will be useful, but | ||
| 13 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 15 | ;;; GNU General Public License for more details. | ||
| 16 | ;;; | ||
| 17 | ;;; You should have received a copy of the GNU General Public License | ||
| 18 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | ||
| 19 | |||
| 20 | (define-module (test-combinators) | ||
| 21 | #:use-module (guix combinators) | ||
| 22 | #:use-module (srfi srfi-1) | ||
| 23 | #:use-module (srfi srfi-64) | ||
| 24 | #:use-module (ice-9 vlist)) | ||
| 25 | |||
| 26 | (test-begin "combinators") | ||
| 27 | |||
| 28 | (test-equal "fold2, 1 list" | ||
| 29 | (list (reverse (iota 5)) | ||
| 30 | (map - (reverse (iota 5)))) | ||
| 31 | (call-with-values | ||
| 32 | (lambda () | ||
| 33 | (fold2 (lambda (i r1 r2) | ||
| 34 | (values (cons i r1) | ||
| 35 | (cons (- i) r2))) | ||
| 36 | '() '() | ||
| 37 | (iota 5))) | ||
| 38 | list)) | ||
| 39 | |||
| 40 | (test-equal "fold2, 2 lists" | ||
| 41 | (list (reverse '((a . 0) (b . 1) (c . 2) (d . 3))) | ||
| 42 | (reverse '((a . 0) (b . -1) (c . -2) (d . -3)))) | ||
| 43 | (call-with-values | ||
| 44 | (lambda () | ||
| 45 | (fold2 (lambda (k v r1 r2) | ||
| 46 | (values (alist-cons k v r1) | ||
| 47 | (alist-cons k (- v) r2))) | ||
| 48 | '() '() | ||
| 49 | '(a b c d) | ||
| 50 | '(0 1 2 3))) | ||
| 51 | list)) | ||
| 52 | |||
| 53 | (let* ((tree (alist->vhash | ||
| 54 | '((0 2 3) (1 3 4) (2) (3 5 6) (4 6) (5) (6)) | ||
| 55 | hashq)) | ||
| 56 | (add-one (lambda (_ r) (1+ r))) | ||
| 57 | (tree-lookup (lambda (n) (cdr (vhash-assq n tree))))) | ||
| 58 | (test-equal "fold-tree, single root" | ||
| 59 | 5 (fold-tree add-one 0 tree-lookup '(0))) | ||
| 60 | (test-equal "fold-tree, two roots" | ||
| 61 | 7 (fold-tree add-one 0 tree-lookup '(0 1))) | ||
| 62 | (test-equal "fold-tree, sum" | ||
| 63 | 16 (fold-tree + 0 tree-lookup '(0))) | ||
| 64 | (test-equal "fold-tree, internal" | ||
| 65 | 18 (fold-tree + 0 tree-lookup '(3 4))) | ||
| 66 | (test-equal "fold-tree, cons" | ||
| 67 | '(1 3 4 5 6) | ||
| 68 | (sort (fold-tree cons '() tree-lookup '(1)) <)) | ||
| 69 | (test-equal "fold-tree, overlapping paths" | ||
| 70 | '(1 3 4 5 6) | ||
| 71 | (sort (fold-tree cons '() tree-lookup '(1 4)) <)) | ||
| 72 | (test-equal "fold-tree, cons, two roots" | ||
| 73 | '(0 2 3 4 5 6) | ||
| 74 | (sort (fold-tree cons '() tree-lookup '(0 4)) <)) | ||
| 75 | (test-equal "fold-tree-leaves, single root" | ||
| 76 | 2 (fold-tree-leaves add-one 0 tree-lookup '(1))) | ||
| 77 | (test-equal "fold-tree-leaves, single root, sum" | ||
| 78 | 11 (fold-tree-leaves + 0 tree-lookup '(1))) | ||
| 79 | (test-equal "fold-tree-leaves, two roots" | ||
| 80 | 3 (fold-tree-leaves add-one 0 tree-lookup '(0 1))) | ||
| 81 | (test-equal "fold-tree-leaves, two roots, sum" | ||
| 82 | 13 (fold-tree-leaves + 0 tree-lookup '(0 1)))) | ||
| 83 | |||
| 84 | (test-end) | ||
| 85 | |||
diff --git a/tests/utils.scm b/tests/utils.scm index 854999f670b..a54482e94ce 100644 --- a/tests/utils.scm +++ b/tests/utils.scm | |||
| @@ -97,31 +97,6 @@ | |||
| 97 | (string-replace-substring "/nix/store/chbouib" "/nix/" "/gnu/") | 97 | (string-replace-substring "/nix/store/chbouib" "/nix/" "/gnu/") |
| 98 | (string-replace-substring "" "foo" "bar"))) | 98 | (string-replace-substring "" "foo" "bar"))) |
| 99 | 99 | ||
| 100 | (test-equal "fold2, 1 list" | ||
| 101 | (list (reverse (iota 5)) | ||
| 102 | (map - (reverse (iota 5)))) | ||
| 103 | (call-with-values | ||
| 104 | (lambda () | ||
| 105 | (fold2 (lambda (i r1 r2) | ||
| 106 | (values (cons i r1) | ||
| 107 | (cons (- i) r2))) | ||
| 108 | '() '() | ||
| 109 | (iota 5))) | ||
| 110 | list)) | ||
| 111 | |||
| 112 | (test-equal "fold2, 2 lists" | ||
| 113 | (list (reverse '((a . 0) (b . 1) (c . 2) (d . 3))) | ||
| 114 | (reverse '((a . 0) (b . -1) (c . -2) (d . -3)))) | ||
| 115 | (call-with-values | ||
| 116 | (lambda () | ||
| 117 | (fold2 (lambda (k v r1 r2) | ||
| 118 | (values (alist-cons k v r1) | ||
| 119 | (alist-cons k (- v) r2))) | ||
| 120 | '() '() | ||
| 121 | '(a b c d) | ||
| 122 | '(0 1 2 3))) | ||
| 123 | list)) | ||
| 124 | |||
| 125 | (test-equal "strip-keyword-arguments" | 100 | (test-equal "strip-keyword-arguments" |
| 126 | '(a #:b b #:c c) | 101 | '(a #:b b #:c c) |
| 127 | (strip-keyword-arguments '(#:foo #:bar #:baz) | 102 | (strip-keyword-arguments '(#:foo #:bar #:baz) |
| @@ -136,37 +111,6 @@ | |||
| 136 | (ensure-keyword-arguments '(#:foo 2) '(#:bar 3)) | 111 | (ensure-keyword-arguments '(#:foo 2) '(#:bar 3)) |
| 137 | (ensure-keyword-arguments '(#:foo 2) '(#:bar 3 #:foo 42)))) | 112 | (ensure-keyword-arguments '(#:foo 2) '(#:bar 3 #:foo 42)))) |
| 138 | 113 | ||
| 139 | (let* ((tree (alist->vhash | ||
| 140 | '((0 2 3) (1 3 4) (2) (3 5 6) (4 6) (5) (6)) | ||
| 141 | hashq)) | ||
| 142 | (add-one (lambda (_ r) (1+ r))) | ||
| 143 | (tree-lookup (lambda (n) (cdr (vhash-assq n tree))))) | ||
| 144 | (test-equal "fold-tree, single root" | ||
| 145 | 5 (fold-tree add-one 0 tree-lookup '(0))) | ||
| 146 | (test-equal "fold-tree, two roots" | ||
| 147 | 7 (fold-tree add-one 0 tree-lookup '(0 1))) | ||
| 148 | (test-equal "fold-tree, sum" | ||
| 149 | 16 (fold-tree + 0 tree-lookup '(0))) | ||
| 150 | (test-equal "fold-tree, internal" | ||
| 151 | 18 (fold-tree + 0 tree-lookup '(3 4))) | ||
| 152 | (test-equal "fold-tree, cons" | ||
| 153 | '(1 3 4 5 6) | ||
| 154 | (sort (fold-tree cons '() tree-lookup '(1)) <)) | ||
| 155 | (test-equal "fold-tree, overlapping paths" | ||
| 156 | '(1 3 4 5 6) | ||
| 157 | (sort (fold-tree cons '() tree-lookup '(1 4)) <)) | ||
| 158 | (test-equal "fold-tree, cons, two roots" | ||
| 159 | '(0 2 3 4 5 6) | ||
| 160 | (sort (fold-tree cons '() tree-lookup '(0 4)) <)) | ||
| 161 | (test-equal "fold-tree-leaves, single root" | ||
| 162 | 2 (fold-tree-leaves add-one 0 tree-lookup '(1))) | ||
| 163 | (test-equal "fold-tree-leaves, single root, sum" | ||
| 164 | 11 (fold-tree-leaves + 0 tree-lookup '(1))) | ||
| 165 | (test-equal "fold-tree-leaves, two roots" | ||
| 166 | 3 (fold-tree-leaves add-one 0 tree-lookup '(0 1))) | ||
| 167 | (test-equal "fold-tree-leaves, two roots, sum" | ||
| 168 | 13 (fold-tree-leaves + 0 tree-lookup '(0 1)))) | ||
| 169 | |||
| 170 | (test-assert "filtered-port, file" | 114 | (test-assert "filtered-port, file" |
| 171 | (let* ((file (search-path %load-path "guix.scm")) | 115 | (let* ((file (search-path %load-path "guix.scm")) |
| 172 | (input (open-file file "r0b"))) | 116 | (input (open-file file "r0b"))) |
