This tutorial is based on Lecture 18.
You are given a skeleton with a a
partial emulation of #lang plai/gc2/collector
. Your task the this
tutorial is to write some unit test functions for the collector
API.
For each of the incomplete functions below, complete the function
using (with-heap ....)
, (init-allocator)
, (current-heap)
and the
gc:*function
to yield the specified final heap. Do not update the
heap directly, but through the given gc:*
functions.
(module+ test
(define (flat-2 a b) ....)
(test (flat-2 1 2) #(5 flat 1 flat 2))
(test (flat-2 'flat 'cons) #(5 flat flat flat cons))
(test (flat-2 'cons 'flat) #(5 flat cons flat flat))
(define (cons-2 a b) ....)
(test (cons-2 'first 'rest) #(8 flat first flat rest cons 1 3))
(test (cons-2 1 2) #(8 flat 1 flat 2 cons 1 3))
(test (cons-2 'cons 'cons) #(8 flat cons flat cons cons 1 3))
(define (self-cons) ....)
(test (self-cons) #(4 cons 1 1))
(define (list-3 a b c) ....)
(test (list-3 'cons 'cons 'cons) '#(18 flat cons flat () cons 1 3
flat cons cons 8 5 flat cons cons 13 10 free free))
(test (list-3 'flat 'flat 'flat) '#(18 flat flat flat () cons 1 3
flat flat cons 8 5 flat flat cons 13 10 free free))
(test (list-3 1 2 3) '#(18 flat 3 flat () cons 1 3
flat 2 cons 8 5 flat 1 cons 13 10 free free))
)