Unit testing 在Prolog中进行测试。如何运行单元测试来检查我的输出文件是否与我的文本文件匹配?

Unit testing 在Prolog中进行测试。如何运行单元测试来检查我的输出文件是否与我的文本文件匹配?,unit-testing,testing,prolog,swi-prolog,plunit,Unit Testing,Testing,Prolog,Swi Prolog,Plunit,我正在使用prolog swipl实现一个自然语言生成器 我有一个.txt测试文件,其中包含一些我应该能够以这种格式生成的短语: [goal,identify,type_object,animal,object,cat,event,ran away,when,[last,mont],where,[]] [which,cats,ran away,last,month,?] [goal,identify,type_object,animal,object,dog,event,ran,when,[l

我正在使用prolog swipl实现一个自然语言生成器

我有一个.txt测试文件,其中包含一些我应该能够以这种格式生成的短语:

[goal,identify,type_object,animal,object,cat,event,ran away,when,[last,mont],where,[]]
[which,cats,ran away,last,month,?]

[goal,identify,type_object,animal,object,dog,event,ran,when,[last,mont],where,[]]
[which,dogs,ran away,last,year,?]
等等

我如何使用它或其他东西?要检查我的测试文件的所有元素是否都在我的输出文件中,并返回true/false?

read/1可能是您要查找的内容:

假设我定义了一个事实p/1:

然后我可以从标准输入中读取一个术语,并比较以|开头的行:SWI Prolog表示为用户输入,您的实现可能不同:

?- read(X), p(X).
|: [a,b,c].

X = [a, b, c].

?- read(X), p(X).
|: [].

false.

如果我的正确输出与我的测试大小相同,这将起作用。实际上,我的测试样本要小得多。但我喜欢这个方向。谢谢
?- read(X), p(X).
|: [a,b,c].

X = [a, b, c].

?- read(X), p(X).
|: [].

false.