Вот небольшой тест:
:- begin_tests(tuturuu).
test(foo) :- Expected=[a,b],Got=[a,b,c],verdict(foo,Expected,Got).
% helper: transform lists A,B into ordered sets As,Bs
setify(A,B,As,Bs) :- % A,B -> As,Bs
list_to_ord_set(A,As), % A->As
list_to_ord_set(B,Bs). % B->Bs
% did the test pass? set-compare Expected and Got
verdict(Value,Expected,Got) :- % V,E,G -> b?
setify(Expected,Got,Eos,Gos),
format("For ~w, expected ~w and got ~w\n",[Value,Eos,Gos]),
ord_seteq(Eos,Gos)
-> true ; (format("For ~w, expected ~w but got ~w\n",[Value,Eos,Gos]),fail).
:- end_tests(tuturuu).
rt :- run_tests(tuturuu).
Когда я загружаю его в SWI-Prolog:
?- [foo].
Warning: /home/somone/foo.pl:13:
Warning: Singleton variable in branch: Eos
Warning: Singleton variable in branch: Gos
true.
Ветвь ->
не имеет доступа к (локальной ) переменные Eos
и Gos
? Но почему?
У него есть доступ к Value
, потому что тот появляется в голове, я полагаю.
И действительно:
?- rt.
% PL-Unit: tuturuu For foo, expected [a,b] and got [a,b,c]
For foo, expected _29026 but got _29032 <--- YUP NO ACCESS
ERROR: /home/someone/foo.pl:3:
test foo: failed
done
% 1 test failed
% 0 tests passed
false.
Это на самом деле не видно почему возникает такое ограничение, ожидайте, что, возможно, это часть, которая не была реализована в компиляторе?
(Кстати, нам нужен один из тех, которые "держат полосу в зеленом windows" для модульного тестирования из Мир Java, вот так: (украден у здесь )
![junit test bar](https://i.stack.imgur.com/ZSBw7.png)