有QuickCheck Happstack.State方法的好方法吗? [英] Is there a good way to QuickCheck Happstack.State methods?

查看:123
本文介绍了有QuickCheck Happstack.State方法的好方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一套我想用QuickCheck测试的Happstack.State MACID方法,但是我很难找出最优雅的方法来实现这一点。我遇到的问题是:




  • 评估 Ev monad计算位于 IO monad中,通过 query update

  • 无法创建纯粹的内存中MACID存储; 这是通过设计。因此,在 IO monad中运行的东西意味着每次测试后都有临时文件需要清理。 无法初始化a除了 initialValue 以外的新MACID存储;它不能通过任意生成,除非我公开一个取代批发状态的访问方法。

  • 解决上述所有问题表示仅使用 MonadReader MonadState 特性的函数(并在 Reader中运行测试) 或 State 而不是 Ev ,这意味着放弃使用 getRandom getEventClockTime 等方法定义内部。


我可以看到的唯一选项是:


  • 在丢弃的磁盘MACID存储中运行方法,清理在每次测试之后进行,并且每次从 initialValue 开始建立。

  • 编写方法让大部分代码在 MonadReader MonadState (它更容易测试),并且依靠少量不能快速检查的胶水它调用 getRandom getE如果需要,可以使用ventClockTime



有没有更好的解决方案,我可以忽略它?

$

$ b

解决方案

您可以检出happstack-state附带的quickcheck属性: http: //patch-tag.com/r/mae/happstack/snapshot/current/content/pretty/happstack-state/tests/Happstack/State/Tests



如果您只是在进行测试,并且您想要一个可抛弃的数据存储,那么您可以使用内存保存程序,它只将状态,事件文件和检查点存储在RAM中。如果你失去了力量,那么你的所有状态都会丢失。这对测试来说很好,但不适用于真实的现场服务器。您链接的信息是关于真实的在线服务器,而不仅仅是测试。



这对initialValue问题没有帮助,但它确实使选项1更容易,因为您不必进行任何磁盘清理。



要替换initialValue,您需要创建自己的方法来取代当前批发状态。



类似于:

 
newState :: YourState - >更新YourState()
newState st = put st

或其他东西。


  • jeremy


I have a set of Happstack.State MACID methods that I want to test using QuickCheck, but I'm having trouble figuring out the most elegant way to accomplish that. The problems I'm running into are:

  • The only way to evaluate an Ev monad computation is in the IO monad via query or update.
  • There's no way to create a purely in-memory MACID store; this is by design. Therefore, running things in the IO monad means there are temporary files to clean up after each test.
  • There's no way to initialize a new MACID store except with the initialValue for the state; it can't be generated via Arbitrary unless I expose an access method that replaces the state wholesale.
  • Working around all of the above means writing methods that only use features of MonadReader or MonadState (and running the test inside Reader or State instead of Ev. This means forgoing the use of getRandom or getEventClockTime and the like inside the method definitions.

The only options I can see are:

  • Run the methods in a throw-away on-disk MACID store, cleaning up after each test and settling for starting from initialValue each time.
  • Write the methods to have most of the code run in a MonadReader or MonadState (which is more easily testable), and rely on a small amount of non-QuickCheck-able glue around it that calls getRandom or getEventClockTime as necessary.

Is there a better solution that I'm overlooking?

解决方案

You might checkout out the quickcheck properties that are included with happstack-state:

http://patch-tag.com/r/mae/happstack/snapshot/current/content/pretty/happstack-state/tests/Happstack/State/Tests

If you are just doing testing, and you want a throw-away data store, then you can use the memory saver, which just stores the state, event files, and checkpoints in RAM. If you lose power, then all your state would be lost. That is fine for tests, but not for a real live server. That message you linked to was talk about real live servers, not just testing.

That won't help with the initialValue issue, but it does make option 1 easier since you don't have to do any disk cleanup.

To replace the initialValue, you would need to create your own method that replaces the current state wholesale.

something like:

newState :: YourState -> Update YourState ()
newState st = put st

or something.

  • jeremy

这篇关于有QuickCheck Happstack.State方法的好方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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