【问题标题】:Test in Prolog. How to run a unit test that checks if my output file matches the my text file?在 Prolog 中测试。如何运行单元测试来检查我的输出文件是否与我的文本文件匹配?
【发布时间】:2018-12-11 03:04:20
【问题描述】:

我正在使用 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,?]

等等……

我如何使用 plunit(或其他东西?)来检查我的测试文件的所有元素是否都在我的输出文件中返回真/假?

【问题讨论】:

    标签: unit-testing testing prolog swi-prolog plunit


    【解决方案1】:

    read/1 可能就是您要找的东西:

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

    p([a,b,c]).
    

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

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

    【讨论】:

    • 如果我的正确输出与我的测试大小相同,那将起作用。实际上,我的睾丸样本要小得多。但我喜欢这个方向。谢谢!
    猜你喜欢
    • 2021-12-13
    • 2019-07-19
    • 1970-01-01
    • 1970-01-01
    • 2021-02-20
    • 1970-01-01
    • 2017-07-29
    • 2011-12-09
    • 1970-01-01
    相关资源
    最近更新 更多