如何对依赖于随机生成的数字的测试代码进行单元化? [英] How do you unit test code that relies on randomly generated numbers?

查看:95
本文介绍了如何对依赖于随机生成的数字的测试代码进行单元化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

依赖于您随机生成数据的单元测试代码的最佳方法是什么?我发现了这个问题在堆栈溢出,但有一点不同.我知道您可以使用固定装置来模拟数据库之类的东西,但我认为我要尝试的工作有所不同.

What is the best way to unit test code that relies on you randomly generating data? I found this question on stack overflow but it is a little different. I know that you can use fixtures to mock out something like a database but I think that what I'm trying to do is a little different.

我正在尝试编写一个 adaline神经网络.这需要我随机生成权重,然后随着更多数据显示给网络来调整权重的值.我该如何对这样的单元进行测试?我已经开始为不依赖随机输入的部分编写测试,但是我不知道如何处理该部分.

I'm trying to write an adaline neural network. This requires me to randomly generate weights and then the values for the weights are adjusted as more data is presented to the network. How do I unit test something like this? I've started writing tests for the parts that don't rely on random inputs, but I don't know how to handle this part.

任何建议将不胜感激.

推荐答案

您可以一直使用new Random(seed)获取确定性随机数. 为什么不确定性测试是一个问题?点击此处查看原因

You could use new Random(seed) to get deterministic random number all the time. Why non-deterministic tests are a problem? Click here to see why

这篇关于如何对依赖于随机生成的数字的测试代码进行单元化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆