简体   繁体   中英

How do you unit test code that relies on randomly generated numbers?

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.

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.

Any suggestions would be appreciated.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM