测试的随机值 - 这种方法的思考? [英] Testing for Random Value - Thoughts on this Approach?

查看:108
本文介绍了测试的随机值 - 这种方法的思考?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

OK,我一直在一个随机图像选择和排队系统(这样你就不会看到相同的图像过于频繁)。

OK, I have been working on a random image selector and queue system (so you don't see the same images too often).

所有进行得顺顺当当(至于我的蹩脚code一样)的直到我到了随机位。我想测试它,但你怎么测试呢?没有 Debug.Assert的(i.IsRandom)(黯然):D

All was going swimmingly (as far as my crappy code does) until I got to the random bit. I wanted to test it, but how do you test for it? There is no Debug.Assert(i.IsRandom) (sadly) :D

所以,我得到了我的大脑它与一些茶浇水后,用下面的来了,我只是想知道如果我能有你的想法?

So, I got my brain on it after watering it with some tea and came up with the following, I was just wondering if I could have your thoughts?


  • 基本上我知道在随机位是问题,所以我认为撕开出一个委托(将被传递给对象的构造函数)。

  • 然后,我创建了pretty多执行相同的逻辑的生活的code类,但会记住private变量选择的值。

  • 然后我扔的代表到现场类,并针对测试:

  • Basically I knew the random bit was the problem, so I ripped that out to a delegate (which would then be passed to the objects constructor).
  • I then created a class that pretty much performs the same logic as the live code, but remembers the value selected in a private variable.
  • I then threw that delegate to the live class and tested against that:

Debug.Assert(myObj.RndVal == RndIntTester.ValuePassed);

但我忍不住想,被我浪费我的时间吗我跑了通过大量的迭代,看它是否在任何时间等跌倒了。

But I couldn't help but think, was I wasting my time? I ran that through lots of iterations to see if it fell over at any time etc.

你觉得我是在浪费我的时间吗?或者可能我已经逃脱了:

Do you think I was wasting my time with this? Or could I have got away with:

<一个href=\"http://stackoverflow.com/questions/122741/testing-for-random-value-thoughts-on-this-approach#122765\">GateKiller's答案提醒我这个:


  • 我要补充一点,我基本上都不希望看到同样的结果比x次以上的Y规格的游泳池。

  • 加入测试容器基本上让我看看随机选择任何的previously选择的图像是的。

  • 我想在技术上这里的东西不是RNG被测试(因为我从来不写了code),但我在期待的随机的从有限的池中的结果的事实,我想跟踪他们。

  • I should add that I basically never want to see the same result more than X number of times from a pool of Y size.
  • The addition of the test container basically allowed me to see if any of the previously selected images were "randomly" selected.
  • I guess technically the thing here being tested in not the RNG (since I never wrote that code) but the fact that am I expecting random results from a limited pool, and I want to track them.

推荐答案

从测试的要求:这样你就不会看到相同的图像往往

Test from the requirement : "so you don't see the same images too often"

询问100张图像。你看到的图像太频繁?

Ask for 100 images. Did you see an image too often?

这篇关于测试的随机值 - 这种方法的思考?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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