Testing update with quickcheck

91 views
Skip to first unread message

Cecilia G

unread,
Nov 27, 2014, 9:15:10 AM11/27/14
to chalmer...@googlegroups.com
Hi!

When we are trying to test the update function with quickcheck, it often fails due to indices being out of bounds.
When bounding positions to correct values, we get "Gave up! Only passed 7 tests". Is there a way to get quickcheck to
create better values, without using a new Arbitrary? (since it seems that we should not write an Arbitrary for the Pos type)

Philip Steingrüber

unread,
Nov 27, 2014, 9:17:41 AM11/27/14
to chalmer...@googlegroups.com
I have run into similar problems. I seem to remember that a way of discarding "invalid" test data was shown on one of the lectures. Can't find it now though. :/

David Sands

unread,
Nov 27, 2014, 9:29:29 AM11/27/14
to chalmer...@googlegroups.com, Cecilia G

Generate and throw away bad values is not a sensible strategy as you discovered. QuickCheck just gives up. 
We discussed several ways to tackle this problem in the lecture
  1. Use arbitrary values but apply a function to them to get them in the right “shape”. E.g. If you want a natural number apply abs to an arbitrary integer. 
  2. Define a new data type containing the data you need and make it an instance of Arbitrary by defining the generator you want. Note that Pos is not a new data type, it is just a name for an existing data type. 
  3. Define the generator you need and use the quickCheck function forAll (see the documentation)
— Dave


--
You received this message because you are subscribed to the Google Groups "2014 Functional Programming TDA 452/ DIT142" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chalmers-fp-1...@googlegroups.com.
To post to this group, send email to chalmer...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/chalmers-fp-14/c7099ee5-ee0e-4459-ad1a-55472fe10e87%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages