learning-sicp

My embarrassing half assed SICP run.
git clone https://kaka.farm/~git/learning-sicp
Log | Files | Refs

exercise-17.scm (826B)


      1 (define-library (sicp tests chapter-3 exercise-17)
      2   (import (scheme base))
      3   (import (srfi :64))
      4   (import (only (sicp solutions chapter-3 exercise-17) count-pairs))
      5 
      6   (begin
      7     (test-begin "chapter-3-exercise-17")
      8 
      9     (define three-pairs '(1 2 3))
     10 
     11     (test-equal
     12         3
     13       (count-pairs three-pairs))
     14 
     15     (define four-pairs
     16       (let ([a (list 1 2)]
     17             [b (list 3)])
     18         (set-car! (cdr a) b)
     19         (set-cdr! (cdr a) b)
     20         a))
     21 
     22     (test-equal
     23         3
     24       (count-pairs four-pairs))
     25 
     26     (define seven-pairs
     27       (let ([a (list 1)]
     28             [b (list 2)]
     29             [c (list 3)])
     30         (set-car! a b)
     31         (set-cdr! a b)
     32         (set-car! b c)
     33         (set-cdr! b c)
     34         a))
     35 
     36     (test-equal
     37         3
     38       (count-pairs seven-pairs))
     39 
     40     (test-end "chapter-3-exercise-17")))