Loading ...
Sorry, an error occurred while loading the content.

Re: [extremeperl] Book: Higher Order Perl

Expand Messages
  • Shae Matijs Erisson
    ... You give a condition, QuickCheck generates a random input and stuffs that into your condition to see if it s true. If it fails you see what input failed.
    Message 1 of 58 , Mar 31 4:29 AM
      Rob Nagler <nagler@...> writes:

      > Does the generative tool automatically compute the boundary conditions?

      You give a condition, QuickCheck generates a random input and stuffs that into
      your condition to see if it's true. If it fails you see what input failed.

      prop_RevUnit :: [Int] -> Bool
      prop_RevUnit x =
      reverse [x] == [x]

      This condition states that the reverse of an input is equal to the input.
      Randomly generated inputs rarely pass this test. (only lists of length 1 or 0)

      prop_RevApp :: [Int] -> [Int] -> Property
      prop_RevApp xs ys = reverse (xs ++ ys) == reverse xs ++ reverse ys

      This claims that list reversal is distributive over list concatenation.

      Properties are half the work with QuickCheck, the other half is generators.
      Usually it's pretty easy.

      For ICFP2003 we generated random terrain with this datatype and generator:

      data Terrain = Road | Start | Goal | Impassable Char

      instance Arbitrary Terrain where
      arbitrary = frequency
      [(10,return Road),
      (7,return (Impassable 'g')),
      (2,return Goal),
      (1,return Start)]

      We then used that to generate totally random maps.
      If you want maps that fulfill a particular condition such as 'connected from
      start to goal' you define that condition and use ==> which filters generated
      data according to a predicate.
      Or you can define a separate generator that always produces connected maps.

      In my opinion, this sort of generative testing is a better approach that single
      case unit testing. It can require more work to get the more general testing.
      I bet you're not surprised.

      QuickCheck has been ported to Common Lisp, Python, Perl.
      The ports do lose something in the process, for a variety of reasons.

      > What do you mean by "better job"? Done faster? Higher quality?

      Done faster, higher quality, and more 'code as communication'. Want details?
      For more on 'communication' see a recent post of mine to the shootout list:
      And if you have any ideas on how to do a 'code as literature' critique website,
      I would really like to know. Maybe there's already such a thing for Perl?
      Programming is the Magic Executable Fridge Poetry, | www.ScannedInAvian.com
      It is machines made of thought, fueled by ideas. | -- Shae Matijs Erisson
    • Tom Vilot
      ... Wait. That sounds like Rob .... ;c) (kidding) ... Wait. That *also* sounds like Rob ... ... (not kidding!)
      Message 58 of 58 , Apr 8, 2005
        Greg C wrote:

        > Consider: projects A and B have identical goals. In project A, you
        > have free
        > rein in your choice of software and hardware tools. However, the
        > manager sets
        > arbitrary deadlines, likes to stand behind people and criticize their
        > code as
        > they type,

        Wait. That sounds like Rob ....
        ;c) (kidding)

        > On project B, the choice of langauge and hardware are made for you and
        > there's
        > only one computer per two programmers. On the other hand, the manager
        > sees his
        > people as people, negotiates requirements and schedules on a realistic
        > basis,
        > trusts his people, follows a set of best practices (be it XP or some
        > other) and
        > chases everyone out of the office at 5:30.

        Wait. That *also* sounds like Rob ...


        (not kidding!)
      Your message has been successfully submitted and would be delivered to recipients shortly.