Sometimes I find myself thinking: "I should really write some tests for all
of this!"
But then I ask myself: "Uhm, how can I test some of the inner procedures of
this procedure?"
I sometimes use inner procedures when no other part of the code needs
access to some procedure and it fits purpose-wise into that wrapping
procedure.
It is also helpful to wrap things, which I want to be exchangeable. For
example for some xexpr rendering on a website, I could make a renderer for
the whole website, which then internally is broken down into parts, which
are all implemented by their own procedures, which are inner procedures to
the all-wrapping renderer. This way I can return some procedure which uses
these inner procedures (its in the closure's environment). This seems very
useful to me and I would like to keep some code that way. It also keeps
namespaces cleaner and makes naming easier, because a procedure inside a
wrapping procedure can have simpler names than outside of it in some cases.
However I have this problem of "How to unit test these inner procedures?"
Ideally I would not need to put tests into the wrapping procedure, but
could keep the tests separate in another file.
Here is some code example:
~~~
(define (modulator clazz)
(define (modulo a-number)
(remainder a-number clazz))
modulo)
(let ([my-modulator (modulator 7)])
(displayln "My modulator will do the job!")
(my-modulator 50))
~~~
(OK this is a very artificial example.)
How would I unit test the `modulo` procedure, without taking it outside of
its wrapping procedure? Is there an easy way this can be done? (or maybe
inner procedure unit testing is a big no-no? If so, why?)
--
You received this message because you are subscribed to the Google Groups
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.