learning-sicp

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

exercise-23.scm (3393B)


      1 (define-library (sicp tests chapter-3 exercise-23)
      2   (import (scheme base))
      3   (import (scheme write))
      4 
      5   (import (srfi :64))
      6 
      7   (import (sicp solutions chapter-3 exercise-23))
      8 
      9   (begin
     10     (test-begin "chapter-3-exercise-23")
     11 
     12     (define (test-equal-print-deque string-ratsui deque-matsui)
     13       (define string-port (open-output-string))
     14 
     15       (print-deque deque-matsui string-port)
     16 
     17       (print-deque deque-matsui) (newline)
     18 
     19       (define string-matsui
     20         (get-output-string string-port))
     21 
     22       (test-equal string-ratsui string-matsui))
     23 
     24     (define q1 (make-deque))
     25     (test-equal-print-deque "()" q1)
     26     (test-error (front-deque q1))
     27     (test-error (rear-deque q1))
     28 
     29     (rear-insert-deque! q1 1)
     30     (test-equal-print-deque "(1)" q1)
     31     (test-equal
     32         1
     33       (front-deque q1))
     34     (test-equal
     35         1
     36       (rear-deque q1))
     37 
     38     (rear-insert-deque! q1 2)
     39     (test-equal-print-deque "(1 2)" q1)
     40     (test-equal
     41         1
     42       (front-deque q1))
     43     (test-equal
     44         2
     45       (rear-deque q1))
     46 
     47     (rear-insert-deque! q1 3)
     48     (test-equal-print-deque "(1 2 3)" q1)
     49     (test-equal
     50         1
     51       (front-deque q1))
     52     (test-equal
     53         3
     54       (rear-deque q1))
     55 
     56     (rear-insert-deque! q1 4)
     57     (test-equal-print-deque "(1 2 3 4)" q1)
     58     (test-equal
     59         1
     60       (front-deque q1))
     61     (test-equal
     62         4
     63       (rear-deque q1))
     64 
     65 
     66     (front-delete-deque! q1)
     67     (test-equal-print-deque "(2 3 4)" q1)
     68     (test-equal
     69         2
     70       (front-deque q1))
     71     (test-equal
     72         4
     73       (rear-deque q1))
     74 
     75 
     76     (front-delete-deque! q1)
     77     (test-equal-print-deque "(3 4)" q1)
     78     (test-equal
     79         3
     80       (front-deque q1))
     81     (test-equal
     82         4
     83       (rear-deque q1))
     84 
     85 
     86     (front-delete-deque! q1)
     87     (test-equal-print-deque "(4)" q1)
     88     (test-equal
     89         4
     90       (front-deque q1))
     91     (test-equal
     92         4
     93       (rear-deque q1))
     94 
     95 
     96 
     97     (front-delete-deque! q1)
     98     (test-equal-print-deque "()" q1)
     99     (test-error
    100       (front-deque q1))
    101     (test-error
    102       (rear-deque q1))
    103 
    104     (front-insert-deque! q1 1)
    105     (test-equal-print-deque "(1)" q1)
    106     (test-equal
    107         1
    108       (front-deque q1))
    109     (test-equal
    110         1
    111       (rear-deque q1))
    112 
    113     (front-insert-deque! q1 2)
    114     (test-equal-print-deque "(2 1)" q1)
    115     (test-equal
    116         2
    117       (front-deque q1))
    118     (test-equal
    119         1
    120       (rear-deque q1))
    121 
    122     (front-insert-deque! q1 3)
    123     (test-equal-print-deque "(3 2 1)" q1)
    124     (test-equal
    125         3
    126       (front-deque q1))
    127     (test-equal
    128         1
    129       (rear-deque q1))
    130 
    131     (front-insert-deque! q1 4)
    132     (test-equal-print-deque "(4 3 2 1)" q1)
    133     (test-equal
    134         4
    135       (front-deque q1))
    136     (test-equal
    137         1
    138       (rear-deque q1))
    139 
    140     (rear-delete-deque! q1)
    141     (test-equal-print-deque "(4 3 2)" q1)
    142     (test-equal
    143         4
    144       (front-deque q1))
    145     (test-equal
    146         2
    147       (rear-deque q1))
    148 
    149     (rear-delete-deque! q1)
    150     (test-equal-print-deque "(4 3)" q1)
    151     (test-equal
    152         4
    153       (front-deque q1))
    154     (test-equal
    155         3
    156       (rear-deque q1))
    157 
    158     (rear-delete-deque! q1)
    159     (test-equal-print-deque "(4)" q1)
    160     (test-equal
    161         4
    162       (front-deque q1))
    163     (test-equal
    164         4
    165       (rear-deque q1))
    166 
    167     (rear-delete-deque! q1)
    168     (test-equal-print-deque "()" q1)
    169     (test-error (front-deque q1))
    170     (test-error (rear-deque q1))
    171 
    172 
    173     (test-end "chapter-3-exercise-23")))