Fast generic function dispatch without calling `compile' at runtime
[bpt/guile.git] / test-suite / tests / procs.test
1 ;;;; procss.test --- Procedures. -*- mode: scheme; coding: utf-8; -*-
2 ;;;;
3 ;;;; Copyright (C) 2010 Free Software Foundation, Inc.
4 ;;;;
5 ;;;; This library is free software; you can redistribute it and/or
6 ;;;; modify it under the terms of the GNU Lesser General Public
7 ;;;; License as published by the Free Software Foundation; either
8 ;;;; version 3 of the License, or (at your option) any later version.
9 ;;;;
10 ;;;; This library is distributed in the hope that it will be useful,
11 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ;;;; Lesser General Public License for more details.
14 ;;;;
15 ;;;; You should have received a copy of the GNU Lesser General Public
16 ;;;; License along with this library; if not, write to the Free Software
17 ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19 (define-module (test-procs)
20 #:use-module (srfi srfi-1)
21 #:use-module (test-suite lib))
22
23 (with-test-prefix "common procedures"
24
25 (pass-if "identity"
26 (eq? 'a (identity 'a)))
27
28 (pass-if "const"
29 (and (procedure? (const 'a))
30 (eq? 'a ((const 'a)))
31 (eq? 'a ((const 'a) 'b 'c 'd))))
32
33 (pass-if "negate"
34 (and (procedure? (negate number?))
35 ((negate real?) 'dream)
36 ((negate odd?) 0)))
37
38 (with-test-prefix "compose"
39
40 (pass-if "identity"
41 (eq? 1+ (compose 1+)))
42
43 (pass-if "simple"
44 (= 2.0 ((compose sqrt 1+ 1+) 2)))
45
46 (pass-if "multiple values"
47 (equal? ((compose zip unzip2) '((1 2) (a b)))
48 '((1 2) (a b))))))