Debian Codegraph @

%3a78/examples.scm

raw symbols SCIP
1 ; <PLAINTEXT>
2 ; Copyright (c) 2005-2006 Sebastian Egner.
3 ;
4 ; Permission is hereby granted, free of charge, to any person obtaining
5 ; a copy of this software and associated documentation files (the
6 ; ``Software''), to deal in the Software without restriction, including
7 ; without limitation the rights to use, copy, modify, merge, publish,
8 ; distribute, sublicense, and/or sell copies of the Software, and to
9 ; permit persons to whom the Software is furnished to do so, subject to
10 ; the following conditions:
11 ;
12 ; The above copyright notice and this permission notice shall be
13 ; included in all copies or substantial portions of the Software.
14 ;
15 ; THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
16 ; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 ; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 ; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 ; LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 ; OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 ; WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 ;
23 ; -----------------------------------------------------------------------
24
25 ; Lightweight testing (examples)
26 ; ==============================
27 ;
28 ; [email protected]
29 ; in R5RS + SRFI 23 (error) + SRFI 42 (comprehensions)
30 ;
31 ; history of this file:
32 ; SE, 25-Oct-2004: first version
33
34 ; -- portability --
35
36 ; PLT:
37 ; (require (lib "23.ss" "srfi") (lib "42.ss" "srfi")) (load "check.scm")
38 ; (load "examples.scm")
39
40 ; Scheme48:
41 ; ,open srfi-23 srfi-42
42 ; ,load check.scm examples.scm
43
44 ; -- simple test --
45
46 (check (+ 1 1) => 2)
47 (check (+ 1 1) => 3) ; fails
48
49 ; -- different equality predicate --
50
51 (check (vector 1) => (vector 1))
52 (check (vector 1) (=> eq?) (vector 1)) ; fails
53
54 ; -- parametric tests --
55
56 (check-ec (+ 1 1) => 2)
57
58 (check-ec (: x 10) (+ x 1) => (+ x 1) (x))
59
60 (check-ec (: e 100) (positive? (expt 2 e)) => #t (e)) ; fails on fixnums
61
62 (check-ec (: e 100) (:let x (expt 2.0 e)) (= (+ x 1) x) => #f (x)) ; fails
63
64 (check-ec (: e 100) (:let x (expt 2.0 e)) (= (+ x 1) x) => #f)
65
66 (check-ec (: x 10) (: y 10) (: z 10)
67 (* x (+ y z)) => (+ (* x y) (* x z))
68 (x y z)) ; passes with 10^3 cases checked
69
70 ; -- toy examples --
71
72 (define (fib n)
73 (if (<= n 2) 1 (+ (fib (- n 1)) (fib (- n 2)))))
74
75 (check (fib 1) => 1)
76 (check (fib 2) => 1)
77 (check-ec (: n 1 31) (even? (fib n)) => (= (modulo n 3) 0) (n))
78
79 ; -- reporting --
80
81 (check-report)