0

I'm writing an assignment for a prolog class and I'm stuck on something simple. I've written a bunch of logic in a file called question1.pl

I'm using SWI on Mac OS X, so at the command prompt I do this:

swilg
consult('question1.pl').

to load the file, then to test it I do:

?- father(homer,bart).
true
?- father(marge,bart).
false

and so on.

My question is, how do I write a "test script" for my code?

I'm assuming I should write something like question1-tests.pl that looks like this:

(write 'test1, should be true').
father(homer,bart).
(write 'test2, should be false').
father(marge,bart).

But how do I run that script?

Sorry, I know this is simple, but I'm stuck. Thanks!

Autonomous
  • 8,935
  • 1
  • 38
  • 77

2 Answers2

0

Answering my own question, I figured out I can add this to my question1.pl ...

doTests:-write('Test1, should be true'),nl,father(homer,bart).

And simply run

?- doTests

To get output. Sufficient for my assignment needs.

0

Not sure if this is the best way, but you can make a script like this:

swipl <<END
[question1].
write('test1, should be true').
father(homer,bart).
write('test2, should be false').
father(marge,bart).
END