随机过程的单元测试?

发布于 2024-09-11 06:59:29 字数 127 浏览 5 评论 0原文

有没有一种合理的方法来对随机过程进行单元测试?例如,假设您已经为特定系统模型编写了模拟器。模拟器根据 rng 的种子随机工作,因此无法预测系统的状态,如果可以的话,每次测试都应该在尝试测试类的任何方法之前使系统进入特定状态。有更好的方法吗?

Is there a sane way to unit test a stochastic process? For example say that you have coded a simulator for a specific system model. The simulator works randomly based on the seeds of the rngs so the state of the system cannot be predicted and if it can be every test should bring the system to a specific state before it attempts to test any method of a class. Is there a better way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

终难愈 2024-09-18 06:59:29

两个明显的选择是消除随机性(即,使用固定的已知种子进行单元测试并从那里继续),或进行统计测试(即运行相同的测试用例一百万次并验证平均值和方差(等)符合预期)。后者可能是对您的系统的更好测试,但您将不得不忍受一些误报。

The two obvious choices are to remove the randomness (that is, use a fixed, known seed for your unit tests and proceed from there), or to test statistically (that is, run the same test case a million times and verify that the mean and variance (etc.) match expectations). The latter is probably a better test of your system, but you'll have to live with some false alarms.

心凉怎暖 2024-09-18 06:59:29

这是一篇不错的博文涵盖了这个主题。基本上,您需要将受控随机性注入到被测试的对象中。

Here's a nice blog post that covers this topic. Basically you will need to inject a controlled randomness into the object under test.

流年已逝 2024-09-18 06:59:29

也许您可以使用 JUnit Theories 来解决这个问题。

http://blogs.oracle.com/jacobc/entry/junit_theories

Maybe you could use JUnit Theories to solve that.

http://blogs.oracle.com/jacobc/entry/junit_theories

冰魂雪魄 2024-09-18 06:59:29

您需要找到系统的 Q0 和 p00。 p00 是预测状态,而 qo 是
计算出的状态。预测的状态可以找到循环系统,即
系统中的最小值,即 k。

you need to find the Q0 and p00 for the system. p00 is the predicted state while qo is
the calculated state.the predicted state can lead to find the recurrant system which is
the smallest value, say k in the system.

一萌ing 2024-09-18 06:59:29

如果您的模型是随机的,那么您可以将输出视为随机生成的样本。然后,在单元测试功能中,您可以使用置信区间执行某种假设检验。如果测试输出在置信区间内,则测试成功。然而,有可能产生假阳性/假阴性。

If your model is stochastic, then you could treat output as a randomly generated sample. Then, in your unit testing function, you could perform some sort of hypothesis testing with confidence interval. If the test output is within the confidence bound, then the test is successful. However, there will be a possibility of generating false positive/false negative.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文