![]() |
QuickCheck
1 Attachment(s)
A library for automated specification-based testing. Inspired by QuickCheck, but pretty different because of how different Haskell is from GS2.
To use QuickCheck, you define a function which returns true or false based on if the defined test succeeds: PHP Code:
Now, here comes the QuickCheck magic: PHP Code:
Then we pass it to quickCheck(domain, testFunction), which will run this.bound many trials using a different arbitrary value each time. All together now: PHP Code:
Here is the output: NPC Code:Succeeded 100 times. First check worked, second one failed on the second trial (which used the number 24, and was indeed out of bounds). Looks like it works. Here is another more advanced example: PHP Code:
It then gets passed through a function we want to test (in this case, introsort). If the condition evaluates to true, that means the sort worked! Output: NPC Code:Succeeded 100 times. Looks like our introsort function is working fine. Those were two simple examples, you could get more complicated, and I may write an article about doing real-world test cases. I may also update this script at some point to make it more powerful. Only works in v6, sorry! For this to work you also need utility_bind. |
| All times are GMT +2. The time now is 03:44 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.