如何使用XSB Prolog进行单元测试?有图书馆吗?或者是否有可能以某种方式plunit
在XSB中使用SWI-Prolog的库?
如果没有可用的XSB测试库(或其他Prologs没有与之兼容plunit
),这个问题的变体可能是:你如何测试你的Prolog代码?您是否使用喜欢的模式进行测试?
我正在编写一个prolog程序来检查变量是否是整数.我"返回"结果的方式很奇怪,但我认为回答我的问题并不重要.
我已经写了通过单元测试此行为; 他们来了...
foo_test.pl
:- begin_tests('foo').
:- consult('foo').
test('that_1_is_recognised_as_int') :-
count_ints(1, 1).
test('that_atom_is_not_recognised_as_int') :-
count_ints(arbitrary, 0).
:- end_tests('foo').
:- run_tests.
Run Code Online (Sandbox Code Playgroud)
这是通过这些测试的代码......
foo.pl
count_ints(X, Answer) :-
integer(X),
Answer is 1.
count_ints(X, Answer) :-
\+ integer(X),
Answer is 0.
Run Code Online (Sandbox Code Playgroud)
测试正在通过,这很好,但我在运行它时会收到警告.这是运行测试时的输出...
?- ['foo_test'].
% foo compiled into plunit_foo 0.00 sec, 3 clauses
% PL-Unit: foo
Warning: /home/brandon/projects/sillybin/prolog/foo_test.pl:11:
/home/brandon/projects/sillybin/prolog/foo_test.pl:4:
PL-Unit: Test that_1_is_recognised_as_int: Test succeeded with choicepoint
. done
% All 2 tests passed
% foo_test …
Run Code Online (Sandbox Code Playgroud)