Hello fellow Racketeers,
while preparing some lecture notes I noticed that sometimes it is useful to have a multiple implementations of single algorithm prepared. As I am playing with this idea, I started to write identical rackunit tests for each of those implementations - which doesn't make much sense. Is there a way to create a test-suite (or anything else) and then apply it to multiple implementations of given procedure(s)?
I can think of two very simple approaches - parameters and syntax macros. I can do both without virtually any effort, but it makes me wonder whether there isn't already a solution for this problem.
You can abstract over test cases with a procedure (as long as you're abstracting over values). If your abstraction has too many arguments, you can bundle them up as a unit and use unit linking instead of function application to combine the pieces. (The main db tests work this way: see db/db-tests/tests/db/{config.rkt,all-tests.rkt} for the signatures, helper units, and linking.)
Another approach is to write the tests in a separate non-module file and include them into different environments for the different implementations. I think that would be a good way to test different implementations of the same macro, for example.
I tried using signatures and units (and btw, this is the first time they look like they can be useful for me), but failed. I will keep on trying - the db-tests are a the best!
Of course this runs two test suites and prints one result - which is far from optimal. The simple case I am preparing for the students is a singly-linked list implementation consisting of the structs and a decent list of operations - some of them implemented in more versions to see the differences. So ideally I want to run one "big" test suite covering the whole module but when there are more implementations, particular test-cases will cover al versions of given procedures.
It is tempting to just write a simple macro for that, but maybe there is a better solution.