Unit testing a method with random behaviour

前端 未结 6 379
梦如初夏
梦如初夏 2020-12-17 08:44

I am writing unit test cases for a game I am working on. When the game starts, the player is positioned randomly, and I have two problems with that:

  1. Since the
6条回答
  •  既然无缘
    2020-12-17 09:18

    As other answers said, random algorithms are deterministic. you can reproduce a sequence if you use the same seed.

    The only situations where I had to deal with a non-deterministic code, is when multithreading was involved. Then, you are dependant on the scheduler of the operating system.

    In those cases, I write the unit-test as a loop, that repeats thousand of times the test code.

提交回复
热议问题