I am new to scheme, and write code on SICP these days with PLT scheme.
I find it is an easy tool.
But when I use their test-engine (see simple code below), I found the
check-expect don't work as I expected. But the maintainer of PLT told
me it's not a bug. Any suggestions are welcome :)
;; check-expect will always find a to be the last set! value, Am I
wrong?
(require test-engine/scheme-tests)
(define a 'b)
(check-expect (eq? a 'b) #f) ; a = 'c, wrong?
(check-expect (eq? a 'c) #t)
(set! a 'c)
(check-expect (eq? a 'c) #t)
(test)
Best regards.
Shenli
I am not a PLT user and I do not know how CHECK-EXPECT and TEST behave
exactly, but skimming the PLT documentation I *guess* what follows.
Running the code:
(define a 'b)
(write (eq? a 'b))
(newline)
(write (eq? a 'c))
(newline)
(set! a 'c)
(write (eq? a 'c))
(newline)
prints:
#t
#f
#t
which is what we expect. But CHECK-EXPECT and the final TEST do
something different: they accumulate tests to be run later. The
following code prints the results of the accumulated expressions:
(define test-closures '())
(define a 'b)
(set! test-closures (cons (lambda ()
(write (eq? a 'b))
(newline))
test-closures))
(set! test-closures (cons (lambda ()
(write (eq? a 'c))
(newline))
test-closures))
(set! a 'c)
(set! test-closures (cons (lambda ()
(write (eq? a 'c))
(newline))
test-closures))
(map (lambda (closure)
(closure))
(reverse test-closures))
this program prints:
#f
#t
#t
If you are a beginner, you are not yet acquainted with the concept of
closures, so you will not be able to understand this code. (SICP does
not use the word "closure" with the meaning I do here, it uses
"procedures with free variables"). If this is the case, for the time
being avoid the use of SET! when possible, and trust yourself that you
will be able to understand everything going on with the study.
--
Marco Maggi
We have a number of scattered test suite libraries and
we plan to sort the, out going forward. For now, you can
solve your immediate problem using (test) to force
running the tests earlier (before the mutation happens),
or you can go with a more traditional test tool like
schemeunit.