arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2509.02012cs.SE
收藏

ProbTest:面向概率程序的单元测试(扩展版)

ProbTest: Unit Testing for Probabilistic Programs (Extended Version)

Katrine Christensen, Mahsa Varshosaz, Raúl Pardo

AI总结:

本文提出黑盒单元测试方法 ProbTest,基于优惠券收集者问题自动确定概率程序所需测试次数并提供统计保证,以 PyTest 插件实现,并在 Gymnasium 和随机数据结构案例中评估。

摘要:

由于概率程序具有随机性,测试它们并非易事。给定一个输入,程序可能会根据其内部潜在的随机选择产生不同的结果。这意味着,测试概率程序的预期结果需要重复执行测试;而确定性程序对每个测试输入可能只需执行一次即可。由此引出以下问题:为了有效测试一个概率程序,我们应当运行多少次?本文提出了一种新颖的黑盒单元测试方法 ProbTest,用于测试概率程序的结果。该方法建立在著名组合问题“优惠券收集者问题”的相关理论之上。使用该方法,开发者可以像往常一样编写单元测试而无需额外付出努力,同时所需的测试执行次数会被自动确定,并为结果提供统计保证。我们将 ProbTest 实现为 PyTest 的一个插件,PyTest 是面向 Python 程序的知名单元测试工具。借助该插件,开发者可以像编写任何其他 Python 程序一样编写单元测试,而必要的测试执行则会被自动处理。我们在来自 Gymnasium 强化学习库以及一种随机化数据结构的案例研究中评估了该方法。

英文摘要:

Testing probabilistic programs is non-trivial due to their stochastic nature. Given an input, the program may produce different outcomes depending on the underlying stochastic choices in the program. This means testing the expected outcomes of probabilistic programs requires repeated test executions unlike deterministic programs where a single execution may suffice for each test input. This raises the following question: how many times should we run a probabilistic program to effectively test it? This work proposes a novel black-box unit testing method, ProbTest, for testing the outcomes of probabilistic programs. Our method is founded on the theory surrounding a well-known combinatorial problem, the coupon collector's problem. Using this method, developers can write unit tests as usual without extra effort while the number of required test executions is determined automatically with statistical guarantees for the results. We implement ProbTest as a plug-in for PyTest, a well-known unit testing tool for python programs. Using this plug-in, developers can write unit tests similar to any other Python program and the necessary test executions are handled automatically. We evaluate the method on case studies from the Gymnasium reinforcement learning library and a randomized data structure.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑