On 14/10/2013 16:28,
tbra...@google.com wrote:
> Most software tests look like the Prolog code you actually run.
>
> Is it necessary to write tests for Prolog/logic programs?
It is true that a properly written Prolog program can be used as a test.
In practice, that means you can run the program once to compute a result,
and then run it again to verify the result. Obviously, the benefit you get
from this kind of test is limited -- after all, if your program is buggy,
you use the same buggy program for testing. Having said that, executing the
Prolog program in "test mode" (i.e. with all variables already instantiated
to their solutions) may well lead to different control flow in the Prolog
code, so that it is indeed possible to catch a few errors with this method.
This technique is actually more useful for Constraint Logic Programming (CLP),
where the programs tend to be simpler (i.e. more declarative, more test-like).
There, the execution algorithms used in "solving-mode" can be extremely complex,
while running the same program as a test is computationally trivial.
The shortcoming of such a test is of course that you use the same specification
for both computing and testing, i.e. you won't catch errors in the specification.
To do so, you need separate tests that use a different problem formulation, or
explicitly check for conditions that are merely implicit in the program.
The other issue is that you a need a manageable, finite number of concrete
test cases, out of the potentially infinite number of possible call patterns.
Some of these could be generated automatically from the program, I'm pretty
sure that research has been done in this direction.
Cheers,
Joachim