As an aside to the discussion at hand, what papers/books/online
articles are good to read to learn about how to come up with good
properties and generators?

On Wed, Apr 30, 2014 at 3:36 PM, Alex Miller <a...@puredanger.com> wrote:
> The only hard parts about property based testing are the properties and the
> generators. ;)
>
> On Wednesday, April 30, 2014 6:38:19 AM UTC-5, henry w wrote:
>>
>> Hi, I wanted to get started with clojure.test.check (formerly
>> simple-check) and I am new to property based testing.
>>
>> I plucked clojure.core/group-by for no particular reason as a function to
>> test.
>>
>> I started by stating some properties i think should hold:
>>
>> ;; 1. applying the grouping key function to each member in a grouping
>> should result in the grouping key
>> ;; 2. flattening the vals of the group-by result should give back the
>> contents of the original collection.
>> ;; 3. no element appears in more than one grouping.
>
>
> those seem good
>
>>
>>
>> so far so good I think. there may be others but this seems ok for now.
>>
>> now, how to generate some data.
>>
>> for group-by we need two params:
>> 1) a grouping function
>> 2) a collection of items to be grouped
>>
>> If I start by naively generating collections of maps (containing keyword
>> keys and int vals, for example), the data is of the right shape to use in
>> group by, but there is no guarantee that:
>> 1) any of the maps share a key that I could use for grouping
>> 2) the values under a common key are shared
>>
>> This is really the crux of my problem.... ideally I would have the
>> generator *mostly* produce data which is actually doing to result in the
>> sort of collection i might want to call group-by on in real life (ie not
>> have everything grouped under nil on each generation). So should i create a
>> generator that creates keywords (which i will want to use as grouping
>> function) then have another generator that produces what are going to be the
>> values under this grouping key, then a generator that uses both of these to
>> create collections of maps from these. then i would have to find out what
>> the grouping keyword was that was generated.... this could all work, I have
>> read enough about generators to have a stab at this... but is it the right
>> approach?
>
>
> You don't seem to be leveraging the possibilities of the grouping function.
> If you create a grouping function that maps many random values into a small
> number of groups, then everything may get easier. Some candidate functions:
> first character of the keyword, length of the keyword, etc.
>
> Or working backwards is often useful with a generator - generate the
> grouping values first, then use the inverse of the grouping function to
> generate data that maps to that group and populate the input with that.
>
>>
>>
>> as far as implementing tests for the properties so far, I have done
>> property 2 above, using a basic generator and yanking out an arbitrary key
>> from it.... clearly a flawed approach as not much 'realistic' grouping is
>> going to happen here.
>>
>> (def vector-of-maps (gen/such-that not-empty (gen/vector (gen/such-that
>> not-empty (gen/map gen/keyword gen/int)))))
>>
>> (def all-elements-are-grouped
>>   (prop/for-all [group-by-input vector-of-maps]
>>                 (let [a-map-key (-> group-by-input first keys first)] ;;
>> hmm, seems far from ideal
>>                   (= (set group-by-input) (-> (group-by a-map-key
>> group-by-input) vals flatten set)))))
>>
>> help appreciated... perhaps I need to learn more about the paradigm first,
>> but resources linked from the readme are all a bit more basic than this. so
>> if you know of some more advanced tutorials please let me know.
>>
>> Thanks
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to