exercise-10.scm (2255B)
1 (define-library (sicp tests chapter-1 exercise-10) 2 (import (scheme base) 3 (scheme eval) 4 (srfi :1) 5 (srfi :64) 6 (sicp solutions chapter-1 exercise-10)) 7 8 ;;; XXX: No solution. 9 10 (begin 11 12 13 (test-begin "chapter-1-exercise-10") 14 15 (for-each 16 (lambda (test-expr) 17 (test-equal 18 (A 1 10) 19 (eval test-expr 20 (environment '(scheme base) 21 '(sicp solutions chapter-1 exercise-10))))) 22 '((A 1 10) 23 (cond ((= 10 0) 0) 24 ((= 1 0) (* 2 10)) 25 ((= 10 1) 2) 26 (else (A (- 1 1) 27 (A 1 (- 10 1))))) 28 (A (- 1 1) 29 (A 1 (- 10 1))) 30 (A 0 (A 1 9)) 31 (A 0 (A 0 (A 1 8))) 32 (A 0 (A 0 (A 0 (A 1 7)))) 33 (A 0 (A 0 (A 0 (A 0 (A 1 6))))) 34 (A 0 (A 0 (A 0 (A 0 (A 0 (A 1 5)))))) 35 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 1 4))))))) 36 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 1 3)))))))) 37 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 1 2))))))))) 38 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 1 1)))))))))) 39 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 2))))))))) 40 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (* 2 2))))))))) 41 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 8))))))) 42 (A 0 (A 0 (A 0 (A 0 (A 0 (A 0 16)))))) 43 (A 0 (A 0 (A 0 (A 0 (A 0 32))))) 44 (A 0 (A 0 (A 0 (A 0 64)))) 45 (A 0 (A 0 (A 0 128))) 46 (A 0 (A 0 256)) 47 (A 0 512) 48 1024)) 49 50 51 (A 2 4) 52 53 (A 3 3) 54 55 56 57 (A 2 4) 58 (cond ((= 4 0) 0) 59 ((= 2 0) (* 2 4)) 60 ((= 4 1) 2) 61 (else (A (- 2 1) 62 (A 2 (- 4 1))))) 63 (A 1 64 (A 1 (A 2 (- 3 1)))) 65 66 (A 1 67 (A 1 (A 2 (- 3 1)))) 68 (A 1 69 (A 1 (A 2 (- 3 1)))) 70 71 72 (do ((i 0 (+ i 1))) 73 ((> i 10)) 74 (test-equal 75 (* 2 i) 76 (f i))) 77 78 (do ((i 0 (+ i 1))) 79 ((> i 10)) 80 (test-equal 81 (expt 2 i) 82 (g i))) 83 84 (do ((i 0 (+ i 1))) 85 ((> i 5)) 86 (test-equal 87 (do ((m i (- m 1)) 88 (s (expt 1 2) (expt 2 s))) 89 ((= m 0) s)) 90 (h i))) 91 92 '(test-equal 1024 (A 1 10)) 93 '(test-equal 1024 (A 2 4)) 94 95 (test-end "chapter-1-exercise-10") 96 ))